IteratorTest.php 3.4 KB

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