NavigationTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_Navigation
  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. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_NavigationTest::main');
  24. }
  25. /**
  26. * Zend_Navigation
  27. */
  28. require_once 'Zend/Navigation.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Navigation
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Navigation
  36. */
  37. class Zend_NavigationTest extends PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * @var Zend_Navigation
  41. */
  42. private $_navigation;
  43. protected function setUp()
  44. {
  45. parent::setUp();
  46. $this->_navigation = new Zend_Navigation();
  47. }
  48. protected function tearDown()
  49. {
  50. $this->_navigation = null;
  51. parent::tearDown();
  52. }
  53. /**
  54. * Runs the test methods of this class.
  55. *
  56. * @return void
  57. */
  58. public static function main()
  59. {
  60. $suite = new PHPUnit_Framework_TestSuite("Zend_NavigationTest");
  61. $result = PHPUnit_TextUI_TestRunner::run($suite);
  62. }
  63. /**
  64. * Testing that navigation order is done correctly
  65. *
  66. * @group ZF-8337
  67. * @group ZF-8313
  68. */
  69. public function testNavigationArraySortsCorrectly()
  70. {
  71. require_once 'Zend/Navigation/Page/Uri.php';
  72. $page1 = new Zend_Navigation_Page_Uri(array('uri' => 'page1'));
  73. $page2 = new Zend_Navigation_Page_Uri(array('uri' => 'page2'));
  74. $page3 = new Zend_Navigation_Page_Uri(array('uri' => 'page3'));
  75. $this->_navigation->setPages(array($page1, $page2, $page3));
  76. $page1->setOrder(1);
  77. $page3->setOrder(0);
  78. $page2->setOrder(2);
  79. $pages = $this->_navigation->toArray();
  80. $this->assertSame(3, count($pages));
  81. $this->assertEquals('page3', $pages[0]['uri']);
  82. $this->assertEquals('page1', $pages[1]['uri']);
  83. $this->assertEquals('page2', $pages[2]['uri']);
  84. }
  85. }