RefererConfigTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Model\RefererConfig;
  4. class RefererConfigTest extends \PHPUnit_Framework_TestCase
  5. {
  6. private $validXml = <<<BBBB
  7. <?xml version="1.0" encoding="utf-8"?>
  8. <RefererConfiguration>
  9. <AllowEmptyReferer>true</AllowEmptyReferer>
  10. <RefererList>
  11. <Referer>http://www.aliyun.com</Referer>
  12. <Referer>https://www.aliyun.com</Referer>
  13. <Referer>http://www.*.com</Referer>
  14. <Referer>https://www.?.aliyuncs.com</Referer>
  15. </RefererList>
  16. </RefererConfiguration>
  17. BBBB;
  18. private $validXml2 = <<<BBBB
  19. <?xml version="1.0" encoding="utf-8"?>
  20. <RefererConfiguration>
  21. <AllowEmptyReferer>true</AllowEmptyReferer>
  22. <RefererList>
  23. <Referer>http://www.aliyun.com</Referer>
  24. </RefererList>
  25. </RefererConfiguration>
  26. BBBB;
  27. public function testParseValidXml()
  28. {
  29. $refererConfig = new RefererConfig();
  30. $refererConfig->parseFromXml($this->validXml);
  31. $this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($refererConfig->serializeToXml()));
  32. }
  33. public function testParseValidXml2()
  34. {
  35. $refererConfig = new RefererConfig();
  36. $refererConfig->parseFromXml($this->validXml2);
  37. $this->assertEquals(true, $refererConfig->isAllowEmptyReferer());
  38. $this->assertEquals(1, count($refererConfig->getRefererList()));
  39. $this->assertEquals($this->cleanXml($this->validXml2), $this->cleanXml(strval($refererConfig)));
  40. }
  41. private function cleanXml($xml)
  42. {
  43. return str_replace("\n", "", str_replace("\r", "", $xml));
  44. }
  45. }