FeedLinkTest.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/FeedLink.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_FeedLinkTest extends PHPUnit_Framework_TestCase
  33. {
  34. public function setUp() {
  35. $this->feedLinkText = file_get_contents(
  36. 'Zend/Gdata/_files/FeedLinkElementSample1.xml',
  37. true);
  38. $this->feedLink = new Zend_Gdata_Extension_FeedLink();
  39. }
  40. public function testEmptyFeedLinkShouldHaveNoExtensionElements() {
  41. $this->assertTrue(is_array($this->feedLink->extensionElements));
  42. $this->assertTrue(count($this->feedLink->extensionElements) == 0);
  43. }
  44. public function testEmptyFeedLinkShouldHaveNoExtensionAttributes() {
  45. $this->assertTrue(is_array($this->feedLink->extensionAttributes));
  46. $this->assertTrue(count($this->feedLink->extensionAttributes) == 0);
  47. }
  48. public function testSampleFeedLinkShouldHaveNoExtensionElements() {
  49. $this->feedLink->transferFromXML($this->feedLinkText);
  50. $this->assertTrue(is_array($this->feedLink->extensionElements));
  51. $this->assertTrue(count($this->feedLink->extensionElements) == 0);
  52. }
  53. public function testSampleFeedLinkShouldHaveNoExtensionAttributes() {
  54. $this->feedLink->transferFromXML($this->feedLinkText);
  55. $this->assertTrue(is_array($this->feedLink->extensionAttributes));
  56. $this->assertTrue(count($this->feedLink->extensionAttributes) == 0);
  57. }
  58. public function testNormalFeedLinkShouldHaveNoExtensionElements() {
  59. $this->feedLink->href = "http://www.google.com/calendar/feeds/default/private/full";
  60. $this->feedLink->rel = "via";
  61. $this->feedLink->countHint = "5";
  62. $this->feedLink->readOnly = false;
  63. $this->assertEquals("http://www.google.com/calendar/feeds/default/private/full", $this->feedLink->href);
  64. $this->assertEquals("via", $this->feedLink->rel);
  65. $this->assertEquals("5", $this->feedLink->countHint);
  66. $this->assertEquals(false, $this->feedLink->readOnly);
  67. $this->assertEquals(0, count($this->feedLink->extensionElements));
  68. $newFeedLink = new Zend_Gdata_Extension_FeedLink();
  69. $newFeedLink->transferFromXML($this->feedLink->saveXML());
  70. $this->assertEquals(0, count($newFeedLink->extensionElements));
  71. $newFeedLink->extensionElements = array(
  72. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  73. $this->assertEquals(1, count($newFeedLink->extensionElements));
  74. $this->assertEquals("http://www.google.com/calendar/feeds/default/private/full", $newFeedLink->href);
  75. $this->assertEquals("via", $newFeedLink->rel);
  76. $this->assertEquals("5", $newFeedLink->countHint);
  77. $this->assertEquals(false, $newFeedLink->readOnly);
  78. /* try constructing using magic factory */
  79. $gdata = new Zend_Gdata();
  80. $newFeedLink2 = $gdata->newFeedLink();
  81. $newFeedLink2->transferFromXML($newFeedLink->saveXML());
  82. $this->assertEquals(1, count($newFeedLink2->extensionElements));
  83. $this->assertEquals("http://www.google.com/calendar/feeds/default/private/full", $newFeedLink2->href);
  84. $this->assertEquals("via", $newFeedLink2->rel);
  85. $this->assertEquals("5", $newFeedLink2->countHint);
  86. $this->assertEquals(false, $newFeedLink2->readOnly);
  87. }
  88. public function testEmptyFeedLinkToAndFromStringShouldMatch() {
  89. $feedLinkXml = $this->feedLink->saveXML();
  90. $newFeedLink = new Zend_Gdata_Extension_FeedLink();
  91. $newFeedLink->transferFromXML($feedLinkXml);
  92. $newFeedLinkXml = $newFeedLink->saveXML();
  93. $this->assertTrue($feedLinkXml == $newFeedLinkXml);
  94. }
  95. public function testFeedLinkWithValueToAndFromStringShouldMatch() {
  96. $this->feedLink->href = "http://www.google.com/calendar/feeds/default/private/full";
  97. $this->feedLink->rel = "via";
  98. $this->feedLink->countHint = "5";
  99. $this->feedLink->readOnly = false;
  100. $feedLinkXml = $this->feedLink->saveXML();
  101. $newFeedLink = new Zend_Gdata_Extension_FeedLink();
  102. $newFeedLink->transferFromXML($feedLinkXml);
  103. $newFeedLinkXml = $newFeedLink->saveXML();
  104. $this->assertTrue($feedLinkXml == $newFeedLinkXml);
  105. $this->assertEquals("http://www.google.com/calendar/feeds/default/private/full", $this->feedLink->href);
  106. $this->assertEquals("via", $this->feedLink->rel);
  107. $this->assertEquals("5", $this->feedLink->countHint);
  108. $this->assertEquals(false, $this->feedLink->readOnly);
  109. }
  110. public function testExtensionAttributes() {
  111. $extensionAttributes = $this->feedLink->extensionAttributes;
  112. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  113. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  114. $this->feedLink->extensionAttributes = $extensionAttributes;
  115. $this->assertEquals('bar', $this->feedLink->extensionAttributes['foo1']['value']);
  116. $this->assertEquals('rab', $this->feedLink->extensionAttributes['foo2']['value']);
  117. $feedLinkXml = $this->feedLink->saveXML();
  118. $newFeedLink = new Zend_Gdata_Extension_FeedLink();
  119. $newFeedLink->transferFromXML($feedLinkXml);
  120. $this->assertEquals('bar', $newFeedLink->extensionAttributes['foo1']['value']);
  121. $this->assertEquals('rab', $newFeedLink->extensionAttributes['foo2']['value']);
  122. }
  123. public function testConvertFullFeedLinkToAndFromString() {
  124. $this->feedLink->transferFromXML($this->feedLinkText);
  125. $this->assertEquals("http://www.google.com/calendar/feeds/default/private/full/3tsi3ag1q40bnsik88k25sgpss/comments", $this->feedLink->href);
  126. $this->assertEquals("http://schemas.google.com/g/2005#feed", $this->feedLink->rel);
  127. $this->assertEquals("0", $this->feedLink->countHint);
  128. $this->assertEquals(true, $this->feedLink->readOnly);
  129. $this->assertTrue($this->feedLink->feed instanceof Zend_Gdata_App_Feed);
  130. $this->assertEquals("Comments for: Sample Event", $this->feedLink->feed->title->text);
  131. }
  132. }