UserEntryTest.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_Gapps
  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/Gapps/UserEntry.php';
  22. require_once 'Zend/Gdata/Gapps.php';
  23. /**
  24. * @package Zend_Gdata_App
  25. * @subpackage UnitTests
  26. */
  27. class Zend_Gdata_Gapps_UserEntryTest extends PHPUnit_Framework_TestCase
  28. {
  29. public function setUp() {
  30. $this->entryText = file_get_contents(
  31. 'Zend/Gdata/Gapps/_files/UserEntryDataSample1.xml',
  32. true);
  33. $this->entry = new Zend_Gdata_Gapps_UserEntry();
  34. }
  35. private function verifyAllSamplePropertiesAreCorrect ($userEntry) {
  36. $this->assertEquals('https://apps-apis.google.com/a/feeds/example.com/user/2.0/SusanJones',
  37. $userEntry->id->text);
  38. $this->assertEquals('1970-01-01T00:00:00.000Z', $userEntry->updated->text);
  39. $this->assertEquals('http://schemas.google.com/g/2005#kind', $userEntry->category[0]->scheme);
  40. $this->assertEquals('http://schemas.google.com/apps/2006#user', $userEntry->category[0]->term);
  41. $this->assertEquals('text', $userEntry->title->type);
  42. $this->assertEquals('SusanJones', $userEntry->title->text);;
  43. $this->assertEquals('self', $userEntry->getLink('self')->rel);
  44. $this->assertEquals('application/atom+xml', $userEntry->getLink('self')->type);
  45. $this->assertEquals('https://apps-apis.google.com/a/feeds/example.com/user/2.0/SusanJones', $userEntry->getLink('self')->href);
  46. $this->assertEquals('edit', $userEntry->getLink('edit')->rel);
  47. $this->assertEquals('application/atom+xml', $userEntry->getLink('edit')->type);
  48. $this->assertEquals('https://apps-apis.google.com/a/feeds/example.com/user/2.0/SusanJones', $userEntry->getLink('edit')->href);
  49. $this->assertEquals('SusanJones', $userEntry->login->username);
  50. $this->assertEquals('Jones', $userEntry->name->familyName);
  51. $this->assertEquals('Susan', $userEntry->name->givenName);
  52. $this->assertEquals('http://schemas.google.com/apps/2006#user.nicknames', $userEntry->getFeedLink('http://schemas.google.com/apps/2006#user.nicknames')->rel);
  53. $this->assertEquals('https://apps-apis.google.com/a/feeds/example.com/nickname/2.0?username=Susy-1321', $userEntry->getFeedLink('http://schemas.google.com/apps/2006#user.nicknames')->href);
  54. $this->assertEquals('http://schemas.google.com/apps/2006#user.emailLists', $userEntry->getFeedLink('http://schemas.google.com/apps/2006#user.emailLists')->rel);
  55. $this->assertEquals('https://apps-apis.google.com/a/feeds/example.com/emailList/2.0?recipient=us-sales@example.com', $userEntry->getFeedLink('http://schemas.google.com/apps/2006#user.emailLists')->href);
  56. $this->assertEquals('2048', $userEntry->quota->limit);
  57. }
  58. public function testEmptyEntryShouldHaveNoExtensionElements() {
  59. $this->assertTrue(is_array($this->entry->extensionElements));
  60. $this->assertTrue(count($this->entry->extensionElements) == 0);
  61. }
  62. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  63. $this->assertTrue(is_array($this->entry->extensionAttributes));
  64. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  65. }
  66. public function testSampleEntryShouldHaveNoExtensionElements() {
  67. $this->entry->transferFromXML($this->entryText);
  68. $this->assertTrue(is_array($this->entry->extensionElements));
  69. $this->assertTrue(count($this->entry->extensionElements) == 0);
  70. }
  71. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  72. $this->entry->transferFromXML($this->entryText);
  73. $this->assertTrue(is_array($this->entry->extensionAttributes));
  74. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  75. }
  76. public function testEmptyUserEntryToAndFromStringShouldMatch() {
  77. $entryXml = $this->entry->saveXML();
  78. $newUserEntry = new Zend_Gdata_Gapps_UserEntry();
  79. $newUserEntry->transferFromXML($entryXml);
  80. $newUserEntryXml = $newUserEntry->saveXML();
  81. $this->assertTrue($entryXml == $newUserEntryXml);
  82. }
  83. public function testGetFeedLinkReturnsAllStoredEntriesWhenUsedWithNoParameters() {
  84. // Prepare test data
  85. $entry1 = new Zend_Gdata_Extension_FeedLink();
  86. $entry1->rel = "first";
  87. $entry1->href= "foo";
  88. $entry2 = new Zend_Gdata_Extension_FeedLink();
  89. $entry2->rel = "second";
  90. $entry2->href= "bar";
  91. $data = array($entry1, $entry2);
  92. // Load test data and run test
  93. $this->entry->feedLink = $data;
  94. $this->assertEquals(2, count($this->entry->feedLink));
  95. }
  96. public function testGetFeedLinkCanReturnEntriesByRelValue() {
  97. // Prepare test data
  98. $entry1 = new Zend_Gdata_Extension_FeedLink();
  99. $entry1->rel = "first";
  100. $entry1->href= "foo";
  101. $entry2 = new Zend_Gdata_Extension_FeedLink();
  102. $entry2->rel = "second";
  103. $entry2->href= "bar";
  104. $data = array($entry1, $entry2);
  105. // Load test data and run test
  106. $this->entry->feedLink = $data;
  107. $this->assertEquals($entry1, $this->entry->getFeedLink('first'));
  108. $this->assertEquals($entry2, $this->entry->getFeedLink('second'));
  109. }
  110. public function testSamplePropertiesAreCorrect () {
  111. $this->entry->transferFromXML($this->entryText);
  112. $this->verifyAllSamplePropertiesAreCorrect($this->entry);
  113. }
  114. public function testConvertUserEntryToAndFromString() {
  115. $this->entry->transferFromXML($this->entryText);
  116. $entryXml = $this->entry->saveXML();
  117. $newUserEntry = new Zend_Gdata_Gapps_UserEntry();
  118. $newUserEntry->transferFromXML($entryXml);
  119. $this->verifyAllSamplePropertiesAreCorrect($newUserEntry);
  120. $newUserEntryXml = $newUserEntry->saveXML();
  121. $this->assertEquals($entryXml, $newUserEntryXml);
  122. }
  123. }