2
0

CycleTest.php 5.6 KB

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