EmailListFeedTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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) 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.php';
  22. require_once 'Zend/Gdata/Gapps/EmailListFeed.php';
  23. /**
  24. * @package Zend_Gdata
  25. * @subpackage UnitTests
  26. */
  27. class Zend_Gdata_Gapps_EmailListFeedTest extends PHPUnit_Framework_TestCase
  28. {
  29. protected $emailListFeed = null;
  30. /**
  31. * Called before each test to setup any fixtures.
  32. */
  33. public function setUp()
  34. {
  35. $emailListFeedText = file_get_contents(
  36. 'Zend/Gdata/Gapps/_files/EmailListFeedDataSample1.xml',
  37. true);
  38. $this->emailListFeed = new Zend_Gdata_Gapps_EmailListFeed($emailListFeedText);
  39. $this->emptyEmailListFeed = new Zend_Gdata_Gapps_EmailListFeed();
  40. }
  41. public function testEmptyFeedShouldHaveNoExtensionElements() {
  42. $this->assertTrue(is_array($this->emptyEmailListFeed->extensionElements));
  43. $this->assertTrue(count($this->emptyEmailListFeed->extensionElements) == 0);
  44. }
  45. public function testEmptyFeedShouldHaveNoExtensionAttributes() {
  46. $this->assertTrue(is_array($this->emptyEmailListFeed->extensionAttributes));
  47. $this->assertTrue(count($this->emptyEmailListFeed->extensionAttributes) == 0);
  48. }
  49. public function testSampleFeedShouldHaveNoExtensionElements() {
  50. $this->assertTrue(is_array($this->emailListFeed->extensionElements));
  51. $this->assertTrue(count($this->emailListFeed->extensionElements) == 0);
  52. }
  53. public function testSampleFeedShouldHaveNoExtensionAttributes() {
  54. $this->assertTrue(is_array($this->emailListFeed->extensionAttributes));
  55. $this->assertTrue(count($this->emailListFeed->extensionAttributes) == 0);
  56. }
  57. /**
  58. * Convert sample feed to XML then back to objects. Ensure that
  59. * all objects are instances of EventEntry and object count matches.
  60. */
  61. public function testXmlImportAndOutputAreNonDestructive()
  62. {
  63. $entryCount = 0;
  64. foreach ($this->emailListFeed as $entry) {
  65. $entryCount++;
  66. $this->assertTrue($entry instanceof Zend_Gdata_Gapps_EmailListEntry);
  67. }
  68. $this->assertTrue($entryCount > 0);
  69. /* Grab XML from $this->emailListFeed and convert back to objects */
  70. $newEmailListFeed = new Zend_Gdata_Gapps_EmailListFeed(
  71. $this->emailListFeed->saveXML());
  72. $newEntryCount = 0;
  73. foreach ($newEmailListFeed as $entry) {
  74. $newEntryCount++;
  75. $this->assertTrue($entry instanceof Zend_Gdata_Gapps_EmailListEntry);
  76. }
  77. $this->assertEquals($entryCount, $newEntryCount);
  78. }
  79. /**
  80. * Ensure that there number of lsit feeds equals the number
  81. * of calendars defined in the sample file.
  82. */
  83. public function testAllEntriesInFeedAreInstantiated()
  84. {
  85. //TODO feeds implementing ArrayAccess would be helpful here
  86. $entryCount = 0;
  87. foreach ($this->emailListFeed as $entry) {
  88. $entryCount++;
  89. }
  90. $this->assertEquals(2, $entryCount);
  91. }
  92. }