LinksTest.php 25 KB

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