GroupEntryTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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-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/Gapps/GroupEntry.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-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. * @group Zend_Gdata_Gapps
  32. */
  33. class Zend_Gdata_Gapps_GroupEntryTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->entryText = file_get_contents(
  37. 'Zend/Gdata/Gapps/_files/GroupEntryDataSample1.xml',
  38. true);
  39. $this->entry = new Zend_Gdata_Gapps_GroupEntry();
  40. }
  41. private function verifyAllSamplePropertiesAreCorrect ($groupEntry) {
  42. $this->assertEquals('https://www.google.com/a/feeds/group/2.0/example.com/us-sales',
  43. $groupEntry->id->text);
  44. $this->assertEquals('1970-01-01T00:00:00.000Z', $groupEntry->updated->text);
  45. $this->assertEquals('self', $groupEntry->getLink('self')->rel);
  46. $this->assertEquals('application/atom+xml', $groupEntry->getLink('self')->type);
  47. $this->assertEquals('https://www.google.com/a/feeds/group/2.0/example.com/us-sales', $groupEntry->getLink('self')->href);
  48. $this->assertEquals('edit', $groupEntry->getLink('edit')->rel);
  49. $this->assertEquals('application/atom+xml', $groupEntry->getLink('edit')->type);
  50. $this->assertEquals('https://www.google.com/a/feeds/group/2.0/example.com/us-sales', $groupEntry->getLink('edit')->href);
  51. $this->assertEquals('groupId', $groupEntry->property[0]->name);
  52. $this->assertEquals('us-sales', $groupEntry->property[0]->value);
  53. $this->assertEquals('groupName', $groupEntry->property[1]->name);
  54. $this->assertEquals('us-sales', $groupEntry->property[1]->value);
  55. $this->assertEquals('description', $groupEntry->property[2]->name);
  56. $this->assertEquals('UnitedStatesSalesTeam', $groupEntry->property[2]->value);
  57. $this->assertEquals('emailPermission', $groupEntry->property[3]->name);
  58. $this->assertEquals('Domain', $groupEntry->property[3]->value);
  59. }
  60. public function testEmptyEntryShouldHaveNoExtensionElements() {
  61. $this->assertTrue(is_array($this->entry->extensionElements));
  62. $this->assertTrue(count($this->entry->extensionElements) == 0);
  63. }
  64. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  65. $this->assertTrue(is_array($this->entry->extensionAttributes));
  66. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  67. }
  68. public function testSampleEntryShouldHaveNoExtensionElements() {
  69. $this->entry->transferFromXML($this->entryText);
  70. $this->assertTrue(is_array($this->entry->extensionElements));
  71. $this->assertTrue(count($this->entry->extensionElements) == 0);
  72. }
  73. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  74. $this->entry->transferFromXML($this->entryText);
  75. $this->assertTrue(is_array($this->entry->extensionAttributes));
  76. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  77. }
  78. public function testEmptyGroupEntryToAndFromStringShouldMatch() {
  79. $entryXml = $this->entry->saveXML();
  80. $newGroupEntry = new Zend_Gdata_Gapps_GroupEntry();
  81. $newGroupEntry->transferFromXML($entryXml);
  82. $newGroupEntryXml = $newGroupEntry->saveXML();
  83. $this->assertTrue($entryXml == $newGroupEntryXml);
  84. }
  85. public function testSamplePropertiesAreCorrect () {
  86. $this->entry->transferFromXML($this->entryText);
  87. $this->verifyAllSamplePropertiesAreCorrect($this->entry);
  88. }
  89. public function testConvertGroupEntryToAndFromString() {
  90. $this->entry->transferFromXML($this->entryText);
  91. $entryXml = $this->entry->saveXML();
  92. $newGroupEntry = new Zend_Gdata_Gapps_GroupEntry();
  93. $newGroupEntry->transferFromXML($entryXml);
  94. $this->verifyAllSamplePropertiesAreCorrect($newGroupEntry);
  95. $newGroupEntryXml = $newGroupEntry->saveXML();
  96. $this->assertEquals($entryXml, $newGroupEntryXml);
  97. }
  98. }