MvcTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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-2012 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. require_once 'Zend/Navigation/Page/Mvc.php';
  23. require_once 'Zend/Controller/Request/Http.php';
  24. require_once 'Zend/Controller/Router/Route.php';
  25. require_once 'Zend/Controller/Router/Route/Regex.php';
  26. /**
  27. * Tests the class Zend_Navigation_Page_Mvc
  28. *
  29. * @category Zend
  30. * @package Zend_Navigation
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @group Zend_Navigation
  35. */
  36. class Zend_Navigation_Page_MvcTest extends PHPUnit_Framework_TestCase
  37. {
  38. protected $_front;
  39. protected $_oldRequest;
  40. protected $_oldRouter;
  41. protected function setUp()
  42. {
  43. $this->_front = Zend_Controller_Front::getInstance();
  44. $this->_oldRequest = $this->_front->getRequest();
  45. $this->_oldRouter = $this->_front->getRouter();
  46. $this->_front->resetInstance();
  47. $this->_front->setRequest(new Zend_Controller_Request_Http());
  48. $this->_front->getRouter()->addDefaultRoutes();
  49. }
  50. protected function tearDown()
  51. {
  52. if (null !== $this->_oldRequest) {
  53. $this->_front->setRequest($this->_oldRequest);
  54. } else {
  55. $this->_front->setRequest(new Zend_Controller_Request_Http());
  56. }
  57. $this->_front->setRouter($this->_oldRouter);
  58. }
  59. public function testHrefGeneratedByUrlHelperRequiresNoRoute()
  60. {
  61. $page = new Zend_Navigation_Page_Mvc(array(
  62. 'label' => 'foo',
  63. 'action' => 'index',
  64. 'controller' => 'index'
  65. ));
  66. $page->setAction('view');
  67. $page->setController('news');
  68. $this->assertEquals('/news/view', $page->getHref());
  69. }
  70. public function testHrefGeneratedIsRouteAware()
  71. {
  72. $page = new Zend_Navigation_Page_Mvc(array(
  73. 'label' => 'foo',
  74. 'action' => 'myaction',
  75. 'controller' => 'mycontroller',
  76. 'route' => 'myroute',
  77. 'params' => array(
  78. 'page' => 1337
  79. )
  80. ));
  81. $this->_front->getRouter()->addRoute(
  82. 'myroute',
  83. new Zend_Controller_Router_Route(
  84. 'lolcat/:action/:page',
  85. array(
  86. 'module' => 'default',
  87. 'controller' => 'foobar',
  88. 'action' => 'bazbat',
  89. 'page' => 1
  90. )
  91. )
  92. );
  93. $this->assertEquals('/lolcat/myaction/1337', $page->getHref());
  94. }
  95. /**
  96. * @group ZF-8922
  97. */
  98. public function testGetHrefWithFragmentIdentifier()
  99. {
  100. $page = new Zend_Navigation_Page_Mvc(array(
  101. 'label' => 'foo',
  102. 'fragment' => 'qux',
  103. 'controller' => 'mycontroller',
  104. 'action' => 'myaction',
  105. 'route' => 'myroute',
  106. 'params' => array(
  107. 'page' => 1337
  108. )
  109. ));
  110. $this->_front->getRouter()->addRoute(
  111. 'myroute',
  112. new Zend_Controller_Router_Route(
  113. 'lolcat/:action/:page',
  114. array(
  115. 'module' => 'default',
  116. 'controller' => 'foobar',
  117. 'action' => 'bazbat',
  118. 'page' => 1
  119. )
  120. )
  121. );
  122. $this->assertEquals('/lolcat/myaction/1337#qux', $page->getHref());
  123. }
  124. public function testIsActiveReturnsTrueOnIdenticalModuleControllerAction()
  125. {
  126. $page = new Zend_Navigation_Page_Mvc(array(
  127. 'label' => 'foo',
  128. 'action' => 'index',
  129. 'controller' => 'index'
  130. ));
  131. $this->_front->getRequest()->setParams(array(
  132. 'module' => 'default',
  133. 'controller' => 'index',
  134. 'action' => 'index'
  135. ));
  136. $this->assertEquals(true, $page->isActive());
  137. }
  138. public function testIsActiveReturnsFalseOnDifferentModuleControllerAction()
  139. {
  140. $page = new Zend_Navigation_Page_Mvc(array(
  141. 'label' => 'foo',
  142. 'action' => 'bar',
  143. 'controller' => 'index'
  144. ));
  145. $this->_front->getRequest()->setParams(array(
  146. 'module' => 'default',
  147. 'controller' => 'index',
  148. 'action' => 'index'
  149. ));
  150. $this->assertEquals(false, $page->isActive());
  151. }
  152. public function testIsActiveReturnsTrueOnIdenticalIncludingPageParams()
  153. {
  154. $page = new Zend_Navigation_Page_Mvc(array(
  155. 'label' => 'foo',
  156. 'action' => 'view',
  157. 'controller' => 'post',
  158. 'module' => 'blog',
  159. 'params' => array(
  160. 'id' => '1337'
  161. )
  162. ));
  163. $this->_front->getRequest()->setParams(array(
  164. 'module' => 'blog',
  165. 'controller' => 'post',
  166. 'action' => 'view',
  167. 'id' => '1337'
  168. ));
  169. $this->assertEquals(true, $page->isActive());
  170. }
  171. public function testIsActiveReturnsTrueWhenRequestHasMoreParams()
  172. {
  173. $page = new Zend_Navigation_Page_Mvc(array(
  174. 'label' => 'foo',
  175. 'action' => 'view',
  176. 'controller' => 'post',
  177. 'module' => 'blog'
  178. ));
  179. $this->_front->getRequest()->setParams(array(
  180. 'module' => 'blog',
  181. 'controller' => 'post',
  182. 'action' => 'view',
  183. 'id' => '1337'
  184. ));
  185. $this->assertEquals(true, $page->isActive());
  186. }
  187. public function testIsActiveReturnsFalseWhenRequestHasLessParams()
  188. {
  189. $page = new Zend_Navigation_Page_Mvc(array(
  190. 'label' => 'foo',
  191. 'action' => 'view',
  192. 'controller' => 'post',
  193. 'module' => 'blog',
  194. 'params' => array(
  195. 'id' => '1337'
  196. )
  197. ));
  198. $this->_front->getRequest()->setParams(array(
  199. 'module' => 'blog',
  200. 'controller' => 'post',
  201. 'action' => 'view',
  202. 'id' => null
  203. ));
  204. $this->assertEquals(false, $page->isActive());
  205. }
  206. public function testIsActiveIsRouteAware()
  207. {
  208. $page = new Zend_Navigation_Page_Mvc(array(
  209. 'label' => 'foo',
  210. 'action' => 'myaction',
  211. 'route' => 'myroute',
  212. 'params' => array(
  213. 'page' => 1337
  214. )
  215. ));
  216. $this->_front->getRouter()->addRoute(
  217. 'myroute',
  218. new Zend_Controller_Router_Route(
  219. 'lolcat/:action/:page',
  220. array(
  221. 'module' => 'default',
  222. 'controller' => 'foobar',
  223. 'action' => 'bazbat',
  224. 'page' => 1
  225. )
  226. )
  227. );
  228. $this->_front->getRequest()->setParams(array(
  229. 'module' => 'default',
  230. 'controller' => 'foobar',
  231. 'action' => 'myaction',
  232. 'page' => 1337
  233. ));
  234. $this->assertEquals(true, $page->isActive());
  235. }
  236. /**
  237. * @group ZF-11664
  238. */
  239. public function testIsActiveWithoutAndWithRecursiveOption()
  240. {
  241. // Parent
  242. $page = new Zend_Navigation_Page_Mvc(array(
  243. 'controller' => 'index',
  244. 'action' => 'index',
  245. ));
  246. // Child
  247. $page->addPage(new Zend_Navigation_Page_Mvc(array(
  248. 'controller' => 'index',
  249. 'action' => 'foo',
  250. )));
  251. // Front controller
  252. $this->_front->getRequest()->setParams(array(
  253. 'controller' => 'index',
  254. 'action' => 'foo'
  255. ));
  256. $this->assertFalse($page->isActive());
  257. $this->assertTrue($page->isActive(true));
  258. }
  259. public function testActionAndControllerAccessors()
  260. {
  261. $page = new Zend_Navigation_Page_Mvc(array(
  262. 'label' => 'foo',
  263. 'action' => 'index',
  264. 'controller' => 'index'
  265. ));
  266. $props = array('Action', 'Controller');
  267. $valids = array('index', 'help', 'home', 'default', '1', ' ', '', null);
  268. $invalids = array(42, (object) null);
  269. foreach ($props as $prop) {
  270. $setter = "set$prop";
  271. $getter = "get$prop";
  272. foreach ($valids as $valid) {
  273. $page->$setter($valid);
  274. $this->assertEquals($valid, $page->$getter());
  275. }
  276. foreach ($invalids as $invalid) {
  277. try {
  278. $page->$setter($invalid);
  279. $msg = "'$invalid' is invalid for $setter(), but no ";
  280. $msg .= 'Zend_Navigation_Exception was thrown';
  281. $this->fail($msg);
  282. } catch (Zend_Navigation_Exception $e) {
  283. }
  284. }
  285. }
  286. }
  287. public function testModuleAndRouteAccessors()
  288. {
  289. $page = new Zend_Navigation_Page_Mvc(array(
  290. 'label' => 'foo',
  291. 'action' => 'index',
  292. 'controller' => 'index'
  293. ));
  294. $props = array('Module', 'Route');
  295. $valids = array('index', 'help', 'home', 'default', '1', ' ', null);
  296. $invalids = array(42, (object) null);
  297. foreach ($props as $prop) {
  298. $setter = "set$prop";
  299. $getter = "get$prop";
  300. foreach ($valids as $valid) {
  301. $page->$setter($valid);
  302. $this->assertEquals($valid, $page->$getter());
  303. }
  304. foreach ($invalids as $invalid) {
  305. try {
  306. $page->$setter($invalid);
  307. $msg = "'$invalid' is invalid for $setter(), but no ";
  308. $msg .= 'Zend_Navigation_Exception was thrown';
  309. $this->fail($msg);
  310. } catch (Zend_Navigation_Exception $e) {
  311. }
  312. }
  313. }
  314. }
  315. public function testSetAndGetResetParams()
  316. {
  317. $page = new Zend_Navigation_Page_Mvc(array(
  318. 'label' => 'foo',
  319. 'action' => 'index',
  320. 'controller' => 'index'
  321. ));
  322. $valids = array(true, 1, '1', 3.14, 'true', 'yes');
  323. foreach ($valids as $valid) {
  324. $page->setResetParams($valid);
  325. $this->assertEquals(true, $page->getResetParams());
  326. }
  327. $invalids = array(false, 0, '0', 0.0, array());
  328. foreach ($invalids as $invalid) {
  329. $page->setResetParams($invalid);
  330. $this->assertEquals(false, $page->getResetParams());
  331. }
  332. }
  333. public function testSetAndGetParams()
  334. {
  335. $page = new Zend_Navigation_Page_Mvc(array(
  336. 'label' => 'foo',
  337. 'action' => 'index',
  338. 'controller' => 'index'
  339. ));
  340. $params = array('foo' => 'bar', 'baz' => 'bat');
  341. $page->setParams($params);
  342. $this->assertEquals($params, $page->getParams());
  343. $page->setParams();
  344. $this->assertEquals(array(), $page->getParams());
  345. $page->setParams($params);
  346. $this->assertEquals($params, $page->getParams());
  347. $page->setParams(array());
  348. $this->assertEquals(array(), $page->getParams());
  349. }
  350. /**
  351. * @group ZF-10727
  352. */
  353. public function testSetAndGetParam()
  354. {
  355. $page = new Zend_Navigation_Page_Mvc(array(
  356. 'label' => 'foo',
  357. 'action' => 'index',
  358. 'controller' => 'index'
  359. ));
  360. $page->setParam('foo', 'bar');
  361. $this->assertEquals('bar', $page->getParam('foo'));
  362. // Check type conversion
  363. $page->setParam(null, null);
  364. $this->assertEquals(null, $page->getParam('null'));
  365. }
  366. /**
  367. * @group ZF-10727
  368. */
  369. public function testAddParams()
  370. {
  371. $page = new Zend_Navigation_Page_Mvc(array(
  372. 'label' => 'foo',
  373. 'action' => 'index',
  374. 'controller' => 'index'
  375. ));
  376. $params = array('foo' => 'bar', 'baz' => 'bat');
  377. $page->addParams($params);
  378. $this->assertEquals($params, $page->getParams());
  379. $params2 = array('qux' => 'foobar');
  380. $page->addParams($params2);
  381. $this->assertEquals(array_merge($params, $params2), $page->getParams());
  382. }
  383. /**
  384. * @group ZF-10727
  385. */
  386. public function testRemoveParam()
  387. {
  388. $page = new Zend_Navigation_Page_Mvc(array(
  389. 'label' => 'foo',
  390. 'action' => 'index',
  391. 'controller' => 'index'
  392. ));
  393. $params = array('foo' => 'bar', 'baz' => 'bat');
  394. $page->setParams($params);
  395. $page->removeParam('foo');
  396. $this->assertEquals(array('baz' => 'bat'), $page->getParams());
  397. $this->assertNull($page->getParam('foo'));
  398. }
  399. /**
  400. * @group ZF-10727
  401. */
  402. public function testClearParams()
  403. {
  404. $page = new Zend_Navigation_Page_Mvc(array(
  405. 'label' => 'foo',
  406. 'action' => 'index',
  407. 'controller' => 'index'
  408. ));
  409. $params = array('foo' => 'bar', 'baz' => 'bat');
  410. $page->setParams($params);
  411. $page->clearParams();
  412. $this->assertEquals(array(), $page->getParams());
  413. }
  414. /**
  415. * @group ZF-11664
  416. */
  417. public function testSetActiveAndIsActive()
  418. {
  419. // Page
  420. $page = new Zend_Navigation_Page_Mvc(array(
  421. 'controller' => 'foo',
  422. 'action' => 'bar',
  423. ));
  424. // Front controller
  425. $this->_front->getRequest()->setParams(array(
  426. 'controller' => 'foo',
  427. 'action' => 'bar'
  428. ));
  429. $this->assertTrue($page->isActive());
  430. $page->setActive(false);
  431. $this->assertFalse($page->isActive());
  432. }
  433. /**
  434. * @group ZF-10465
  435. */
  436. public function testSetAndGetEncodeUrl()
  437. {
  438. $page = new Zend_Navigation_Page_Mvc(array(
  439. 'label' => 'foo',
  440. 'action' => 'index',
  441. 'controller' => 'index',
  442. ));
  443. $page->setEncodeUrl(false);
  444. $this->assertEquals(false, $page->getEncodeUrl());
  445. }
  446. /**
  447. * @group ZF-10465
  448. */
  449. public function testEncodeUrlIsRouteAware()
  450. {
  451. $page = new Zend_Navigation_Page_Mvc(array(
  452. 'label' => 'foo',
  453. 'route' => 'myroute',
  454. 'encodeUrl' => false,
  455. 'params' => array(
  456. 'contentKey' => 'pagexy/subpage',
  457. )
  458. ));
  459. $this->_front->getRouter()->addRoute(
  460. 'myroute',
  461. new Zend_Controller_Router_Route_Regex(
  462. '(.+)\.html',
  463. array(
  464. 'module' => 'default',
  465. 'controller' => 'foobar',
  466. 'action' => 'bazbat',
  467. ),
  468. array(
  469. 1 => 'contentKey'
  470. ),
  471. '%s.html'
  472. )
  473. );
  474. $this->assertEquals('/pagexy/subpage.html', $page->getHref());
  475. }
  476. /**
  477. * @group ZF-7794
  478. */
  479. public function testSetScheme()
  480. {
  481. $page = new Zend_Navigation_Page_Mvc();
  482. $page->setScheme('https');
  483. $this->assertEquals('https', $page->getScheme());
  484. }
  485. /**
  486. * @group ZF-7794
  487. */
  488. public function testOptionScheme()
  489. {
  490. $page = new Zend_Navigation_Page_Mvc(
  491. array(
  492. 'scheme' => 'https',
  493. )
  494. );
  495. $this->assertEquals('https', $page->getScheme());
  496. }
  497. /**
  498. * @group ZF-7794
  499. */
  500. public function testHrefGeneratedWithScheme()
  501. {
  502. $page = new Zend_Navigation_Page_Mvc(array(
  503. 'controller' => 'foo',
  504. 'action' => 'bar',
  505. 'scheme' => 'https',
  506. ));
  507. $_SERVER['HTTP_HOST'] = 'foobar.example.com';
  508. $this->assertEquals(
  509. 'https://foobar.example.com/foo/bar',
  510. $page->getHref()
  511. );
  512. }
  513. /**
  514. * @group ZF-7794
  515. */
  516. public function testHrefGeneratedWithSchemeIsRouteAware()
  517. {
  518. $page = new Zend_Navigation_Page_Mvc(array(
  519. 'action' => 'myaction',
  520. 'controller' => 'mycontroller',
  521. 'route' => 'myroute',
  522. 'params' => array(
  523. 'page' => 1337,
  524. ),
  525. 'scheme' => 'https',
  526. ));
  527. $this->_front->getRouter()->addRoute(
  528. 'myroute',
  529. new Zend_Controller_Router_Route(
  530. 'lolcat/:action/:page',
  531. array(
  532. 'module' => 'default',
  533. 'controller' => 'foobar',
  534. 'action' => 'bazbat',
  535. 'page' => 1,
  536. )
  537. )
  538. );
  539. $_SERVER['HTTP_HOST'] = 'foobar.example.com';
  540. $this->assertEquals(
  541. 'https://foobar.example.com/lolcat/myaction/1337',
  542. $page->getHref()
  543. );
  544. }
  545. public function testToArrayMethod()
  546. {
  547. $options = array(
  548. 'label' => 'foo',
  549. 'action' => 'index',
  550. 'controller' => 'index',
  551. 'module' => 'test',
  552. 'fragment' => 'bar',
  553. 'id' => 'my-id',
  554. 'class' => 'my-class',
  555. 'title' => 'my-title',
  556. 'target' => 'my-target',
  557. 'order' => 100,
  558. 'active' => true,
  559. 'visible' => false,
  560. 'encodeUrl' => false,
  561. 'scheme' => 'https',
  562. 'foo' => 'bar',
  563. 'meaning' => 42
  564. );
  565. $page = new Zend_Navigation_Page_Mvc($options);
  566. $toArray = $page->toArray();
  567. $options['reset_params'] = true;
  568. $options['route'] = null;
  569. $options['params'] = array();
  570. $options['rel'] = array();
  571. $options['rev'] = array();
  572. $this->assertEquals(
  573. array(),
  574. array_diff_assoc($options, $page->toArray())
  575. );
  576. }
  577. public function testSpecifyingAnotherUrlHelperToGenerateHrefs()
  578. {
  579. $path = dirname(dirname(__FILE__)) . '/_files/My/UrlHelper.php';
  580. require_once $path;
  581. $newHelper = new My_UrlHelper();
  582. Zend_Navigation_Page_Mvc::setUrlHelper($newHelper);
  583. $page = new Zend_Navigation_Page_Mvc();
  584. $expected = My_UrlHelper::RETURN_URL;
  585. $actual = $page->getHref();
  586. $old = Zend_Controller_Action_HelperBroker::getStaticHelper('Url');
  587. Zend_Navigation_Page_Mvc::setUrlHelper($old);
  588. $this->assertEquals($expected, $actual);
  589. }
  590. /**
  591. * @group ZF-7794
  592. */
  593. public function testSpecifyingAnotherSchemeHelperToGenerateHrefs()
  594. {
  595. $path = dirname(dirname(__FILE__)) . '/_files/My/SchemeHelper.php';
  596. require_once $path;
  597. $newHelper = new My_SchemeHelper();
  598. Zend_Navigation_Page_Mvc::setSchemeHelper($newHelper);
  599. $page = new Zend_Navigation_Page_Mvc(
  600. array(
  601. 'scheme' => 'https',
  602. )
  603. );
  604. $expected = My_SchemeHelper::RETURN_URL;
  605. $actual = $page->getHref();
  606. $old = new Zend_View_Helper_ServerUrl();
  607. Zend_Navigation_Page_Mvc::setSchemeHelper($old);
  608. $this->assertEquals($expected, $actual);
  609. }
  610. /**
  611. * @group ZF-11550
  612. */
  613. public function testNullValuesInMatchedRouteWillStillReturnMatchedPage()
  614. {
  615. $page = new Zend_Navigation_Page_Mvc(array(
  616. 'route' => 'default',
  617. 'module' => 'default',
  618. 'controller' => 'index',
  619. 'action' => 'index',
  620. 'label' => 'Home',
  621. 'title' => 'Home',
  622. ));
  623. $this->_front->getRouter()->addRoute(
  624. 'default',
  625. new Zend_Controller_Router_Route(
  626. ':locale/:module/:controller/:action/*',
  627. array(
  628. 'locale' => null,
  629. 'module' => 'default',
  630. 'controller' => 'index',
  631. 'action' => 'index',
  632. ),
  633. array(
  634. 'locale' => '.*',
  635. 'module' => '.*',
  636. 'controller' => '.*',
  637. 'action' => '.*',
  638. )
  639. )
  640. );
  641. $this->_front->getRequest()->setParams(array(
  642. 'locale' => 'en_US',
  643. 'module' => 'default',
  644. 'controller' => 'index',
  645. 'action' => 'index',
  646. ));
  647. $this->assertEquals(true, $page->isActive());
  648. }
  649. /**
  650. * @group ZF-12414
  651. */
  652. public function testNullValueInParameters()
  653. {
  654. // Create pages
  655. $pages = array();
  656. $pages['home'] = new Zend_Navigation_Page_Mvc(
  657. array(
  658. 'label' => 'Home',
  659. 'route' => 'page',
  660. 'params' => array(
  661. 'slug' => '',
  662. ),
  663. )
  664. );
  665. $pages['news'] = new Zend_Navigation_Page_Mvc(
  666. array(
  667. 'label' => 'News',
  668. 'route' => 'page',
  669. 'params' => array(
  670. 'slug' => 'news',
  671. ),
  672. )
  673. );
  674. // Add route
  675. $this->_front->getRouter()->addRoute(
  676. 'page',
  677. new Zend_Controller_Router_Route_Regex(
  678. '((?!(admin|page)).*)',
  679. array(
  680. 'module' => 'page',
  681. 'controller' => 'index',
  682. 'action' => 'index',
  683. ),
  684. array(
  685. 1 => 'slug',
  686. ),
  687. '%s'
  688. )
  689. );
  690. // Set request
  691. $this->_front->getRequest()->setParams(
  692. array(
  693. 'module' => 'page',
  694. 'controller' => 'index',
  695. 'action' => 'index',
  696. 'slug' => 'news',
  697. )
  698. );
  699. $this->assertTrue($pages['news']->isActive());
  700. $this->assertFalse($pages['home']->isActive());
  701. }
  702. }