CalendarTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_Calendar
  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/Calendar.php';
  23. require_once 'Zend/Gdata/Calendar/EventFeed.php';
  24. require_once 'Zend/Http/Client.php';
  25. require_once 'Zend/Http/Client/Adapter/Test.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Gdata_Calendar
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Gdata
  33. * @group Zend_Gdata_Calendar
  34. */
  35. class Zend_Gdata_CalendarTest extends PHPUnit_Framework_TestCase
  36. {
  37. public function setUp()
  38. {
  39. $this->eventFeedText = file_get_contents(
  40. 'Zend/Gdata/Calendar/_files/TestDataEventFeedSample1.xml',
  41. true);
  42. $this->eventFeed = new Zend_Gdata_Calendar_EventFeed();
  43. }
  44. public function testEmptyEventFeedShouldHaveNoExtensionElements() {
  45. $this->assertTrue(is_array($this->eventFeed->extensionElements));
  46. $this->assertTrue(count($this->eventFeed->extensionElements) == 0);
  47. }
  48. public function testEmptyEventFeedShouldHaveNoExtensionAttributes() {
  49. $this->assertTrue(is_array($this->eventFeed->extensionAttributes));
  50. $this->assertTrue(count($this->eventFeed->extensionAttributes) == 0);
  51. }
  52. public function testSampleEventFeedShouldHaveNoExtensionElements() {
  53. $this->eventFeed->transferFromXML($this->eventFeedText);
  54. $this->assertTrue(is_array($this->eventFeed->extensionElements));
  55. $this->assertTrue(count($this->eventFeed->extensionElements) == 0);
  56. }
  57. public function testSampleEventFeedShouldHaveNoExtensionAttributes() {
  58. $this->eventFeed->transferFromXML($this->eventFeedText);
  59. $this->assertTrue(is_array($this->eventFeed->extensionAttributes));
  60. $this->assertTrue(count($this->eventFeed->extensionAttributes) == 0);
  61. }
  62. public function testEventFeedToAndFromString()
  63. {
  64. $this->eventFeed->transferFromXML($this->eventFeedText);
  65. $entryCount = 0;
  66. foreach ($this->eventFeed as $entry) {
  67. $entryCount++;
  68. $this->assertTrue($entry instanceof Zend_Gdata_Calendar_EventEntry);
  69. }
  70. $this->assertTrue($entryCount > 0);
  71. /* Grab XML from $this->eventFeed and convert back to objects */
  72. $newEventFeed = new Zend_Gdata_Calendar_EventFeed(
  73. $this->eventFeed->saveXML());
  74. $newEntryCount = 0;
  75. foreach ($newEventFeed as $entry) {
  76. $newEntryCount++;
  77. $this->assertTrue($entry instanceof Zend_Gdata_Calendar_EventEntry);
  78. }
  79. $this->assertEquals($entryCount, $newEntryCount);
  80. }
  81. public function testEntryCount()
  82. {
  83. $this->eventFeed->transferFromXML($this->eventFeedText);
  84. //TODO feeds implementing ArrayAccess would be helpful here
  85. $entryCount = 0;
  86. foreach ($this->eventFeed as $entry) {
  87. $entryCount++;
  88. }
  89. $this->assertEquals($entryCount, 10);
  90. $this->assertEquals($entryCount, $this->eventFeed->totalResults->text);
  91. }
  92. }