CommentsTest.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id $
  21. */
  22. require_once 'Zend/Gdata/Extension/Comments.php';
  23. require_once 'Zend/Gdata.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Gdata
  31. */
  32. class Zend_Gdata_CommentsTest extends PHPUnit_Framework_TestCase
  33. {
  34. public function setUp() {
  35. $this->commentsText = file_get_contents(
  36. 'Zend/Gdata/_files/CommentsElementSample1.xml',
  37. true);
  38. $this->comments = new Zend_Gdata_Extension_Comments();
  39. }
  40. public function testEmptyCommentsShouldHaveNoExtensionElements() {
  41. $this->assertTrue(is_array($this->comments->extensionElements));
  42. $this->assertTrue(count($this->comments->extensionElements) == 0);
  43. }
  44. public function testEmptyCommentsShouldHaveNoExtensionAttributes() {
  45. $this->assertTrue(is_array($this->comments->extensionAttributes));
  46. $this->assertTrue(count($this->comments->extensionAttributes) == 0);
  47. }
  48. public function testSampleCommentsShouldHaveNoExtensionElements() {
  49. $this->comments->transferFromXML($this->commentsText);
  50. $this->assertTrue(is_array($this->comments->extensionElements));
  51. $this->assertTrue(count($this->comments->extensionElements) == 0);
  52. }
  53. public function testSampleCommentsShouldHaveNoExtensionAttributes() {
  54. $this->comments->transferFromXML($this->commentsText);
  55. $this->assertTrue(is_array($this->comments->extensionAttributes));
  56. $this->assertTrue(count($this->comments->extensionAttributes) == 0);
  57. }
  58. public function testNormalCommentsShouldHaveNoExtensionElements() {
  59. $this->comments->rel = "http://schemas.google.com/g/2005#regular";
  60. $this->assertEquals("http://schemas.google.com/g/2005#regular", $this->comments->rel);
  61. $this->assertEquals(0, count($this->comments->extensionElements));
  62. $newComments = new Zend_Gdata_Extension_Comments();
  63. $newComments->transferFromXML($this->comments->saveXML());
  64. $this->assertEquals(0, count($newComments->extensionElements));
  65. $newComments->extensionElements = array(
  66. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  67. $this->assertEquals(1, count($newComments->extensionElements));
  68. $this->assertEquals("http://schemas.google.com/g/2005#regular", $newComments->rel);
  69. /* try constructing using magic factory */
  70. $gdata = new Zend_Gdata();
  71. $newComments2 = $gdata->newComments();
  72. $newComments2->transferFromXML($newComments->saveXML());
  73. $this->assertEquals(1, count($newComments2->extensionElements));
  74. $this->assertEquals("http://schemas.google.com/g/2005#regular", $newComments2->rel);
  75. }
  76. public function testEmptyCommentsToAndFromStringShouldMatch() {
  77. $commentsXml = $this->comments->saveXML();
  78. $newComments = new Zend_Gdata_Extension_Comments();
  79. $newComments->transferFromXML($commentsXml);
  80. $newCommentsXml = $newComments->saveXML();
  81. $this->assertTrue($commentsXml == $newCommentsXml);
  82. }
  83. public function testCommentsWithValueToAndFromStringShouldMatch() {
  84. $this->comments->rel = "http://schemas.google.com/g/2005#regular";
  85. $commentsXml = $this->comments->saveXML();
  86. $newComments = new Zend_Gdata_Extension_Comments();
  87. $newComments->transferFromXML($commentsXml);
  88. $newCommentsXml = $newComments->saveXML();
  89. $this->assertTrue($commentsXml == $newCommentsXml);
  90. $this->assertEquals("http://schemas.google.com/g/2005#regular", $this->comments->rel);
  91. }
  92. public function testExtensionAttributes() {
  93. $extensionAttributes = $this->comments->extensionAttributes;
  94. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  95. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  96. $this->comments->extensionAttributes = $extensionAttributes;
  97. $this->assertEquals('bar', $this->comments->extensionAttributes['foo1']['value']);
  98. $this->assertEquals('rab', $this->comments->extensionAttributes['foo2']['value']);
  99. $commentsXml = $this->comments->saveXML();
  100. $newComments = new Zend_Gdata_Extension_Comments();
  101. $newComments->transferFromXML($commentsXml);
  102. $this->assertEquals('bar', $newComments->extensionAttributes['foo1']['value']);
  103. $this->assertEquals('rab', $newComments->extensionAttributes['foo2']['value']);
  104. }
  105. public function testConvertFullCommentsToAndFromString() {
  106. $this->comments->transferFromXML($this->commentsText);
  107. $this->assertEquals("http://schemas.google.com/g/2005#reviews", $this->comments->rel);
  108. $this->assertTrue($this->comments->feedLink instanceof Zend_Gdata_Extension_FeedLink);
  109. $this->assertEquals("http://example.com/restaurants/SanFrancisco/432432/reviews", $this->comments->feedLink->href);
  110. }
  111. }