EntryLinkTest.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/EntryLink.php';
  22. require_once 'Zend/Gdata.php';
  23. /**
  24. * @package Zend_Gdata
  25. * @subpackage UnitTests
  26. * @copyright Copyright (c) 2005-2009 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_EntryLinkTest extends PHPUnit_Framework_TestCase
  30. {
  31. public function setUp() {
  32. $this->entryLinkText = file_get_contents(
  33. 'Zend/Gdata/_files/EntryLinkElementSample1.xml',
  34. true);
  35. $this->entryLink = new Zend_Gdata_Extension_EntryLink();
  36. }
  37. public function testEmptyEntryLinkShouldHaveNoExtensionElements() {
  38. $this->assertTrue(is_array($this->entryLink->extensionElements));
  39. $this->assertTrue(count($this->entryLink->extensionElements) == 0);
  40. }
  41. public function testEmptyEntryLinkShouldHaveNoExtensionAttributes() {
  42. $this->assertTrue(is_array($this->entryLink->extensionAttributes));
  43. $this->assertTrue(count($this->entryLink->extensionAttributes) == 0);
  44. }
  45. public function testSampleEntryLinkShouldHaveNoExtensionElements() {
  46. $this->entryLink->transferFromXML($this->entryLinkText);
  47. $this->assertTrue(is_array($this->entryLink->extensionElements));
  48. $this->assertTrue(count($this->entryLink->extensionElements) == 0);
  49. }
  50. public function testSampleEntryLinkShouldHaveNoExtensionAttributes() {
  51. $this->entryLink->transferFromXML($this->entryLinkText);
  52. $this->assertTrue(is_array($this->entryLink->extensionAttributes));
  53. $this->assertTrue(count($this->entryLink->extensionAttributes) == 0);
  54. }
  55. public function testNormalEntryLinkShouldHaveNoExtensionElements() {
  56. $this->entryLink->href = "http://gmail.com/jo/contacts/Bob";
  57. $this->entryLink->rel = "self";
  58. $this->entryLink->readOnly = "false";
  59. $this->assertEquals("http://gmail.com/jo/contacts/Bob", $this->entryLink->href);
  60. $this->assertEquals("self", $this->entryLink->rel);
  61. $this->assertEquals("false", $this->entryLink->readOnly);
  62. $this->assertEquals(0, count($this->entryLink->extensionElements));
  63. $newEntryLink = new Zend_Gdata_Extension_EntryLink();
  64. $newEntryLink->transferFromXML($this->entryLink->saveXML());
  65. $this->assertEquals(0, count($newEntryLink->extensionElements));
  66. $newEntryLink->extensionElements = array(
  67. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  68. $this->assertEquals(1, count($newEntryLink->extensionElements));
  69. $this->assertEquals("http://gmail.com/jo/contacts/Bob", $newEntryLink->href);
  70. $this->assertEquals("self", $newEntryLink->rel);
  71. $this->assertEquals("false", $newEntryLink->readOnly);
  72. /* try constructing using magic factory */
  73. $gdata = new Zend_Gdata();
  74. $newEntryLink2 = $gdata->newEntryLink();
  75. $newEntryLink2->transferFromXML($newEntryLink->saveXML());
  76. $this->assertEquals(1, count($newEntryLink2->extensionElements));
  77. $this->assertEquals("http://gmail.com/jo/contacts/Bob", $newEntryLink2->href);
  78. $this->assertEquals("self", $newEntryLink2->rel);
  79. $this->assertEquals("false", $newEntryLink2->readOnly);
  80. }
  81. public function testEmptyEntryLinkToAndFromStringShouldMatch() {
  82. $entryLinkXml = $this->entryLink->saveXML();
  83. $newEntryLink = new Zend_Gdata_Extension_EntryLink();
  84. $newEntryLink->transferFromXML($entryLinkXml);
  85. $newEntryLinkXml = $newEntryLink->saveXML();
  86. $this->assertTrue($entryLinkXml == $newEntryLinkXml);
  87. }
  88. public function testEntryLinkWithValueToAndFromStringShouldMatch() {
  89. $this->entryLink->href = "http://gmail.com/jo/contacts/Bob";
  90. $this->entryLink->rel = "self";
  91. $this->entryLink->readOnly = "false";
  92. $entryLinkXml = $this->entryLink->saveXML();
  93. $newEntryLink = new Zend_Gdata_Extension_EntryLink();
  94. $newEntryLink->transferFromXML($entryLinkXml);
  95. $newEntryLinkXml = $newEntryLink->saveXML();
  96. $this->assertTrue($entryLinkXml == $newEntryLinkXml);
  97. $this->assertEquals("http://gmail.com/jo/contacts/Bob", $this->entryLink->href);
  98. $this->assertEquals("self", $this->entryLink->rel);
  99. $this->assertEquals("false", $this->entryLink->readOnly);
  100. }
  101. public function testExtensionAttributes() {
  102. $extensionAttributes = $this->entryLink->extensionAttributes;
  103. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  104. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  105. $this->entryLink->extensionAttributes = $extensionAttributes;
  106. $this->assertEquals('bar', $this->entryLink->extensionAttributes['foo1']['value']);
  107. $this->assertEquals('rab', $this->entryLink->extensionAttributes['foo2']['value']);
  108. $entryLinkXml = $this->entryLink->saveXML();
  109. $newEntryLink = new Zend_Gdata_Extension_EntryLink();
  110. $newEntryLink->transferFromXML($entryLinkXml);
  111. $this->assertEquals('bar', $newEntryLink->extensionAttributes['foo1']['value']);
  112. $this->assertEquals('rab', $newEntryLink->extensionAttributes['foo2']['value']);
  113. }
  114. public function testConvertFullEntryLinkToAndFromString() {
  115. $this->entryLink->transferFromXML($this->entryLinkText);
  116. $this->assertEquals("http://gmail.com/jo/contacts/Jo", $this->entryLink->href);
  117. $this->assertEquals("via", $this->entryLink->rel);
  118. $this->assertEquals("true", $this->entryLink->readOnly);
  119. $this->assertTrue($this->entryLink->entry instanceof Zend_Gdata_App_Entry);
  120. $this->assertEquals("Jo March", $this->entryLink->entry->title->text);
  121. }
  122. }