GetWebsiteResultTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Result\GetWebsiteResult;
  4. use OSS\Http\ResponseCore;
  5. use OSS\Core\OssException;
  6. class GetWebsiteResultTest extends \PHPUnit_Framework_TestCase
  7. {
  8. private $validXml = <<<BBBB
  9. <?xml version="1.0" encoding="utf-8"?>
  10. <WebsiteConfiguration>
  11. <IndexDocument>
  12. <Suffix>index.html</Suffix>
  13. </IndexDocument>
  14. <ErrorDocument>
  15. <Key>errorDocument.html</Key>
  16. </ErrorDocument>
  17. </WebsiteConfiguration>
  18. BBBB;
  19. public function testParseValidXml()
  20. {
  21. $response = new ResponseCore(array(), $this->validXml, 200);
  22. $result = new GetWebsiteResult($response);
  23. $this->assertTrue($result->isOK());
  24. $this->assertNotNull($result->getData());
  25. $this->assertNotNull($result->getRawResponse());
  26. $websiteConfig = $result->getData();
  27. $this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($websiteConfig->serializeToXml()));
  28. }
  29. private function cleanXml($xml)
  30. {
  31. return str_replace("\n", "", str_replace("\r", "", $xml));
  32. }
  33. public function testInvalidResponse()
  34. {
  35. $response = new ResponseCore(array(), $this->validXml, 300);
  36. try {
  37. new GetWebsiteResult($response);
  38. $this->assertTrue(false);
  39. } catch (OssException $e) {
  40. }
  41. }
  42. }