| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_View
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- require_once dirname(__FILE__) . '/TestAbstract.php';
- require_once 'Zend/View/Helper/Navigation/Breadcrumbs.php';
- /**
- * Tests Zend_View_Helper_Navigation_Breadcrumbs
- *
- * @category Zend_Tests
- * @package Zend_View
- * @subpackage Helper
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_View
- * @group Zend_View_Helper
- */
- class Zend_View_Helper_Navigation_BreadcrumbsTest
- extends Zend_View_Helper_Navigation_TestAbstract
- {
- /**
- * Class name for view helper to test
- *
- * @var string
- */
- protected $_helperName = 'Zend_View_Helper_Navigation_Breadcrumbs';
- /**
- * View helper
- *
- * @var Zend_View_Helper_Navigation_Breadcrumbs
- */
- protected $_helper;
- public function testHelperEntryPointWithoutAnyParams()
- {
- $returned = $this->_helper->breadcrumbs();
- $this->assertEquals($this->_helper, $returned);
- $this->assertEquals($this->_nav1, $returned->getContainer());
- }
- public function testHelperEntryPointWithContainerParam()
- {
- $returned = $this->_helper->breadcrumbs($this->_nav2);
- $this->assertEquals($this->_helper, $returned);
- $this->assertEquals($this->_nav2, $returned->getContainer());
- }
- public function testNullOutContainer()
- {
- $old = $this->_helper->getContainer();
- $this->_helper->setContainer();
- $new = $this->_helper->getContainer();
- $this->assertNotEquals($old, $new);
- }
- public function testAutoloadContainerFromRegistry()
- {
- $oldReg = null;
- if (Zend_Registry::isRegistered(self::REGISTRY_KEY)) {
- $oldReg = Zend_Registry::get(self::REGISTRY_KEY);
- }
- Zend_Registry::set(self::REGISTRY_KEY, $this->_nav1);
- $this->_helper->setContainer();
- $expected = $this->_getExpected('bc/default.html');
- $actual = $this->_helper->render();
- Zend_Registry::set(self::REGISTRY_KEY, $oldReg);
- $this->assertEquals($expected, $actual);
- }
- public function testSetSeparator()
- {
- $this->_helper->setSeparator('foo');
- $expected = $this->_getExpected('bc/separator.html');
- $this->assertEquals($expected, $this->_helper->render());
- }
- public function testSetMaxDepth()
- {
- $this->_helper->setMaxDepth(1);
- $expected = $this->_getExpected('bc/maxdepth.html');
- $this->assertEquals($expected, $this->_helper->render());
- }
- public function testSetMinDepth()
- {
- $this->_helper->setMinDepth(1);
- $expected = '';
- $this->assertEquals($expected, $this->_helper->render($this->_nav2));
- }
- public function testLinkLastElement()
- {
- $this->_helper->setLinkLast(true);
- $expected = $this->_getExpected('bc/linklast.html');
- $this->assertEquals($expected, $this->_helper->render());
- }
- public function testSetIndent()
- {
- $this->_helper->setIndent(8);
- $expected = ' <a';
- $actual = substr($this->_helper->render(), 0, strlen($expected));
- $this->assertEquals($expected, $actual);
- }
- public function testRenderSuppliedContainerWithoutInterfering()
- {
- $this->_helper->setMinDepth(0);
- $rendered1 = $this->_getExpected('bc/default.html');
- $rendered2 = 'Site 2';
- $expected = array(
- 'registered' => $rendered1,
- 'supplied' => $rendered2,
- 'registered_again' => $rendered1
- );
- $actual = array(
- 'registered' => $this->_helper->render(),
- 'supplied' => $this->_helper->render($this->_nav2),
- 'registered_again' => $this->_helper->render()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testUseAclResourceFromPages()
- {
- $acl = $this->_getAcl();
- $this->_helper->setAcl($acl['acl']);
- $this->_helper->setRole($acl['role']);
- $expected = $this->_getExpected('bc/acl.html');
- $this->assertEquals($expected, $this->_helper->render());
- }
- public function testTranslationUsingZendTranslate()
- {
- $this->_helper->setTranslator($this->_getTranslator());
- $expected = $this->_getExpected('bc/translated.html');
- $this->assertEquals($expected, $this->_helper->render());
- }
- public function testTranslationUsingZendTranslateAdapter()
- {
- $translator = $this->_getTranslator();
- $this->_helper->setTranslator($translator->getAdapter());
- $expected = $this->_getExpected('bc/translated.html');
- $this->assertEquals($expected, $this->_helper->render());
- }
- public function testTranslationFromTranslatorInRegistry()
- {
- $oldReg = Zend_Registry::isRegistered('Zend_Translate')
- ? Zend_Registry::get('Zend_Translate')
- : null;
- $translator = $this->_getTranslator();
- Zend_Registry::set('Zend_Translate', $translator);
- $expected = $this->_getExpected('bc/translated.html');
- $actual = $this->_helper->render();
- Zend_Registry::set('Zend_Translate', $oldReg);
- $this->assertEquals($expected, $actual);
- }
- public function testDisablingTranslation()
- {
- $translator = $this->_getTranslator();
- $this->_helper->setTranslator($translator);
- $this->_helper->setUseTranslator(false);
- $expected = $this->_getExpected('bc/default.html');
- $this->assertEquals($expected, $this->_helper->render());
- }
- public function testRenderingPartial()
- {
- $this->_helper->setPartial('bc.phtml');
- $expected = $this->_getExpected('bc/partial.html');
- $this->assertEquals($expected, $this->_helper->render());
- }
- public function testRenderingPartialBySpecifyingAnArrayAsPartial()
- {
- $this->_helper->setPartial(array('bc.phtml', 'default'));
- $expected = $this->_getExpected('bc/partial.html');
- $this->assertEquals($expected, $this->_helper->render());
- }
- public function testRenderingPartialShouldFailOnInvalidPartialArray()
- {
- $this->_helper->setPartial(array('bc.phtml'));
- try {
- $this->_helper->render();
- $this->fail(
- '$partial was invalid, but no Zend_View_Exception was thrown');
- } catch (Zend_View_Exception $e) {
- }
- }
- public function testLastBreadcrumbShouldBeEscaped()
- {
- $container = new Zend_Navigation(array(
- array(
- 'label' => 'Live & Learn',
- 'uri' => '#',
- 'active' => true
- )
- ));
- $expected = 'Live & Learn';
- $actual = $this->_helper->setMinDepth(0)->render($container);
- $this->assertEquals($expected, $actual);
- }
- /**
- * @group ZF-11876
- */
- public function testRenderingWithCustomHtmlAttribs()
- {
- $container = new Zend_Navigation(array(
- array(
- 'label' => 'Page 1',
- 'uri' => 'p1',
- 'customHtmlAttribs' => array(
- 'rel' => 'nofollow',
- 'style' => 'font-weight: bold;',
- ),
- 'pages' => array(
- array(
- 'label' => 'Page 2',
- 'uri' => 'p2',
- 'customHtmlAttribs' => array(
- 'rel' => 'nofollow',
- ),
- 'pages' => array(
- array(
- 'label' => 'Page 3',
- 'uri' => 'p3',
- 'active' => true,
- ),
- ),
- ),
- ),
- ),
- ));
- $expected = '<a href="p1" rel="nofollow" style="font-weight: bold;">Page 1</a>'
- . ' > '
- . '<a href="p2" rel="nofollow">Page 2</a>'
- . ' > '
- . 'Page 3';
- $actual = $this->_helper->setMinDepth(0)->render($container);
- $this->assertEquals($expected, $actual);
- }
- }
|