IteratorTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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-2012 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-2012 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->assertType('Zend_Feed_Entry_Atom', $f, 'Each feed entry should be an instance of Zend_Feed_Entry_Atom');
  68. break;
  69. }
  70. foreach ($this->_nsfeed 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. }
  75. public function testKey()
  76. {
  77. $keys = array();
  78. foreach ($this->_feed as $k => $f) {
  79. $keys[] = $k;
  80. }
  81. $this->assertEquals($keys, array(0, 1), 'Feed should have keys 0 and 1');
  82. $keys = array();
  83. foreach ($this->_nsfeed as $k => $f) {
  84. $keys[] = $k;
  85. }
  86. $this->assertEquals($keys, array(0, 1), 'Feed should have keys 0 and 1');
  87. }
  88. public function testNext()
  89. {
  90. $last = null;
  91. foreach ($this->_feed as $current) {
  92. $this->assertFalse($last === $current, 'Iteration should produce a new object each entry');
  93. $last = $current;
  94. }
  95. $last = null;
  96. foreach ($this->_nsfeed as $current) {
  97. $this->assertFalse($last === $current, 'Iteration should produce a new object each entry');
  98. $last = $current;
  99. }
  100. }
  101. }