2
0

FeedLinkTest.php 6.9 KB

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