IteratorTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_Feed
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2008 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. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. /**
  27. * @see Zend_Feed
  28. */
  29. require_once 'Zend/Feed.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Feed
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Feed_IteratorTest extends PHPUnit_Framework_TestCase
  38. {
  39. private $_feed;
  40. private $_nsfeed;
  41. public function setUp()
  42. {
  43. $this->_feed = Zend_Feed::importFile(dirname(__FILE__) . '/_files/TestAtomFeed.xml');
  44. $this->_nsfeed = Zend_Feed::importFile(dirname(__FILE__) . '/_files/TestAtomFeedNamespaced.xml');
  45. }
  46. public function testRewind()
  47. {
  48. $times = 0;
  49. foreach ($this->_feed as $f) {
  50. ++$times;
  51. }
  52. $times2 = 0;
  53. foreach ($this->_feed as $f) {
  54. ++$times2;
  55. }
  56. $this->assertEquals($times, $times2, 'Feed should have the same number of iterations multiple times through');
  57. $times = 0;
  58. foreach ($this->_nsfeed as $f) {
  59. ++$times;
  60. }
  61. $times2 = 0;
  62. foreach ($this->_nsfeed as $f) {
  63. ++$times2;
  64. }
  65. $this->assertEquals($times, $times2, 'Feed should have the same number of iterations multiple times through');
  66. }
  67. public function testCurrent()
  68. {
  69. foreach ($this->_feed as $f) {
  70. $this->assertType('Zend_Feed_Entry_Atom', $f, 'Each feed entry should be an instance of Zend_Feed_Entry_Atom');
  71. break;
  72. }
  73. foreach ($this->_nsfeed as $f) {
  74. $this->assertType('Zend_Feed_Entry_Atom', $f, 'Each feed entry should be an instance of Zend_Feed_Entry_Atom');
  75. break;
  76. }
  77. }
  78. public function testKey()
  79. {
  80. $keys = array();
  81. foreach ($this->_feed as $k => $f) {
  82. $keys[] = $k;
  83. }
  84. $this->assertEquals($keys, array(0, 1), 'Feed should have keys 0 and 1');
  85. $keys = array();
  86. foreach ($this->_nsfeed as $k => $f) {
  87. $keys[] = $k;
  88. }
  89. $this->assertEquals($keys, array(0, 1), 'Feed should have keys 0 and 1');
  90. }
  91. public function testNext()
  92. {
  93. $last = null;
  94. foreach ($this->_feed as $current) {
  95. $this->assertFalse($last === $current, 'Iteration should produce a new object each entry');
  96. $last = $current;
  97. }
  98. $last = null;
  99. foreach ($this->_nsfeed as $current) {
  100. $this->assertFalse($last === $current, 'Iteration should produce a new object each entry');
  101. $last = $current;
  102. }
  103. }
  104. }