CycleTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // Call Zend_View_Helper_CycleTest::main() if this source file is executed directly.
  3. if (! defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_CycleTest::main");
  5. }
  6. require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/TestHelper.php';
  7. require_once "PHPUnit/Framework/TestCase.php";
  8. require_once "PHPUnit/Framework/TestSuite.php";
  9. /** Zend_View_Helper_Cycle */
  10. require_once 'Zend/View/Helper/Cycle.php';
  11. /**
  12. * Test class for Zend_View_Helper_Cycle.
  13. *
  14. * @category Zend
  15. * @package Zend_View
  16. * @subpackage UnitTests
  17. */
  18. class Zend_View_Helper_CycleTest extends PHPUnit_Framework_TestCase
  19. {
  20. /**
  21. * @var Zend_View_Helper_Cycle
  22. */
  23. public $helper;
  24. /**
  25. * Runs the test methods of this class.
  26. *
  27. * @return void
  28. */
  29. public static function main()
  30. {
  31. require_once "PHPUnit/TextUI/TestRunner.php";
  32. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_CycleTest");
  33. $result = PHPUnit_TextUI_TestRunner::run($suite);
  34. }
  35. /**
  36. * Sets up the fixture, for example, open a network connection.
  37. * This method is called before a test is executed.
  38. *
  39. * @return void
  40. */
  41. public function setUp()
  42. {
  43. $this->helper = new Zend_View_Helper_Cycle();
  44. }
  45. /**
  46. * Tears down the fixture, for example, close a network connection.
  47. * This method is called after a test is executed.
  48. *
  49. * @return void
  50. */
  51. public function tearDown()
  52. {
  53. unset($this->helper);
  54. }
  55. public function testCycleMethodReturnsObjectInstance()
  56. {
  57. $cycle = $this->helper->cycle();
  58. $this->assertTrue($cycle instanceof Zend_View_Helper_Cycle);
  59. }
  60. public function testAssignAndGetValues()
  61. {
  62. $this->helper->assign(array('a', 1, 'asd'));
  63. $this->assertEquals(array('a', 1, 'asd'), $this->helper->getAll());
  64. }
  65. public function testCycleMethod()
  66. {
  67. $this->helper->cycle(array('a', 1, 'asd'));
  68. $this->assertEquals(array('a', 1, 'asd'), $this->helper->getAll());
  69. }
  70. public function testToString()
  71. {
  72. $this->helper->cycle(array('a', 1, 'asd'));
  73. $this->assertEquals('a', (string) $this->helper->toString());
  74. }
  75. public function testNextValue()
  76. {
  77. $this->helper->assign(array('a', 1, 3));
  78. $this->assertEquals('a', (string) $this->helper->next());
  79. $this->assertEquals(1, (string) $this->helper->next());
  80. $this->assertEquals(3, (string) $this->helper->next());
  81. $this->assertEquals('a', (string) $this->helper->next());
  82. $this->assertEquals(1, (string) $this->helper->next());
  83. }
  84. public function testPrevValue()
  85. {
  86. $this->helper->assign(array(4, 1, 3));
  87. $this->assertEquals(3, (string) $this->helper->prev());
  88. $this->assertEquals(1, (string) $this->helper->prev());
  89. $this->assertEquals(4, (string) $this->helper->prev());
  90. $this->assertEquals(3, (string) $this->helper->prev());
  91. $this->assertEquals(1, (string) $this->helper->prev());
  92. }
  93. public function testRewind()
  94. {
  95. $this->helper->assign(array(5, 8, 3));
  96. $this->assertEquals(5, (string) $this->helper->next());
  97. $this->assertEquals(8, (string) $this->helper->next());
  98. $this->helper->rewind();
  99. $this->assertEquals(5, (string) $this->helper->next());
  100. $this->assertEquals(8, (string) $this->helper->next());
  101. }
  102. public function testMixedMethods()
  103. {
  104. $this->helper->assign(array(5, 8, 3));
  105. $this->assertEquals(5, (string) $this->helper->next());
  106. $this->assertEquals(5, (string) $this->helper->current());
  107. $this->assertEquals(8, (string) $this->helper->next());
  108. $this->assertEquals(5, (string) $this->helper->prev());
  109. }
  110. public function testTwoCycles()
  111. {
  112. $this->helper->assign(array(5, 8, 3));
  113. $this->assertEquals(5, (string) $this->helper->next());
  114. $this->assertEquals(2, (string) $this->helper->cycle(array(2,38,1),'cycle2')->next());
  115. $this->assertEquals(8, (string) $this->helper->cycle()->next());
  116. $this->assertEquals(38, (string) $this->helper->setName('cycle2')->next());
  117. }
  118. public function testTwoCyclesInLoop()
  119. {
  120. $expected = array(5,4,2,3);
  121. $expected2 = array(7,34,8,6);
  122. for($i=0;$i<4;$i++) {
  123. $this->assertEquals($expected[$i], (string) $this->helper->cycle($expected)->next());
  124. $this->assertEquals($expected2[$i], (string) $this->helper->cycle($expected2,'cycle2')->next());
  125. }
  126. }
  127. }
  128. // Call Zend_View_Helper_CycleTest::main() if this source file is executed directly.
  129. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_CycleTest::main") {
  130. Zend_View_Helper_CycleTest::main();
  131. }