MvcTest.php 25 KB

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