Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch
Browse files Browse the repository at this point in the history
  • Loading branch information
fdeleon committed Oct 31, 2013
165 parents d43b026 + 2e7e46b + f51e1ec + e6b286e + d5c10b6 + 0eabc04 + fed2583 + af2d845 + e8e4ce2 + f4be937 + 9323faa + 65deb5a + d5a4f17 + 94b36e8 + 62824a2 + 6378cbe + a10281c + cd0ff39 + 02e8122 + a667dd4 + 02ccc35 + 7d61487 + ab2f663 + a27ca10 + 75af0e5 + 24f498b + d2dd157 + 6c759d8 + 51b0320 + aabe1c0 + e76b67c + 5d85a78 + d285b08 + c5df6b0 + ff58ff4 + 5675884 + a55ead5 + 47eb5a8 + a36e34a + 3e520ad + 7b0d374 + 461c28b + 3890e69 + 316384e + 1431343 + debad5a + 1680741 + 4497a00 + bb6633a + 6b7ed03 + 35fcae3 + 0737e9d + c31bf4c + 918649e + ecbe771 + b4124fc + f4e1da0 + a8c70a8 + 50d3c5d + 79180fa + f6f9386 + 8ed6590 + d79a4a4 + 3958052 + eae6146 + 1cc7a46 + 1d9542f + a22d6e2 + 3496b67 + 9398e77 + 687d980 + 900dc7d + 21f6363 + 0eeb6ff + 8c442a3 + adf1f8e + c2ceb18 + 9b17a1c + d5dab4a + 346a62a + 9808633 + bdeec54 + 1a2506a + f5f3d02 + b623064 + 4338bf4 + bdababf + 4054000 + 4449c16 + d3d8b33 + 8427cf8 + 8d162ec + a988e9a + 3e9d597 + ee93c08 + 9d3ce53 + f04a59c + 0c3f2de + a654383 + 502d937 + 93350ca + 23a0ccc + 15dc071 + 6ca79e9 + 7645850 + 7b0843e + b9f38cc + 53d4205 + 0ba91ba + 7ad75c4 + 35376fd + e6713be + b15c871 + 4121ed2 + 905626d + 529973a + e28e80a + b64275a + 2f43075 + 05dea5f + b0f56ea + a0ae2ac + 8b01bd8 + fc7acfc + 87b1ffc + c00475b + 6d05c34 + 2f2787b + 229c668 + c164e00 + e5c1ff6 + 5023ed3 + 3c689b8 + 789b92c + ae927c2 + 7741eac + ab3bdcd + 6c02989 + 0d17da2 + 1035d13 + 361c1cf + b31816b + 0102405 + 84330e4 + 50b28a7 + 196892e + 55ecf0a + cdf2159 + 97a5f0f + 2951d73 + bbfc15c + 7aff06a + 2ec87c8 + 827fd02 + 5559cd9 + 9fd7105 + 090f966 + 295dff4 + cfb3de6 + dd77695 + 5e5614b + 82cdcc8 + 4583c52 + 27420a4 + 66a84a1 commit e75fb63
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 105 deletions.
8 changes: 4 additions & 4 deletions src/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function notifyOrderUpdated()
* calling {@link Page\AbstractPage::setParent()}.
*
* @param Page\AbstractPage|array|Traversable $page page to add
* @return AbstractContainer fluent interface, returns self
* @return self fluent interface, returns self
* @throws Exception\InvalidArgumentException if page is invalid
*/
public function addPage($page)
Expand Down Expand Up @@ -136,7 +136,7 @@ public function addPage($page)
* Adds several pages at once
*
* @param array|Traversable|AbstractContainer $pages pages to add
* @return AbstractContainer fluent interface, returns self
* @return self fluent interface, returns self
* @throws Exception\InvalidArgumentException if $pages is not array,
* Traversable or AbstractContainer
*/
Expand Down Expand Up @@ -172,7 +172,7 @@ public function addPages($pages)
* Sets pages this container should have, removing existing pages
*
* @param array $pages pages to set
* @return AbstractContainer fluent interface, returns self
* @return self fluent interface, returns self
*/
public function setPages(array $pages)
{
Expand Down Expand Up @@ -223,7 +223,7 @@ public function removePage($page)
/**
* Removes all pages in container
*
* @return AbstractContainer fluent interface, returns self
* @return self fluent interface, returns self
*/
public function removePages()
{
Expand Down
59 changes: 59 additions & 0 deletions src/Page/AbstractPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ abstract class AbstractPage extends AbstractContainer
*/
protected $permission;

/**
* Text domain for Translator
*
* @var string
*/
protected $textDomain;

/**
* Whether this page should be considered active
*
Expand Down Expand Up @@ -143,6 +150,13 @@ abstract class AbstractPage extends AbstractContainer
*/
protected $properties = array();

/**
* Static factories list for factory pages
*
* @var array
*/
protected static $factories = array();

// Initialization:

/**
Expand Down Expand Up @@ -220,6 +234,14 @@ public static function factory($options)
}
}

if (static::$factories) {
foreach (static::$factories as $factoryCallBack) {
if (($page = call_user_func($factoryCallBack, $options))) {
return $page;
}
}
}

$hasUri = isset($options['uri']);
$hasMvc = isset($options['action']) || isset($options['controller'])
|| isset($options['route']);
Expand All @@ -235,6 +257,16 @@ public static function factory($options)
}
}

/**
* Add static factory for self::factory function
*
* @param type $callback Any callable variable
*/
public static function addFactory($callback)
{
static::$factories[] = $callback;
}

/**
* Page constructor
*
Expand Down Expand Up @@ -732,6 +764,33 @@ public function getPermission()
return $this->permission;
}

/**
* Sets text domain for translation
*
* @param string|null $textDomain [optional] text domain to associate
* with this page. Default is null, which
* sets no text domain.
*
* @return AbstractPage fluent interface, returns self
*/
public function setTextDomain($textDomain = null)
{
if (null !== $textDomain) {
$this->textDomain = $textDomain;
}
return $this;
}

/**
* Returns text domain for translation
*
* @return mixed|null text domain or null
*/
public function getTextDomain()
{
return $this->textDomain;
}

/**
* Sets whether page should be considered active or not
*
Expand Down
42 changes: 32 additions & 10 deletions src/Page/Mvc.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ class Mvc extends AbstractPage
*
* @var RouteStackInterface
*/
protected static $defaultRouter= null;
protected static $defaultRouter = null;

/**
* Default route name
*
* @var string
*/
protected static $defaultRoute = null;

// Accessors:

Expand Down Expand Up @@ -228,8 +235,8 @@ public function getHref()
}

switch (true) {
case ($this->getRoute() !== null):
$name = $this->getRoute();
case ($this->getRoute() !== null || static::getDefaultRoute() !== null):
$name = ($this->getRoute() !== null) ? $this->getRoute() : static::getDefaultRoute();
break;
case ($this->getRouteMatch() !== null):
$name = $this->getRouteMatch()->getMatchedRouteName();
Expand Down Expand Up @@ -359,13 +366,7 @@ public function getQuery()
*/
public function setParams(array $params = null)
{
if (null === $params) {
$this->params = array();
} else {
// TODO: do this more intelligently?
$this->params = $params;
}

$this->params = empty($params) ? array() : $params;
$this->hrefCache = null;
return $this;
}
Expand Down Expand Up @@ -508,6 +509,27 @@ public static function getDefaultRouter()
return static::$defaultRouter;
}

/**
* Set default route name
*
* @param string $route
* @return void
*/
public static function setDefaultRoute($route)
{
static::$defaultRoute = $route;
}

/**
* Get default route name
*
* @return string
*/
public static function getDefaultRoute()
{
return static::$defaultRoute;
}

// Public methods:

/**
Expand Down
8 changes: 2 additions & 6 deletions test/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Navigation
*/

namespace ZendTest\Navigation;
Expand All @@ -17,9 +16,6 @@
/**
* Tests the class Zend_Navigation_Container
*
* @category Zend
* @package Zend_Navigation
* @subpackage UnitTests
* @group Zend_Navigation
*/
class ContainerTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -799,7 +795,7 @@ public function testFindOneByShouldReturnNullIfNotFound()
{
$nav = $this->_getFindByNavigation();

$found = $nav->findOneBy('id', 'non-existant');
$found = $nav->findOneBy('id', 'non-existent');
$this->assertNull($found);
}

Expand All @@ -823,7 +819,7 @@ public function testFindAllByShouldReturnAllMatchingPages()
public function testFindAllByShouldReturnEmptyArrayifNotFound()
{
$nav = $this->_getFindByNavigation();
$found = $nav->findAllBy('id', 'non-existant');
$found = $nav->findAllBy('id', 'non-existent');

$expected = array('type' => 'array', 'count' => 0);
$actual = array('type' => gettype($found), 'count' => count($found));
Expand Down
4 changes: 0 additions & 4 deletions test/NavigationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Navigation
*/

namespace ZendTest\Navigation;
Expand All @@ -17,9 +16,6 @@
*/

/**
* @category Zend
* @package Zend_Navigation
* @subpackage UnitTests
* @group Zend_Navigation
*/
class NavigationTest extends \PHPUnit_Framework_TestCase
Expand Down
19 changes: 15 additions & 4 deletions test/Page/MvcTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Navigation
*/

namespace ZendTest\Navigation\Page;
Expand All @@ -25,9 +24,6 @@
/**
* Tests the class Zend_Navigation_Page_Mvc
*
* @category Zend
* @package Zend_Navigation
* @subpackage UnitTests
* @group Zend_Navigation
*/
class MvcTest extends TestCase
Expand All @@ -53,6 +49,21 @@ protected function tearDown()
{
}

public function testHrefGeneratedByRouterWithDefaultRoute()
{
$page = new Page\Mvc(array(
'label' => 'foo',
'action' => 'index',
'controller' => 'index'
));
Page\Mvc::setDefaultRoute('default');
$page->setRouter($this->router);
$page->setAction('view');
$page->setController('news');

$this->assertEquals('/news/view', $page->getHref());
}

public function testHrefGeneratedByRouterRequiresNoRoute()
{
$page = new Page\Mvc(array(
Expand Down
31 changes: 23 additions & 8 deletions test/Page/PageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Navigation
*/

namespace ZendTest\Navigation;
Expand All @@ -16,15 +15,31 @@
/**
* Tests Zend_Navigation_Page::factory()
*
/**
* @category Zend
* @package Zend_Navigation
* @subpackage UnitTests
* @group Zend_Navigation
*/
class PageFactoryTest extends \PHPUnit_Framework_TestCase
{

public function testDetectFactoryPage()
{
AbstractPage::addFactory(function ($page) {
if (isset($page['factory_uri'])) {
return new \Zend\Navigation\Page\Uri($page);
} elseif (isset($page['factory_mvc'])) {
return new \Zend\Navigation\Page\Mvc($page);
}
});

$this->assertInstanceOf('Zend\\Navigation\\Page\\Uri', AbstractPage::factory(array(
'label' => 'URI Page',
'factory_uri' => '#'
)));

$this->assertInstanceOf('Zend\\Navigation\\Page\\Mvc', AbstractPage::factory(array(
'label' => 'URI Page',
'factory_mvc' => '#'
)));
}

public function testDetectMvcPage()
{
Expand Down Expand Up @@ -118,8 +133,8 @@ public function testShouldFailForInvalidType()
public function testShouldFailForNonExistantType()
{
$pageConfig = array(
'type' => 'My_NonExistant_Page',
'label' => 'My non-existant Page'
'type' => 'My_NonExistent_Page',
'label' => 'My non-existent Page'
);

try {
Expand All @@ -128,7 +143,7 @@ public function testShouldFailForNonExistantType()
return;
}

$msg = 'An exception has not been thrown for non-existant class';
$msg = 'An exception has not been thrown for non-existent class';
$this->fail($msg);
}

Expand Down
Loading

0 comments on commit e75fb63

Please sign in to comment.