NicknameEntryTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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) 2005-2014 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/Gapps/NicknameEntry.php';
  23. require_once 'Zend/Gdata/Gapps.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata_Gapps
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2014 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. * @group Zend_Gdata_Gapps
  32. */
  33. class Zend_Gdata_Gapps_NicknameEntryTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->entryText = file_get_contents(
  37. 'Zend/Gdata/Gapps/_files/NicknameEntryDataSample1.xml',
  38. true);
  39. $this->entry = new Zend_Gdata_Gapps_NicknameEntry();
  40. }
  41. private function verifyAllSamplePropertiesAreCorrect ($nicknameEntry) {
  42. $this->assertEquals('https://apps-apis.google.com/a/feeds/example.com/nickname/2.0/Susy',
  43. $nicknameEntry->id->text);
  44. $this->assertEquals('1970-01-01T00:00:00.000Z', $nicknameEntry->updated->text);
  45. $this->assertEquals('http://schemas.google.com/g/2005#kind', $nicknameEntry->category[0]->scheme);
  46. $this->assertEquals('http://schemas.google.com/apps/2006#nickname', $nicknameEntry->category[0]->term);
  47. $this->assertEquals('text', $nicknameEntry->title->type);
  48. $this->assertEquals('Susy', $nicknameEntry->title->text);;
  49. $this->assertEquals('self', $nicknameEntry->getLink('self')->rel);
  50. $this->assertEquals('application/atom+xml', $nicknameEntry->getLink('self')->type);
  51. $this->assertEquals('https://apps-apis.google.com/a/feeds/example.com/nickname/2.0/Susy', $nicknameEntry->getLink('self')->href);
  52. $this->assertEquals('edit', $nicknameEntry->getLink('edit')->rel);
  53. $this->assertEquals('application/atom+xml', $nicknameEntry->getLink('edit')->type);
  54. $this->assertEquals('https://apps-apis.google.com/a/feeds/example.com/nickname/2.0/Susy', $nicknameEntry->getLink('edit')->href);
  55. $this->assertEquals('Susy', $nicknameEntry->nickname->name);
  56. $this->assertEquals('SusanJones', $nicknameEntry->login->username);
  57. $this->assertEquals(false, $nicknameEntry->login->suspended);
  58. $this->assertEquals(false, $nicknameEntry->login->admin);
  59. $this->assertEquals(false, $nicknameEntry->login->changePasswordAtNextLogin);
  60. $this->assertEquals(true, $nicknameEntry->login->agreedToTerms);
  61. }
  62. public function testEmptyEntryShouldHaveNoExtensionElements() {
  63. $this->assertTrue(is_array($this->entry->extensionElements));
  64. $this->assertTrue(count($this->entry->extensionElements) == 0);
  65. }
  66. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  67. $this->assertTrue(is_array($this->entry->extensionAttributes));
  68. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  69. }
  70. public function testSampleEntryShouldHaveNoExtensionElements() {
  71. $this->entry->transferFromXML($this->entryText);
  72. $this->assertTrue(is_array($this->entry->extensionElements));
  73. $this->assertTrue(count($this->entry->extensionElements) == 0);
  74. }
  75. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  76. $this->entry->transferFromXML($this->entryText);
  77. $this->assertTrue(is_array($this->entry->extensionAttributes));
  78. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  79. }
  80. public function testEmptyNicknameEntryToAndFromStringShouldMatch() {
  81. $entryXml = $this->entry->saveXML();
  82. $newNicknameEntry = new Zend_Gdata_Gapps_NicknameEntry();
  83. $newNicknameEntry->transferFromXML($entryXml);
  84. $newNicknameEntryXml = $newNicknameEntry->saveXML();
  85. $this->assertTrue($entryXml == $newNicknameEntryXml);
  86. }
  87. public function testSamplePropertiesAreCorrect () {
  88. $this->entry->transferFromXML($this->entryText);
  89. $this->verifyAllSamplePropertiesAreCorrect($this->entry);
  90. }
  91. public function testConvertNicknameEntryToAndFromString() {
  92. $this->entry->transferFromXML($this->entryText);
  93. $entryXml = $this->entry->saveXML();
  94. $newNicknameEntry = new Zend_Gdata_Gapps_NicknameEntry();
  95. $newNicknameEntry->transferFromXML($entryXml);
  96. $this->verifyAllSamplePropertiesAreCorrect($newNicknameEntry);
  97. $newNicknameEntryXml = $newNicknameEntry->saveXML();
  98. $this->assertEquals($entryXml, $newNicknameEntryXml);
  99. }
  100. }