CycleTest.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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_View
  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. // Call Zend_View_Helper_CycleTest::main() if this source file is executed directly.
  23. if (! defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_CycleTest::main");
  25. }
  26. /** Zend_View_Helper_Cycle */
  27. require_once 'Zend/View/Helper/Cycle.php';
  28. /**
  29. * Test class for Zend_View_Helper_Cycle.
  30. *
  31. * @category Zend
  32. * @package Zend_View
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_View
  37. * @group Zend_View_Helper
  38. */
  39. class Zend_View_Helper_CycleTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * @var Zend_View_Helper_Cycle
  43. */
  44. public $helper;
  45. /**
  46. * Runs the test methods of this class.
  47. *
  48. * @return void
  49. */
  50. public static function main()
  51. {
  52. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_CycleTest");
  53. $result = PHPUnit_TextUI_TestRunner::run($suite);
  54. }
  55. /**
  56. * Sets up the fixture, for example, open a network connection.
  57. * This method is called before a test is executed.
  58. *
  59. * @return void
  60. */
  61. public function setUp()
  62. {
  63. $this->helper = new Zend_View_Helper_Cycle();
  64. }
  65. /**
  66. * Tears down the fixture, for example, close a network connection.
  67. * This method is called after a test is executed.
  68. *
  69. * @return void
  70. */
  71. public function tearDown()
  72. {
  73. unset($this->helper);
  74. }
  75. public function testCycleMethodReturnsObjectInstance()
  76. {
  77. $cycle = $this->helper->cycle();
  78. $this->assertTrue($cycle instanceof Zend_View_Helper_Cycle);
  79. }
  80. public function testAssignAndGetValues()
  81. {
  82. $this->helper->assign(array('a', 1, 'asd'));
  83. $this->assertEquals(array('a', 1, 'asd'), $this->helper->getAll());
  84. }
  85. public function testCycleMethod()
  86. {
  87. $this->helper->cycle(array('a', 1, 'asd'));
  88. $this->assertEquals(array('a', 1, 'asd'), $this->helper->getAll());
  89. }
  90. public function testToString()
  91. {
  92. $this->helper->cycle(array('a', 1, 'asd'));
  93. $this->assertEquals('a', (string) $this->helper->toString());
  94. }
  95. public function testNextValue()
  96. {
  97. $this->helper->assign(array('a', 1, 3));
  98. $this->assertEquals('a', (string) $this->helper->next());
  99. $this->assertEquals(1, (string) $this->helper->next());
  100. $this->assertEquals(3, (string) $this->helper->next());
  101. $this->assertEquals('a', (string) $this->helper->next());
  102. $this->assertEquals(1, (string) $this->helper->next());
  103. }
  104. public function testPrevValue()
  105. {
  106. $this->helper->assign(array(4, 1, 3));
  107. $this->assertEquals(3, (string) $this->helper->prev());
  108. $this->assertEquals(1, (string) $this->helper->prev());
  109. $this->assertEquals(4, (string) $this->helper->prev());
  110. $this->assertEquals(3, (string) $this->helper->prev());
  111. $this->assertEquals(1, (string) $this->helper->prev());
  112. }
  113. public function testRewind()
  114. {
  115. $this->helper->assign(array(5, 8, 3));
  116. $this->assertEquals(5, (string) $this->helper->next());
  117. $this->assertEquals(8, (string) $this->helper->next());
  118. $this->helper->rewind();
  119. $this->assertEquals(5, (string) $this->helper->next());
  120. $this->assertEquals(8, (string) $this->helper->next());
  121. }
  122. public function testMixedMethods()
  123. {
  124. $this->helper->assign(array(5, 8, 3));
  125. $this->assertEquals(5, (string) $this->helper->next());
  126. $this->assertEquals(5, (string) $this->helper->current());
  127. $this->assertEquals(8, (string) $this->helper->next());
  128. $this->assertEquals(5, (string) $this->helper->prev());
  129. }
  130. public function testTwoCycles()
  131. {
  132. $this->helper->assign(array(5, 8, 3));
  133. $this->assertEquals(5, (string) $this->helper->next());
  134. $this->assertEquals(2, (string) $this->helper->cycle(array(2,38,1),'cycle2')->next());
  135. $this->assertEquals(8, (string) $this->helper->cycle()->next());
  136. $this->assertEquals(38, (string) $this->helper->setName('cycle2')->next());
  137. }
  138. public function testTwoCyclesInLoop()
  139. {
  140. $expected = array(5,4,2,3);
  141. $expected2 = array(7,34,8,6);
  142. for($i=0;$i<4;$i++) {
  143. $this->assertEquals($expected[$i], (string) $this->helper->cycle($expected)->next());
  144. $this->assertEquals($expected2[$i], (string) $this->helper->cycle($expected2,'cycle2')->next());
  145. }
  146. }
  147. }
  148. // Call Zend_View_Helper_CycleTest::main() if this source file is executed directly.
  149. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_CycleTest::main") {
  150. Zend_View_Helper_CycleTest::main();
  151. }