NavigationTest.php 2.7 KB

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