EntryLinkTest.php 6.4 KB

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