GroupFeedTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.php';
  23. require_once 'Zend/Gdata/Gapps/GroupFeed.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_GroupFeedTest extends PHPUnit_Framework_TestCase
  34. {
  35. protected $groupFeed = null;
  36. /**
  37. * Called before each test to setup any fixtures.
  38. */
  39. public function setUp()
  40. {
  41. $groupFeedText = file_get_contents(
  42. 'Zend/Gdata/Gapps/_files/GroupFeedDataSample1.xml',
  43. true);
  44. $this->groupFeed = new Zend_Gdata_Gapps_GroupFeed($groupFeedText);
  45. $this->emptyGroupFeed = new Zend_Gdata_Gapps_GroupFeed();
  46. }
  47. public function testEmptyFeedShouldHaveNoExtensionElements() {
  48. $this->assertTrue(is_array($this->emptyGroupFeed->extensionElements));
  49. $this->assertTrue(count($this->emptyGroupFeed->extensionElements) == 0);
  50. }
  51. public function testEmptyFeedShouldHaveNoExtensionAttributes() {
  52. $this->assertTrue(is_array($this->emptyGroupFeed->extensionAttributes));
  53. $this->assertTrue(count($this->emptyGroupFeed->extensionAttributes) == 0);
  54. }
  55. public function testSampleFeedShouldHaveNoExtensionElements() {
  56. $this->assertTrue(is_array($this->groupFeed->extensionElements));
  57. $this->assertTrue(count($this->groupFeed->extensionElements) == 0);
  58. }
  59. public function testSampleFeedShouldHaveNoExtensionAttributes() {
  60. $this->assertTrue(is_array($this->groupFeed->extensionAttributes));
  61. $this->assertTrue(count($this->groupFeed->extensionAttributes) == 0);
  62. }
  63. /**
  64. * Convert sample feed to XML then back to objects. Ensure that
  65. * all objects are instances of GroupEntry and object count matches.
  66. */
  67. public function testXmlImportAndOutputAreNonDestructive()
  68. {
  69. $entryCount = 0;
  70. foreach ($this->groupFeed as $entry) {
  71. $entryCount++;
  72. $this->assertTrue($entry instanceof Zend_Gdata_Gapps_GroupEntry);
  73. }
  74. $this->assertTrue($entryCount > 0);
  75. /* Grab XML from $this->groupFeed and convert back to objects */
  76. $newGroupFeed = new Zend_Gdata_Gapps_GroupFeed(
  77. $this->groupFeed->saveXML());
  78. $newEntryCount = 0;
  79. foreach ($newGroupFeed as $entry) {
  80. $newEntryCount++;
  81. $this->assertTrue($entry instanceof Zend_Gdata_Gapps_GroupEntry);
  82. }
  83. $this->assertEquals($entryCount, $newEntryCount);
  84. }
  85. /**
  86. * Ensure that there number of group entries equals the number
  87. * of groups defined in the sample file.
  88. */
  89. public function testAllEntriesInFeedAreInstantiated()
  90. {
  91. //TODO feeds implementing ArrayAccess would be helpful here
  92. $entryCount = 0;
  93. foreach ($this->groupFeed as $entry) {
  94. $entryCount++;
  95. }
  96. $this->assertEquals(2, $entryCount);
  97. }
  98. }