IteratorTest.php 3.4 KB

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