WebsiteConfigTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Model\WebsiteConfig;
  4. class WebsiteConfigTest extends \PHPUnit_Framework_TestCase
  5. {
  6. private $validXml = <<<BBBB
  7. <?xml version="1.0" encoding="utf-8"?>
  8. <WebsiteConfiguration>
  9. <IndexDocument>
  10. <Suffix>index.html</Suffix>
  11. </IndexDocument>
  12. <ErrorDocument>
  13. <Key>errorDocument.html</Key>
  14. </ErrorDocument>
  15. </WebsiteConfiguration>
  16. BBBB;
  17. private $nullXml = <<<BBBB
  18. <?xml version="1.0" encoding="utf-8"?><WebsiteConfiguration><IndexDocument><Suffix/></IndexDocument><ErrorDocument><Key/></ErrorDocument></WebsiteConfiguration>
  19. BBBB;
  20. private $nullXml2 = <<<BBBB
  21. <?xml version="1.0" encoding="utf-8"?><WebsiteConfiguration><IndexDocument><Suffix></Suffix></IndexDocument><ErrorDocument><Key></Key></ErrorDocument></WebsiteConfiguration>
  22. BBBB;
  23. public function testParseValidXml()
  24. {
  25. $websiteConfig = new WebsiteConfig("index");
  26. $websiteConfig->parseFromXml($this->validXml);
  27. $this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($websiteConfig->serializeToXml()));
  28. }
  29. public function testParsenullXml()
  30. {
  31. $websiteConfig = new WebsiteConfig();
  32. $websiteConfig->parseFromXml($this->nullXml);
  33. $this->assertTrue($this->cleanXml($this->nullXml) === $this->cleanXml($websiteConfig->serializeToXml()) ||
  34. $this->cleanXml($this->nullXml2) === $this->cleanXml($websiteConfig->serializeToXml()));
  35. }
  36. public function testWebsiteConstruct()
  37. {
  38. $websiteConfig = new WebsiteConfig("index.html", "errorDocument.html");
  39. $this->assertEquals('index.html', $websiteConfig->getIndexDocument());
  40. $this->assertEquals('errorDocument.html', $websiteConfig->getErrorDocument());
  41. $this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($websiteConfig->serializeToXml()));
  42. }
  43. private function cleanXml($xml)
  44. {
  45. return str_replace("\n", "", str_replace("\r", "", $xml));
  46. }
  47. }