2
0

LinksTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. <?php
  2. require_once dirname(__FILE__) . '/TestAbstract.php';
  3. require_once 'Zend/View/Helper/Navigation/Links.php';
  4. /**
  5. * Tests Zend_View_Helper_Navigation_Links
  6. *
  7. * @author Robin Skoglund
  8. * @category Zend_Tests
  9. * @package Zend_View
  10. * @subpackage Helper
  11. * @copyright Copyright (c) 2008 Zend. (http://www.zym-project.com/)
  12. * @license http://www.zym-project.com/license New BSD License
  13. */
  14. class Zend_View_Helper_Navigation_LinksTest
  15. extends Zend_View_Helper_Navigation_TestAbstract
  16. {
  17. /**
  18. * Class name for view helper to test
  19. *
  20. * @var string
  21. */
  22. protected $_helperName = 'Zend_View_Helper_Navigation_Links';
  23. /**
  24. * View helper
  25. *
  26. * @var Zend_View_Helper_Navigation_Links
  27. */
  28. protected $_helper;
  29. private $_doctypeHelper;
  30. private $_oldDoctype;
  31. public function setUp()
  32. {
  33. parent::setUp();
  34. // doctype fix (someone forgot to clean up after their unit tests)
  35. $this->_doctypeHelper = $this->_helper->view->doctype();
  36. $this->_oldDoctype = $this->_doctypeHelper->getDoctype();
  37. $this->_doctypeHelper->setDoctype(
  38. Zend_View_Helper_Doctype::HTML4_LOOSE);
  39. // disable all active pages
  40. foreach ($this->_helper->findAllByActive(true) as $page) {
  41. $page->active = false;
  42. }
  43. }
  44. public function tearDown()
  45. {
  46. $this->_doctypeHelper->setDoctype($this->_oldDoctype);
  47. }
  48. public function testHelperEntryPointWithoutAnyParams()
  49. {
  50. $returned = $this->_helper->links();
  51. $this->assertEquals($this->_helper, $returned);
  52. $this->assertEquals($this->_nav1, $returned->getContainer());
  53. }
  54. public function testHelperEntryPointWithContainerParam()
  55. {
  56. $returned = $this->_helper->links($this->_nav2);
  57. $this->assertEquals($this->_helper, $returned);
  58. $this->assertEquals($this->_nav2, $returned->getContainer());
  59. }
  60. public function testDoNotRenderIfNoPageIsActive()
  61. {
  62. $this->assertEquals('', $this->_helper->render());
  63. }
  64. public function testDetectRelationFromStringPropertyOfActivePage()
  65. {
  66. $active = $this->_helper->findOneByLabel('Page 2');
  67. $active->addRel('example', 'http://www.example.com/');
  68. $found = $this->_helper->findRelation($active, 'rel', 'example');
  69. $expected = array(
  70. 'type' => 'Zend_Navigation_Page_Uri',
  71. 'href' => 'http://www.example.com/',
  72. 'label' => null
  73. );
  74. $actual = array(
  75. 'type' => get_class($found),
  76. 'href' => $found->getHref(),
  77. 'label' => $found->getLabel()
  78. );
  79. $this->assertEquals($expected, $actual);
  80. }
  81. public function testDetectRelationFromPageInstancePropertyOfActivePage()
  82. {
  83. $active = $this->_helper->findOneByLabel('Page 2');
  84. $active->addRel('example', Zend_Navigation_Page::factory(array(
  85. 'uri' => 'http://www.example.com/',
  86. 'label' => 'An example page'
  87. )));
  88. $found = $this->_helper->findRelExample($active);
  89. $expected = array(
  90. 'type' => 'Zend_Navigation_Page_Uri',
  91. 'href' => 'http://www.example.com/',
  92. 'label' => 'An example page'
  93. );
  94. $actual = array(
  95. 'type' => get_class($found),
  96. 'href' => $found->getHref(),
  97. 'label' => $found->getLabel()
  98. );
  99. $this->assertEquals($expected, $actual);
  100. }
  101. public function testDetectRelationFromArrayPropertyOfActivePage()
  102. {
  103. $active = $this->_helper->findOneByLabel('Page 2');
  104. $active->addRel('example', array(
  105. 'uri' => 'http://www.example.com/',
  106. 'label' => 'An example page'
  107. ));
  108. $found = $this->_helper->findRelExample($active);
  109. $expected = array(
  110. 'type' => 'Zend_Navigation_Page_Uri',
  111. 'href' => 'http://www.example.com/',
  112. 'label' => 'An example page'
  113. );
  114. $actual = array(
  115. 'type' => get_class($found),
  116. 'href' => $found->getHref(),
  117. 'label' => $found->getLabel()
  118. );
  119. $this->assertEquals($expected, $actual);
  120. }
  121. public function testDetectRelationFromConfigInstancePropertyOfActivePage()
  122. {
  123. $active = $this->_helper->findOneByLabel('Page 2');
  124. $active->addRel('example', new Zend_Config(array(
  125. 'uri' => 'http://www.example.com/',
  126. 'label' => 'An example page'
  127. )));
  128. $found = $this->_helper->findRelExample($active);
  129. $expected = array(
  130. 'type' => 'Zend_Navigation_Page_Uri',
  131. 'href' => 'http://www.example.com/',
  132. 'label' => 'An example page'
  133. );
  134. $actual = array(
  135. 'type' => get_class($found),
  136. 'href' => $found->getHref(),
  137. 'label' => $found->getLabel()
  138. );
  139. $this->assertEquals($expected, $actual);
  140. }
  141. public function testDetectMultipleRelationsFromArrayPropertyOfActivePage()
  142. {
  143. $active = $this->_helper->findOneByLabel('Page 2');
  144. $active->addRel('alternate', array(
  145. array(
  146. 'label' => 'foo',
  147. 'uri' => 'bar'
  148. ),
  149. array(
  150. 'label' => 'baz',
  151. 'uri' => 'bat'
  152. )
  153. ));
  154. $found = $this->_helper->findRelAlternate($active);
  155. $expected = array('type' => 'array', 'count' => 2);
  156. $actual = array('type' => gettype($found), 'count' => count($found));
  157. $this->assertEquals($expected, $actual);
  158. }
  159. public function testDetectMultipleRelationsFromConfigPropertyOfActivePage()
  160. {
  161. $active = $this->_helper->findOneByLabel('Page 2');
  162. $active->addRel('alternate', new Zend_Config(array(
  163. array(
  164. 'label' => 'foo',
  165. 'uri' => 'bar'
  166. ),
  167. array(
  168. 'label' => 'baz',
  169. 'uri' => 'bat'
  170. )
  171. )));
  172. $found = $this->_helper->findRelAlternate($active);
  173. $expected = array('type' => 'array', 'count' => 2);
  174. $actual = array('type' => gettype($found), 'count' => count($found));
  175. $this->assertEquals($expected, $actual);
  176. }
  177. public function testExtractingRelationsFromPageProperties()
  178. {
  179. $types = array(
  180. 'alternate', 'stylesheet', 'start', 'next', 'prev', 'contents',
  181. 'index', 'glossary', 'copyright', 'chapter', 'section', 'subsection',
  182. 'appendix', 'help', 'bookmark'
  183. );
  184. $samplePage = Zend_Navigation_Page::factory(array(
  185. 'label' => 'An example page',
  186. 'uri' => 'http://www.example.com/'
  187. ));
  188. $active = $this->_helper->findOneByLabel('Page 2');
  189. $expected = array();
  190. $actual = array();
  191. foreach ($types as $type) {
  192. $active->addRel($type, $samplePage);
  193. $found = $this->_helper->findRelation($active, 'rel', $type);
  194. $expected[$type] = $samplePage->getLabel();
  195. $actual[$type] = $found->getLabel();
  196. $active->removeRel($type);
  197. }
  198. $this->assertEquals($expected, $actual);
  199. }
  200. public function testFindStartPageByTraversal()
  201. {
  202. $active = $this->_helper->findOneByLabel('Page 2.1');
  203. $expected = 'Home';
  204. $actual = $this->_helper->findRelStart($active)->getLabel();
  205. $this->assertEquals($expected, $actual);
  206. }
  207. public function testDoNotFindStartWhenGivenPageIsTheFirstPage()
  208. {
  209. $active = $this->_helper->findOneByLabel('Home');
  210. $actual = $this->_helper->findRelStart($active);
  211. $this->assertNull($actual, 'Should not find any start page');
  212. }
  213. public function testFindNextPageByTraversalShouldFindChildPage()
  214. {
  215. $active = $this->_helper->findOneByLabel('Page 2');
  216. $expected = 'Page 2.1';
  217. $actual = $this->_helper->findRelNext($active)->getLabel();
  218. $this->assertEquals($expected, $actual);
  219. }
  220. public function testFindNextPageByTraversalShouldFindSiblingPage()
  221. {
  222. $active = $this->_helper->findOneByLabel('Page 2.1');
  223. $expected = 'Page 2.2';
  224. $actual = $this->_helper->findRelNext($active)->getLabel();
  225. $this->assertEquals($expected, $actual);
  226. }
  227. public function testFindNextPageByTraversalShouldWrap()
  228. {
  229. $active = $this->_helper->findOneByLabel('Page 2.2.2');
  230. $expected = 'Page 2.3';
  231. $actual = $this->_helper->findRelNext($active)->getLabel();
  232. $this->assertEquals($expected, $actual);
  233. }
  234. public function testFindPrevPageByTraversalShouldFindParentPage()
  235. {
  236. $active = $this->_helper->findOneByLabel('Page 2.1');
  237. $expected = 'Page 2';
  238. $actual = $this->_helper->findRelPrev($active)->getLabel();
  239. $this->assertEquals($expected, $actual);
  240. }
  241. public function testFindPrevPageByTraversalShouldFindSiblingPage()
  242. {
  243. $active = $this->_helper->findOneByLabel('Page 2.2');
  244. $expected = 'Page 2.1';
  245. $actual = $this->_helper->findRelPrev($active)->getLabel();
  246. $this->assertEquals($expected, $actual);
  247. }
  248. public function testFindPrevPageByTraversalShouldWrap()
  249. {
  250. $active = $this->_helper->findOneByLabel('Page 2.3');
  251. $expected = 'Page 2.2.2';
  252. $actual = $this->_helper->findRelPrev($active)->getLabel();
  253. $this->assertEquals($expected, $actual);
  254. }
  255. public function testShouldFindChaptersFromFirstLevelOfPagesInContainer()
  256. {
  257. $active = $this->_helper->findOneByLabel('Page 2.3');
  258. $found = $this->_helper->findRelChapter($active);
  259. $expected = array('Page 1', 'Page 2', 'Page 3', 'Zym');
  260. $actual = array();
  261. foreach ($found as $page) {
  262. $actual[] = $page->getLabel();
  263. }
  264. $this->assertEquals($expected, $actual);
  265. }
  266. public function testFindingChaptersShouldExcludeSelfIfChapter()
  267. {
  268. $active = $this->_helper->findOneByLabel('Page 2');
  269. $found = $this->_helper->findRelChapter($active);
  270. $expected = array('Page 1', 'Page 3', 'Zym');
  271. $actual = array();
  272. foreach ($found as $page) {
  273. $actual[] = $page->getLabel();
  274. }
  275. $this->assertEquals($expected, $actual);
  276. }
  277. public function testFindSectionsWhenActiveChapterPage()
  278. {
  279. $active = $this->_helper->findOneByLabel('Page 2');
  280. $found = $this->_helper->findRelSection($active);
  281. $expected = array('Page 2.1', 'Page 2.2', 'Page 2.3');
  282. $actual = array();
  283. foreach ($found as $page) {
  284. $actual[] = $page->getLabel();
  285. }
  286. $this->assertEquals($expected, $actual);
  287. }
  288. public function testDoNotFindSectionsWhenActivePageIsASection()
  289. {
  290. $active = $this->_helper->findOneByLabel('Page 2.2');
  291. $found = $this->_helper->findRelSection($active);
  292. $this->assertNull($found);
  293. }
  294. public function testDoNotFindSectionsWhenActivePageIsASubsection()
  295. {
  296. $active = $this->_helper->findOneByLabel('Page 2.2.1');
  297. $found = $this->_helper->findRelation($active, 'rel', 'section');
  298. $this->assertNull($found);
  299. }
  300. public function testFindSubsectionWhenActivePageIsSection()
  301. {
  302. $active = $this->_helper->findOneByLabel('Page 2.2');
  303. $found = $this->_helper->findRelSubsection($active);
  304. $expected = array('Page 2.2.1', 'Page 2.2.2');
  305. $actual = array();
  306. foreach ($found as $page) {
  307. $actual[] = $page->getLabel();
  308. }
  309. $this->assertEquals($expected, $actual);
  310. }
  311. public function testDoNotFindSubsectionsWhenActivePageIsASubSubsection()
  312. {
  313. $active = $this->_helper->findOneByLabel('Page 2.2.1');
  314. $found = $this->_helper->findRelSubsection($active);
  315. $this->assertNull($found);
  316. }
  317. public function testDoNotFindSubsectionsWhenActivePageIsAChapter()
  318. {
  319. $active = $this->_helper->findOneByLabel('Page 2');
  320. $found = $this->_helper->findRelSubsection($active);
  321. $this->assertNull($found);
  322. }
  323. public function testFindRevSectionWhenPageIsSection()
  324. {
  325. $active = $this->_helper->findOneByLabel('Page 2.2');
  326. $found = $this->_helper->findRevSection($active);
  327. $this->assertEquals('Page 2', $found->getLabel());
  328. }
  329. public function testFindRevSubsectionWhenPageIsSubsection()
  330. {
  331. $active = $this->_helper->findOneByLabel('Page 2.2.1');
  332. $found = $this->_helper->findRevSubsection($active);
  333. $this->assertEquals('Page 2.2', $found->getLabel());
  334. }
  335. public function testAclFiltersAwayPagesFromPageProperty()
  336. {
  337. $acl = new Zend_Acl();
  338. $acl->addRole(new Zend_Acl_Role('member'));
  339. $acl->addRole(new Zend_Acl_Role('admin'));
  340. $acl->add(new Zend_Acl_Resource('protected'));
  341. $acl->allow('admin', 'protected');
  342. $this->_helper->setAcl($acl);
  343. $this->_helper->setRole($acl->getRole('member'));
  344. $samplePage = Zend_Navigation_Page::factory(array(
  345. 'label' => 'An example page',
  346. 'uri' => 'http://www.example.com/',
  347. 'resource' => 'protected'
  348. ));
  349. $active = $this->_helper->findOneByLabel('Home');
  350. $expected = array(
  351. 'alternate' => false,
  352. 'stylesheet' => false,
  353. 'start' => false,
  354. 'next' => 'Page 1',
  355. 'prev' => false,
  356. 'contents' => false,
  357. 'index' => false,
  358. 'glossary' => false,
  359. 'copyright' => false,
  360. 'chapter' => 'array(4)',
  361. 'section' => false,
  362. 'subsection' => false,
  363. 'appendix' => false,
  364. 'help' => false,
  365. 'bookmark' => false
  366. );
  367. $actual = array();
  368. foreach ($expected as $type => $discard) {
  369. $active->addRel($type, $samplePage);
  370. $found = $this->_helper->findRelation($active, 'rel', $type);
  371. if (null === $found) {
  372. $actual[$type] = false;
  373. } elseif (is_array($found)) {
  374. $actual[$type] = 'array(' . count($found) . ')';
  375. } else {
  376. $actual[$type] = $found->getLabel();
  377. }
  378. }
  379. $this->assertEquals($expected, $actual);
  380. }
  381. public function testAclFiltersAwayPagesFromContainerSearch()
  382. {
  383. $acl = new Zend_Acl();
  384. $acl->addRole(new Zend_Acl_Role('member'));
  385. $acl->addRole(new Zend_Acl_Role('admin'));
  386. $acl->add(new Zend_Acl_Resource('protected'));
  387. $acl->allow('admin', 'protected');
  388. $this->_helper->setAcl($acl);
  389. $this->_helper->setRole($acl->getRole('member'));
  390. $oldContainer = $this->_helper->getContainer();
  391. $container = $this->_helper->getContainer();
  392. $iterator = new RecursiveIteratorIterator(
  393. $container,
  394. RecursiveIteratorIterator::SELF_FIRST);
  395. foreach ($iterator as $page) {
  396. $page->resource = 'protected';
  397. }
  398. $this->_helper->setContainer($container);
  399. $active = $this->_helper->findOneByLabel('Home');
  400. $search = array(
  401. 'start' => 'Page 1',
  402. 'next' => 'Page 1',
  403. 'prev' => 'Page 1.1',
  404. 'chapter' => 'Home',
  405. 'section' => 'Page 1',
  406. 'subsection' => 'Page 2.2'
  407. );
  408. $expected = array();
  409. $actual = array();
  410. foreach ($search as $type => $active) {
  411. $expected[$type] = false;
  412. $active = $this->_helper->findOneByLabel($active);
  413. $found = $this->_helper->findRelation($active, 'rel', $type);
  414. if (null === $found) {
  415. $actual[$type] = false;
  416. } elseif (is_array($found)) {
  417. $actual[$type] = 'array(' . count($found) . ')';
  418. } else {
  419. $actual[$type] = $found->getLabel();
  420. }
  421. }
  422. $this->assertEquals($expected, $actual);
  423. }
  424. public function testFindRelationMustSpecifyRelOrRev()
  425. {
  426. $active = $this->_helper->findOneByLabel('Home');
  427. try {
  428. $this->_helper->findRelation($active, 'foo', 'bar');
  429. $this->fail('An invalid value was given, but a ' .
  430. 'Zend_View_Exception was not thrown');
  431. } catch (Zend_View_Exception $e) {
  432. $this->assertContains('Invalid argument: $rel', $e->getMessage());
  433. }
  434. }
  435. public function testRenderLinkMustSpecifyRelOrRev()
  436. {
  437. $active = $this->_helper->findOneByLabel('Home');
  438. try {
  439. $this->_helper->renderLink($active, 'foo', 'bar');
  440. $this->fail('An invalid value was given, but a ' .
  441. 'Zend_View_Exception was not thrown');
  442. } catch (Zend_View_Exception $e) {
  443. $this->assertContains('Invalid relation attribute', $e->getMessage());
  444. }
  445. }
  446. public function testFindAllRelations()
  447. {
  448. $expectedRelations = array(
  449. 'alternate' => array('Forced page'),
  450. 'stylesheet' => array('Forced page'),
  451. 'start' => array('Forced page'),
  452. 'next' => array('Forced page'),
  453. 'prev' => array('Forced page'),
  454. 'contents' => array('Forced page'),
  455. 'index' => array('Forced page'),
  456. 'glossary' => array('Forced page'),
  457. 'copyright' => array('Forced page'),
  458. 'chapter' => array('Forced page'),
  459. 'section' => array('Forced page'),
  460. 'subsection' => array('Forced page'),
  461. 'appendix' => array('Forced page'),
  462. 'help' => array('Forced page'),
  463. 'bookmark' => array('Forced page'),
  464. 'canonical' => array('Forced page'),
  465. 'home' => array('Forced page')
  466. );
  467. // build expected result
  468. $expected = array(
  469. 'rel' => $expectedRelations,
  470. 'rev' => $expectedRelations
  471. );
  472. // find active page and create page to use for relations
  473. $active = $this->_helper->findOneByLabel('Page 1');
  474. $forcedRelation = new Zend_Navigation_Page_Uri(array(
  475. 'label' => 'Forced page',
  476. 'uri' => '#'
  477. ));
  478. // add relations to active page
  479. foreach ($expectedRelations as $type => $discard) {
  480. $active->addRel($type, $forcedRelation);
  481. $active->addRev($type, $forcedRelation);
  482. }
  483. // build actual result
  484. $actual = $this->_helper->findAllRelations($active);
  485. foreach ($actual as $attrib => $relations) {
  486. foreach ($relations as $type => $pages) {
  487. foreach ($pages as $key => $page) {
  488. $actual[$attrib][$type][$key] = $page->getLabel();
  489. }
  490. }
  491. }
  492. $this->assertEquals($expected, $actual);
  493. }
  494. private function _getFlags()
  495. {
  496. return array(
  497. Zend_View_Helper_Navigation_Links::RENDER_ALTERNATE => 'alternate',
  498. Zend_View_Helper_Navigation_Links::RENDER_STYLESHEET => 'stylesheet',
  499. Zend_View_Helper_Navigation_Links::RENDER_START => 'start',
  500. Zend_View_Helper_Navigation_Links::RENDER_NEXT => 'next',
  501. Zend_View_Helper_Navigation_Links::RENDER_PREV => 'prev',
  502. Zend_View_Helper_Navigation_Links::RENDER_CONTENTS => 'contents',
  503. Zend_View_Helper_Navigation_Links::RENDER_INDEX => 'index',
  504. Zend_View_Helper_Navigation_Links::RENDER_GLOSSARY => 'glossary',
  505. Zend_View_Helper_Navigation_Links::RENDER_CHAPTER => 'chapter',
  506. Zend_View_Helper_Navigation_Links::RENDER_SECTION => 'section',
  507. Zend_View_Helper_Navigation_Links::RENDER_SUBSECTION => 'subsection',
  508. Zend_View_Helper_Navigation_Links::RENDER_APPENDIX => 'appendix',
  509. Zend_View_Helper_Navigation_Links::RENDER_HELP => 'help',
  510. Zend_View_Helper_Navigation_Links::RENDER_BOOKMARK => 'bookmark',
  511. Zend_View_Helper_Navigation_Links::RENDER_CUSTOM => 'canonical'
  512. );
  513. }
  514. public function testSingleRenderFlags()
  515. {
  516. $active = $this->_helper->findOneByLabel('Home');
  517. $active->active = true;
  518. $expected = array();
  519. $actual = array();
  520. // build expected and actual result
  521. foreach ($this->_getFlags() as $newFlag => $type) {
  522. // add forced relation
  523. $active->addRel($type, 'http://www.example.com/');
  524. $active->addRev($type, 'http://www.example.com/');
  525. $this->_helper->setRenderFlag($newFlag);
  526. $expectedOutput = '<link '
  527. . 'rel="' . $type . '" '
  528. . 'href="http://www.example.com/">' . PHP_EOL
  529. . '<link '
  530. . 'rev="' . $type . '" '
  531. . 'href="http://www.example.com/">';
  532. $actualOutput = $this->_helper->render();
  533. $expected[$type] = $expectedOutput;
  534. $actual[$type] = $actualOutput;
  535. // remove forced relation
  536. $active->removeRel($type);
  537. $active->removeRev($type);
  538. }
  539. $this->assertEquals($expected, $actual);
  540. }
  541. public function testRenderFlagBitwiseOr()
  542. {
  543. $newFlag = Zend_View_Helper_Navigation_Links::RENDER_NEXT |
  544. Zend_View_Helper_Navigation_Links::RENDER_PREV;
  545. $this->_helper->setRenderFlag($newFlag);
  546. $active = $this->_helper->findOneByLabel('Page 1.1');
  547. $active->active = true;
  548. // test data
  549. $expected = '<link rel="next" href="page2" title="Page 2">' . PHP_EOL
  550. . '<link rel="prev" href="page1" title="Page 1">';
  551. $actual = $this->_helper->render();
  552. $this->assertEquals($expected, $actual);
  553. }
  554. public function testIndenting()
  555. {
  556. $active = $this->_helper->findOneByLabel('Page 1.1');
  557. $newFlag = Zend_View_Helper_Navigation_Links::RENDER_NEXT |
  558. Zend_View_Helper_Navigation_Links::RENDER_PREV;
  559. $this->_helper->setRenderFlag($newFlag);
  560. $this->_helper->setIndent(' ');
  561. $active->active = true;
  562. // build expected and actual result
  563. $expected = ' <link rel="next" href="page2" title="Page 2">' . PHP_EOL
  564. . ' <link rel="prev" href="page1" title="Page 1">';
  565. $actual = $this->_helper->render();
  566. $this->assertEquals($expected, $actual);
  567. }
  568. public function testSetMaxDepth()
  569. {
  570. $this->_helper->setMaxDepth(1);
  571. $this->_helper->findOneByLabel('Page 2.3.3')->setActive(); // level 2
  572. $flag = Zend_View_Helper_Navigation_Links::RENDER_NEXT;
  573. $expected = '<link rel="next" href="page2/page2_3/page2_3_1" title="Page 2.3.1">';
  574. $actual = $this->_helper->setRenderFlag($flag)->render();
  575. $this->assertEquals($expected, $actual);
  576. }
  577. public function testSetMinDepth()
  578. {
  579. $this->_helper->setMinDepth(2);
  580. $this->_helper->findOneByLabel('Page 2.3')->setActive(); // level 1
  581. $flag = Zend_View_Helper_Navigation_Links::RENDER_NEXT;
  582. $expected = '';
  583. $actual = $this->_helper->setRenderFlag($flag)->render();
  584. $this->assertEquals($expected, $actual);
  585. }
  586. }