MenuTest.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  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_View
  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 dirname(__FILE__) . '/TestAbstract.php';
  23. require_once 'Zend/View/Helper/Navigation/Menu.php';
  24. /**
  25. * Tests Zend_View_Helper_Navigation_Menu
  26. *
  27. * @category Zend
  28. * @package Zend_View
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_View
  33. * @group Zend_View_Helper
  34. */
  35. class Zend_View_Helper_Navigation_MenuTest
  36. extends Zend_View_Helper_Navigation_TestAbstract
  37. {
  38. /**
  39. * Class name for view helper to test
  40. *
  41. * @var string
  42. */
  43. protected $_helperName = 'Zend_View_Helper_Navigation_Menu';
  44. /**
  45. * View helper
  46. *
  47. * @var Zend_View_Helper_Navigation_Menu
  48. */
  49. protected $_helper;
  50. public function testHelperEntryPointWithoutAnyParams()
  51. {
  52. $returned = $this->_helper->menu();
  53. $this->assertEquals($this->_helper, $returned);
  54. $this->assertEquals($this->_nav1, $returned->getContainer());
  55. }
  56. public function testHelperEntryPointWithContainerParam()
  57. {
  58. $returned = $this->_helper->menu($this->_nav2);
  59. $this->assertEquals($this->_helper, $returned);
  60. $this->assertEquals($this->_nav2, $returned->getContainer());
  61. }
  62. public function testNullingOutContainerInHelper()
  63. {
  64. $this->_helper->setContainer();
  65. $this->assertEquals(0, count($this->_helper->getContainer()));
  66. }
  67. public function testAutoloadingContainerFromRegistry()
  68. {
  69. $oldReg = null;
  70. if (Zend_Registry::isRegistered(self::REGISTRY_KEY)) {
  71. $oldReg = Zend_Registry::get(self::REGISTRY_KEY);
  72. }
  73. Zend_Registry::set(self::REGISTRY_KEY, $this->_nav1);
  74. $this->_helper->setContainer(null);
  75. $expected = $this->_getExpected('menu/default1.html');
  76. $actual = $this->_helper->render();
  77. Zend_Registry::set(self::REGISTRY_KEY, $oldReg);
  78. $this->assertEquals($expected, $actual);
  79. }
  80. public function testSetIndentAndOverrideInRenderMenu()
  81. {
  82. $this->_helper->setIndent(8);
  83. $expected = array(
  84. 'indent4' => $this->_getExpected('menu/indent4.html'),
  85. 'indent8' => $this->_getExpected('menu/indent8.html')
  86. );
  87. $renderOptions = array(
  88. 'indent' => 4
  89. );
  90. $actual = array(
  91. 'indent4' => rtrim($this->_helper->renderMenu(null, $renderOptions), PHP_EOL),
  92. 'indent8' => rtrim($this->_helper->renderMenu(), PHP_EOL)
  93. );
  94. $this->assertEquals($expected, $actual);
  95. }
  96. public function testRenderSuppliedContainerWithoutInterfering()
  97. {
  98. $rendered1 = $this->_getExpected('menu/default1.html');
  99. $rendered2 = $this->_getExpected('menu/default2.html');
  100. $expected = array(
  101. 'registered' => $rendered1,
  102. 'supplied' => $rendered2,
  103. 'registered_again' => $rendered1
  104. );
  105. $actual = array(
  106. 'registered' => $this->_helper->render(),
  107. 'supplied' => $this->_helper->render($this->_nav2),
  108. 'registered_again' => $this->_helper->render()
  109. );
  110. $this->assertEquals($expected, $actual);
  111. }
  112. public function testUseAclRoleAsString()
  113. {
  114. $acl = $this->_getAcl();
  115. $this->_helper->setAcl($acl['acl']);
  116. $this->_helper->setRole('member');
  117. $expected = $this->_getExpected('menu/acl_string.html');
  118. $this->assertEquals($expected, $this->_helper->render());
  119. }
  120. public function testFilterOutPagesBasedOnAcl()
  121. {
  122. $acl = $this->_getAcl();
  123. $this->_helper->setAcl($acl['acl']);
  124. $this->_helper->setRole($acl['role']);
  125. $expected = $this->_getExpected('menu/acl.html');
  126. $actual = $this->_helper->render();
  127. $this->assertEquals($expected, $actual);
  128. }
  129. public function testDisablingAcl()
  130. {
  131. $acl = $this->_getAcl();
  132. $this->_helper->setAcl($acl['acl']);
  133. $this->_helper->setRole($acl['role']);
  134. $this->_helper->setUseAcl(false);
  135. $expected = $this->_getExpected('menu/default1.html');
  136. $actual = $this->_helper->render();
  137. $this->assertEquals($expected, $actual);
  138. }
  139. public function testUseAnAclRoleInstanceFromAclObject()
  140. {
  141. $acl = $this->_getAcl();
  142. $this->_helper->setAcl($acl['acl']);
  143. $this->_helper->setRole($acl['acl']->getRole('member'));
  144. $expected = $this->_getExpected('menu/acl_role_interface.html');
  145. $this->assertEquals($expected, $this->_helper->render());
  146. }
  147. public function testUseConstructedAclRolesNotFromAclObject()
  148. {
  149. $acl = $this->_getAcl();
  150. $this->_helper->setAcl($acl['acl']);
  151. $this->_helper->setRole(new Zend_Acl_Role('member'));
  152. $expected = $this->_getExpected('menu/acl_role_interface.html');
  153. $this->assertEquals($expected, $this->_helper->render());
  154. }
  155. public function testSetUlCssClass()
  156. {
  157. $this->_helper->setUlClass('My_Nav');
  158. $expected = $this->_getExpected('menu/css.html');
  159. $this->assertEquals($expected, $this->_helper->render($this->_nav2));
  160. }
  161. /**
  162. * @group ZF-10409
  163. */
  164. public function testSetPrefixForIdWithContent()
  165. {
  166. $this->_helper->setPrefixForId('test-');
  167. $expected = $this->_getExpected('menu/normalize-id-prefix-with-content.html');
  168. $this->assertEquals($expected, $this->_helper->render($this->_nav3));
  169. }
  170. /**
  171. * @group ZF-10409
  172. */
  173. public function testSetPrefixForIdWithoutContent()
  174. {
  175. $this->_helper->setPrefixForId('');
  176. $expected = $this->_getExpected('menu/normalize-id-prefix-without-content.html');
  177. $this->assertEquals($expected, $this->_helper->render($this->_nav3));
  178. }
  179. /**
  180. * @group ZF-10409
  181. */
  182. public function testSetPrefixForIdWithNull()
  183. {
  184. $this->_helper->setPrefixForId(null);
  185. $expected = $this->_getExpected('menu/normalize-id-prefix-with-null.html');
  186. $this->assertEquals($expected, $this->_helper->render($this->_nav3));
  187. }
  188. /**
  189. * @group ZF-10409
  190. */
  191. public function testGetPrefixForIdWithContent()
  192. {
  193. $this->_helper->setPrefixForId('test');
  194. $this->assertEquals('test', $this->_helper->getPrefixForId());
  195. }
  196. /**
  197. * @group ZF-10409
  198. */
  199. public function testGetPrefixForIdWithoutContent()
  200. {
  201. $this->_helper->setPrefixForId('');
  202. $this->assertEquals('', $this->_helper->getPrefixForId());
  203. }
  204. /**
  205. * @group ZF-10409
  206. */
  207. public function testGetPrefixForIdWithNull()
  208. {
  209. $this->_helper->setPrefixForId(null);
  210. $this->assertEquals('menu-', $this->_helper->getPrefixForId());
  211. }
  212. /**
  213. * @group ZF-10409
  214. */
  215. public function testSkipPrefixForIdTrue()
  216. {
  217. $this->_helper->skipPrefixForId(true);
  218. $expected = $this->_getExpected('menu/normalize-id-prefix-without-content.html');
  219. $this->assertEquals($expected, $this->_helper->render($this->_nav3));
  220. }
  221. /**
  222. * @group ZF-10409
  223. */
  224. public function testSkipPrefixForIdFalse()
  225. {
  226. $this->_helper->skipPrefixForId(false);
  227. $expected = $this->_getExpected('menu/normalize-id-prefix-with-null.html');
  228. $this->assertEquals($expected, $this->_helper->render($this->_nav3));
  229. }
  230. public function testTranslationUsingZendTranslate()
  231. {
  232. $translator = $this->_getTranslator();
  233. $this->_helper->setTranslator($translator);
  234. $expected = $this->_getExpected('menu/translated.html');
  235. $this->assertEquals($expected, $this->_helper->render());
  236. }
  237. public function testTranslationUsingZendTranslateAdapter()
  238. {
  239. $translator = $this->_getTranslator();
  240. $this->_helper->setTranslator($translator->getAdapter());
  241. $expected = $this->_getExpected('menu/translated.html');
  242. $this->assertEquals($expected, $this->_helper->render());
  243. }
  244. public function testTranslationUsingTranslatorFromRegistry()
  245. {
  246. $oldReg = Zend_Registry::isRegistered('Zend_Translate')
  247. ? Zend_Registry::get('Zend_Translate')
  248. : null;
  249. $translator = $this->_getTranslator();
  250. Zend_Registry::set('Zend_Translate', $translator);
  251. $expected = $this->_getExpected('menu/translated.html');
  252. $actual = $this->_helper->render();
  253. Zend_Registry::set('Zend_Translate', $oldReg);
  254. $this->assertEquals($expected, $actual);
  255. }
  256. public function testDisablingTranslation()
  257. {
  258. $translator = $this->_getTranslator();
  259. $this->_helper->setTranslator($translator);
  260. $this->_helper->setUseTranslator(false);
  261. $expected = $this->_getExpected('menu/default1.html');
  262. $this->assertEquals($expected, $this->_helper->render());
  263. }
  264. public function testRenderingPartial()
  265. {
  266. $this->_helper->setPartial('menu.phtml');
  267. $expected = $this->_getExpected('menu/partial.html');
  268. $actual = $this->_helper->render();
  269. $this->assertEquals($expected, $actual);
  270. }
  271. public function testRenderingPartialBySpecifyingAnArrayAsPartial()
  272. {
  273. $this->_helper->setPartial(array('menu.phtml', 'default'));
  274. $expected = $this->_getExpected('menu/partial.html');
  275. $actual = $this->_helper->render();
  276. $this->assertEquals($expected, $actual);
  277. }
  278. public function testRenderingPartialShouldFailOnInvalidPartialArray()
  279. {
  280. $this->_helper->setPartial(array('menu.phtml'));
  281. try {
  282. $this->_helper->render();
  283. $this->fail('invalid $partial should throw Zend_View_Exception');
  284. } catch (Zend_View_Exception $e) {
  285. }
  286. }
  287. public function testSetMaxDepth()
  288. {
  289. $this->_helper->setMaxDepth(1);
  290. $expected = $this->_getExpected('menu/maxdepth.html');
  291. $actual = $this->_helper->renderMenu();
  292. $this->assertEquals($expected, $actual);
  293. }
  294. public function testSetMinDepth()
  295. {
  296. $this->_helper->setMinDepth(1);
  297. $expected = $this->_getExpected('menu/mindepth.html');
  298. $actual = $this->_helper->renderMenu();
  299. $this->assertEquals($expected, $actual);
  300. }
  301. public function testSetBothDepts()
  302. {
  303. $this->_helper->setMinDepth(1)->setMaxDepth(2);
  304. $expected = $this->_getExpected('menu/bothdepts.html');
  305. $actual = $this->_helper->renderMenu();
  306. $this->assertEquals($expected, $actual);
  307. }
  308. public function testSetOnlyActiveBranch()
  309. {
  310. $this->_helper->setOnlyActiveBranch(true);
  311. $expected = $this->_getExpected('menu/onlyactivebranch.html');
  312. $actual = $this->_helper->renderMenu();
  313. $this->assertEquals($expected, $actual);
  314. }
  315. public function testSetRenderParents()
  316. {
  317. $this->_helper->setOnlyActiveBranch(true)->setRenderParents(false);
  318. $expected = $this->_getExpected('menu/onlyactivebranch_noparents.html');
  319. $actual = $this->_helper->renderMenu();
  320. $this->assertEquals($expected, $actual);
  321. }
  322. public function testSetOnlyActiveBranchAndMinDepth()
  323. {
  324. $this->_helper->setOnlyActiveBranch()->setMinDepth(1);
  325. $expected = $this->_getExpected('menu/onlyactivebranch_mindepth.html');
  326. $actual = $this->_helper->renderMenu();
  327. $this->assertEquals($expected, $actual);
  328. }
  329. public function testOnlyActiveBranchAndMaxDepth()
  330. {
  331. $this->_helper->setOnlyActiveBranch()->setMaxDepth(2);
  332. $expected = $this->_getExpected('menu/onlyactivebranch_maxdepth.html');
  333. $actual = $this->_helper->renderMenu();
  334. $this->assertEquals($expected, $actual);
  335. }
  336. public function testOnlyActiveBranchAndBothDepthsSpecified()
  337. {
  338. $this->_helper->setOnlyActiveBranch()->setMinDepth(1)->setMaxDepth(2);
  339. $expected = $this->_getExpected('menu/onlyactivebranch_bothdepts.html');
  340. $actual = $this->_helper->renderMenu();
  341. $this->assertEquals($expected, $actual);
  342. }
  343. public function testOnlyActiveBranchNoParentsAndBothDepthsSpecified()
  344. {
  345. $this->_helper->setOnlyActiveBranch()
  346. ->setMinDepth(1)
  347. ->setMaxDepth(2)
  348. ->setRenderParents(false);
  349. $expected = $this->_getExpected('menu/onlyactivebranch_np_bd.html');
  350. $actual = $this->_helper->renderMenu();
  351. $this->assertEquals($expected, $actual);
  352. }
  353. private function _setActive($label)
  354. {
  355. $container = $this->_helper->getContainer();
  356. foreach ($container->findAllByActive(true) as $page) {
  357. $page->setActive(false);
  358. }
  359. if ($p = $container->findOneByLabel($label)) {
  360. $p->setActive(true);
  361. }
  362. }
  363. public function testOnlyActiveBranchNoParentsActiveOneBelowMinDepth()
  364. {
  365. $this->_setActive('Page 2');
  366. $this->_helper->setOnlyActiveBranch()
  367. ->setMinDepth(1)
  368. ->setMaxDepth(1)
  369. ->setRenderParents(false);
  370. $expected = $this->_getExpected('menu/onlyactivebranch_np_bd2.html');
  371. $actual = $this->_helper->renderMenu();
  372. $this->assertEquals($expected, $actual);
  373. }
  374. public function testRenderSubMenuShouldOverrideOptions()
  375. {
  376. $this->_helper->setOnlyActiveBranch(false)
  377. ->setMinDepth(1)
  378. ->setMaxDepth(2)
  379. ->setRenderParents(true);
  380. $expected = $this->_getExpected('menu/onlyactivebranch_noparents.html');
  381. $actual = $this->_helper->renderSubMenu();
  382. $this->assertEquals($expected, $actual);
  383. }
  384. public function testOptionMaxDepth()
  385. {
  386. $options = array(
  387. 'maxDepth' => 1
  388. );
  389. $expected = $this->_getExpected('menu/maxdepth.html');
  390. $actual = $this->_helper->renderMenu(null, $options);
  391. $this->assertEquals($expected, $actual);
  392. }
  393. public function testOptionMinDepth()
  394. {
  395. $options = array(
  396. 'minDepth' => 1
  397. );
  398. $expected = $this->_getExpected('menu/mindepth.html');
  399. $actual = $this->_helper->renderMenu(null, $options);
  400. $this->assertEquals($expected, $actual);
  401. }
  402. public function testOptionBothDepts()
  403. {
  404. $options = array(
  405. 'minDepth' => 1,
  406. 'maxDepth' => 2
  407. );
  408. $expected = $this->_getExpected('menu/bothdepts.html');
  409. $actual = $this->_helper->renderMenu(null, $options);
  410. $this->assertEquals($expected, $actual);
  411. }
  412. public function testOptionOnlyActiveBranch()
  413. {
  414. $options = array(
  415. 'onlyActiveBranch' => true
  416. );
  417. $expected = $this->_getExpected('menu/onlyactivebranch.html');
  418. $actual = $this->_helper->renderMenu(null, $options);
  419. $this->assertEquals($expected, $actual);
  420. }
  421. public function testOptionOnlyActiveBranchNoParents()
  422. {
  423. $options = array(
  424. 'onlyActiveBranch' => true,
  425. 'renderParents' => false
  426. );
  427. $expected = $this->_getExpected('menu/onlyactivebranch_noparents.html');
  428. $actual = $this->_helper->renderMenu(null, $options);
  429. $this->assertEquals($expected, $actual);
  430. }
  431. public function testOptionOnlyActiveBranchAndMinDepth()
  432. {
  433. $options = array(
  434. 'minDepth' => 1,
  435. 'onlyActiveBranch' => true
  436. );
  437. $expected = $this->_getExpected('menu/onlyactivebranch_mindepth.html');
  438. $actual = $this->_helper->renderMenu(null, $options);
  439. $this->assertEquals($expected, $actual);
  440. }
  441. public function testOptionOnlyActiveBranchAndMaxDepth()
  442. {
  443. $options = array(
  444. 'maxDepth' => 2,
  445. 'onlyActiveBranch' => true
  446. );
  447. $expected = $this->_getExpected('menu/onlyactivebranch_maxdepth.html');
  448. $actual = $this->_helper->renderMenu(null, $options);
  449. $this->assertEquals($expected, $actual);
  450. }
  451. public function testOptionOnlyActiveBranchAndBothDepthsSpecified()
  452. {
  453. $options = array(
  454. 'minDepth' => 1,
  455. 'maxDepth' => 2,
  456. 'onlyActiveBranch' => true
  457. );
  458. $expected = $this->_getExpected('menu/onlyactivebranch_bothdepts.html');
  459. $actual = $this->_helper->renderMenu(null, $options);
  460. $this->assertEquals($expected, $actual);
  461. }
  462. public function testOptionOnlyActiveBranchNoParentsAndBothDepthsSpecified()
  463. {
  464. $options = array(
  465. 'minDepth' => 2,
  466. 'maxDepth' => 2,
  467. 'onlyActiveBranch' => true,
  468. 'renderParents' => false
  469. );
  470. $expected = $this->_getExpected('menu/onlyactivebranch_np_bd.html');
  471. $actual = $this->_helper->renderMenu(null, $options);
  472. $this->assertEquals($expected, $actual);
  473. }
  474. /**
  475. * @group ZF-9746
  476. */
  477. public function testRenderingWithAccesskey()
  478. {
  479. $this->_nav3->findOneBy('id', 'home')->setAccesskey('H');
  480. $this->_nav3->findOneBy('uri', 'contact')->setAccesskey('c');
  481. $this->_nav3->findOneBy('id', 'imprint')->setAccesskey('i');
  482. $expected = $this->_getExpected('menu/accesskey.html');
  483. $this->assertEquals($expected, $this->_helper->render($this->_nav3));
  484. }
  485. /**
  486. * @group ZF-6941
  487. */
  488. public function testExpandSiblingNodesOfActiveBranch()
  489. {
  490. $this->_helper->setExpandSiblingNodesOfActiveBranch(true);
  491. $expected = $this->_getExpected('menu/expandbranch.html');
  492. $actual = $this->_helper->renderMenu();
  493. $this->assertEquals($expected, $actual);
  494. }
  495. /**
  496. * @group ZF-6941
  497. */
  498. public function testExpandSiblingNodesOfActiveBranchWhenShowingOnlyActiveBranch()
  499. {
  500. $this->_helper->setExpandSiblingNodesOfActiveBranch(true)->setOnlyActiveBranch(true);
  501. $expected = $this->_getExpected('menu/expandbranch_onlyactivebranch.html');
  502. $actual = $this->_helper->renderMenu();
  503. $this->assertEquals($expected, $actual);
  504. }
  505. /**
  506. * @group ZF-11876
  507. */
  508. public function testRenderingWithCustomHtmlAttribs()
  509. {
  510. $this->_nav3->findOneBy('id', 'home')->setCustomHtmlAttrib('rel', 'nofollow');
  511. $this->_nav3->findOneBy('uri', 'contact')->setCustomHtmlAttribs(
  512. array(
  513. 'rel' => 'nofollow',
  514. 'style' => 'font-weight: bold;',
  515. )
  516. );
  517. $this->_nav3->findOneBy('id', 'imprint')->setCustomHtmlAttrib('rel', 'nofollow');
  518. $expected = $this->_getExpected('menu/customhtmlattribs.html');
  519. $this->assertEquals($expected, $this->_helper->render($this->_nav3));
  520. }
  521. /**
  522. * @group ZF-7212
  523. */
  524. public function testRenderingWithUlId()
  525. {
  526. $this->_helper->setUlId('foo');
  527. $this->assertContains(
  528. '<ul class="navigation" id="foo">',
  529. $this->_helper->renderMenu()
  530. );
  531. }
  532. /**
  533. * @group ZF-7212
  534. */
  535. public function testRenderingWithUlIdPerOptions()
  536. {
  537. $this->assertContains(
  538. '<ul class="navigation" id="foo">',
  539. $this->_helper->renderMenu(null, array('ulId' => 'foo'))
  540. );
  541. }
  542. /**
  543. * @group ZF-7212
  544. */
  545. public function testRenderingOnlyActiveBranchWithUlId()
  546. {
  547. $this->_helper->setUlId('foo')
  548. ->setOnlyActiveBranch()
  549. ->setRenderParents();
  550. $this->assertContains(
  551. '<ul class="navigation" id="foo">',
  552. $this->_helper->renderMenu()
  553. );
  554. }
  555. /**
  556. * @group ZF-7212
  557. */
  558. public function testRenderingSubMenuWithUlId()
  559. {
  560. $this->assertContains(
  561. '<ul class="navigation" id="foo">',
  562. $this->_helper->renderSubMenu(null, null, null, 'foo')
  563. );
  564. }
  565. /**
  566. * @group ZF-7212
  567. */
  568. public function testRenderingDeepestMenuWithUlId()
  569. {
  570. $this->assertContains(
  571. '<ul class="navigation" id="foo">',
  572. $this->_helper->renderMenu(null, array('ulId' => 'foo'))
  573. );
  574. }
  575. /**
  576. * @group ZF-7003
  577. */
  578. public function testSetAddPageClassToLi()
  579. {
  580. $this->_helper->addPageClassToLi();
  581. $this->assertTrue($this->_helper->getAddPageClassToLi());
  582. }
  583. /**
  584. * @group ZF-7003
  585. */
  586. public function testRenderingWithPageClassToLi()
  587. {
  588. $this->_helper->addPageClassToLi();
  589. // Add css class
  590. $container = $this->_helper->getContainer();
  591. $container->findBy('href', 'page1')->setClass('foo');
  592. // Tests
  593. $this->assertContains(
  594. '<li class="foo">',
  595. $this->_helper->renderMenu()
  596. );
  597. $this->assertNotContains(
  598. '<a class="foo" href="page1">Page 1</a>',
  599. $this->_helper->renderMenu()
  600. );
  601. }
  602. /**
  603. * @group ZF-7003
  604. */
  605. public function testRenderDeepestMenuWithPageClassToLi()
  606. {
  607. // Add css class
  608. $container = $this->_helper->getContainer();
  609. $container->findBy('label', 'Page 2.3.3.1')->setClass('foo');
  610. // Tests
  611. $options = array(
  612. 'onlyActiveBranch' => true,
  613. 'renderParents' => false,
  614. 'addPageClassToLi' => true,
  615. );
  616. $this->assertContains(
  617. '<li class="active foo">',
  618. $this->_helper->renderMenu(null, $options)
  619. );
  620. $this->assertNotContains(
  621. '<a class="foo" href="page1">Page 1</a>',
  622. $this->_helper->renderMenu(null, $options)
  623. );
  624. }
  625. /**
  626. * @group ZF-9543
  627. */
  628. public function testSetActiveClass()
  629. {
  630. $this->_helper->setActiveClass('current');
  631. // Test getter
  632. $this->assertEquals('current', $this->_helper->getActiveClass());
  633. // Test rendering
  634. $expected = $this->_getExpected('menu/css_active.html');
  635. $this->assertEquals($expected, $this->_helper->render($this->_nav2));
  636. }
  637. /**
  638. * @group ZF-9543
  639. */
  640. public function testRenderDeepestMenuWithCustomActiveClass()
  641. {
  642. // Tests
  643. $options = array(
  644. 'onlyActiveBranch' => true,
  645. 'renderParents' => false,
  646. 'activeClass' => 'current',
  647. );
  648. $html = $this->_helper->renderMenu(null, $options);
  649. $this->assertContains('<li class="current">', $html);
  650. $this->assertNotContains('<li class="active">', $html);
  651. }
  652. /**
  653. * @group ZF-8951
  654. */
  655. public function testSetRenderParentClass()
  656. {
  657. $this->_helper->setRenderParentClass(true);
  658. $this->assertTrue($this->_helper->getRenderParentClass());
  659. }
  660. /**
  661. * @group ZF-8951
  662. */
  663. public function testSetParentClass()
  664. {
  665. $this->_helper->setParentClass('foo');
  666. $this->assertEquals('foo', $this->_helper->getParentClass());
  667. }
  668. /**
  669. * @group ZF-8951
  670. */
  671. public function testOptionRenderParentClass()
  672. {
  673. $expected = $this->_getExpected('menu/parentclass_standard.html');
  674. $actual = $this->_helper->renderMenu(
  675. null ,
  676. array(
  677. 'renderParentClass' => true,
  678. )
  679. );
  680. $this->assertEquals($expected, $actual);
  681. }
  682. /**
  683. * @group ZF-8951
  684. */
  685. public function testOptionRenderParentClassAndParentClass()
  686. {
  687. $expected = $this->_getExpected('menu/parentclass_custom.html');
  688. $actual = $this->_helper->renderMenu(
  689. null ,
  690. array(
  691. 'renderParentClass' => true,
  692. 'parentClass' => 'foo',
  693. )
  694. );
  695. $this->assertEquals($expected, $actual);
  696. }
  697. /**
  698. * @group ZF-8951
  699. */
  700. public function testRenderingWithStandardParentClass()
  701. {
  702. $this->_helper->setRenderParentClass(true);
  703. $expected = $this->_getExpected('menu/parentclass_standard.html');
  704. $this->assertEquals($expected, $this->_helper->render());
  705. }
  706. /**
  707. * @group ZF-8951
  708. */
  709. public function testRenderingWithCustomParentClass()
  710. {
  711. $this->_helper->setRenderParentClass(true);
  712. $this->_helper->setParentClass('foo');
  713. $expected = $this->_getExpected('menu/parentclass_custom.html');
  714. $this->assertEquals($expected, $this->_helper->render());
  715. }
  716. /**
  717. * @group ZF-8951
  718. */
  719. public function testRenderingWithParentClassAndBothDepts()
  720. {
  721. $this->_helper->setRenderParentClass(true);
  722. $expected = $this->_getExpected('menu/parentclass_bothdepts.html');
  723. $actual = $this->_helper->setMinDepth(1)->setMaxDepth(2)->render();
  724. $this->assertEquals($expected, $actual);
  725. }
  726. /**
  727. * @group ZF-8951
  728. */
  729. public function testRenderingWithParentClassAndOnlyActiveBranchAndBothDepts()
  730. {
  731. $this->_helper->setRenderParentClass(true);
  732. $this->_helper->setOnlyActiveBranch(true);
  733. $expected = $this->_getExpected('menu/parentclass_onlyactivebranch_bothdepts.html');
  734. $actual = $this->_helper->setMinDepth(1)->setMaxDepth(2)->render();
  735. $this->assertEquals($expected, $actual);
  736. }
  737. }