LoggingConfigTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Model\LoggingConfig;
  4. class LoggingConfigTest extends \PHPUnit_Framework_TestCase
  5. {
  6. private $validXml = <<<BBBB
  7. <?xml version="1.0" encoding="utf-8"?>
  8. <BucketLoggingStatus>
  9. <LoggingEnabled>
  10. <TargetBucket>TargetBucket</TargetBucket>
  11. <TargetPrefix>TargetPrefix</TargetPrefix>
  12. </LoggingEnabled>
  13. </BucketLoggingStatus>
  14. BBBB;
  15. private $nullXml = <<<BBBB
  16. <?xml version="1.0" encoding="utf-8"?>
  17. <BucketLoggingStatus/>
  18. BBBB;
  19. public function testParseValidXml()
  20. {
  21. $loggingConfig = new LoggingConfig();
  22. $loggingConfig->parseFromXml($this->validXml);
  23. $this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml(strval($loggingConfig)));
  24. }
  25. public function testConstruct()
  26. {
  27. $loggingConfig = new LoggingConfig('TargetBucket', 'TargetPrefix');
  28. $this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($loggingConfig->serializeToXml()));
  29. }
  30. public function testFailedConstruct()
  31. {
  32. $loggingConfig = new LoggingConfig('TargetBucket', null);
  33. $this->assertEquals($this->cleanXml($this->nullXml), $this->cleanXml($loggingConfig->serializeToXml()));
  34. }
  35. private function cleanXml($xml)
  36. {
  37. return str_replace("\n", "", str_replace("\r", "", $xml));
  38. }
  39. }