AclResultTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Result\AclResult;
  4. use OSS\Core\OssException;
  5. use OSS\Http\ResponseCore;
  6. class AclResultTest extends \PHPUnit_Framework_TestCase
  7. {
  8. private $validXml = <<<BBBB
  9. <?xml version="1.0" ?>
  10. <AccessControlPolicy>
  11. <Owner>
  12. <ID>00220120222</ID>
  13. <DisplayName>user_example</DisplayName>
  14. </Owner>
  15. <AccessControlList>
  16. <Grant>public-read</Grant>
  17. </AccessControlList>
  18. </AccessControlPolicy>
  19. BBBB;
  20. private $invalidXml = <<<BBBB
  21. <?xml version="1.0" ?>
  22. <AccessControlPolicy>
  23. </AccessControlPolicy>
  24. BBBB;
  25. public function testParseValidXml()
  26. {
  27. $response = new ResponseCore(array(), $this->validXml, 200);
  28. $result = new AclResult($response);
  29. $this->assertEquals("public-read", $result->getData());
  30. }
  31. public function testParseNullXml()
  32. {
  33. $response = new ResponseCore(array(), "", 200);
  34. try {
  35. new AclResult($response);
  36. $this->assertTrue(false);
  37. } catch (OssException $e) {
  38. $this->assertEquals('body is null', $e->getMessage());
  39. }
  40. }
  41. public function testParseInvalidXml()
  42. {
  43. $response = new ResponseCore(array(), $this->invalidXml, 200);
  44. try {
  45. new AclResult($response);
  46. $this->assertFalse(true);
  47. } catch (OssException $e) {
  48. $this->assertEquals("xml format exception", $e->getMessage());
  49. }
  50. }
  51. }