Skip to content

Commit

Permalink
Merge pull request zendframework#5669 from Xerkus/hotfix/inject-templ…
Browse files Browse the repository at this point in the history
…ate-listener

Fix bug in InjectTemplateListenerTest
  • Loading branch information
weierophinney committed Mar 3, 2014
2 parents d565ef5 + dd17019 commit 91b0a85
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion tests/ZendTest/Mvc/View/InjectTemplateListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,40 @@ public function testMapsSubNamespaceToSubDirectoryWithControllerFromRouteMatch()
$this->routeMatch->setParam('controller', 'CiderSales');
$this->routeMatch->setParam('action', 'PinkiePieRevenue');

$moduleRouteListener = new ModuleRouteListener;
$moduleRouteListener->onRoute($this->event);

$model = new ViewModel();
$this->event->setResult($model);
$this->listener->injectTemplate($this->event);

$this->assertEquals('sweet-apple-acres/reports/cider-sales/pinkie-pie-revenue', $model->getTemplate());
$this->assertEquals('aj/sweet-apple-acres/reports/cider-sales/pinkie-pie-revenue', $model->getTemplate());
}

public function testMapsSubNamespaceToSubDirectoryWithControllerFromRouteMatchHavingSubNamespace()
{
$this->routeMatch->setParam(ModuleRouteListener::MODULE_NAMESPACE, 'Aj\Controller\SweetAppleAcres\Reports');
$this->routeMatch->setParam('controller', 'Sub\CiderSales');
$this->routeMatch->setParam('action', 'PinkiePieRevenue');

$moduleRouteListener = new ModuleRouteListener;
$moduleRouteListener->onRoute($this->event);

$model = new ViewModel();
$this->event->setResult($model);
$this->listener->injectTemplate($this->event);

$this->assertEquals('aj/sweet-apple-acres/reports/cider-sales/pinkie-pie-revenue', $model->getTemplate());
}

public function testMapsSubNamespaceToSubDirectoryWithControllerFromEventTarget()
{
$this->routeMatch->setParam(ModuleRouteListener::MODULE_NAMESPACE, 'ZendTest\Mvc\Controller\TestAsset');
$this->routeMatch->setParam('action', 'test');

$moduleRouteListener = new ModuleRouteListener;
$moduleRouteListener->onRoute($this->event);

$myViewModel = new ViewModel();
$myController = new \ZendTest\Mvc\Controller\TestAsset\SampleController();

Expand All @@ -125,6 +147,32 @@ public function testMapsSubNamespaceToSubDirectoryWithControllerFromEventTarget(
$this->assertEquals('zend-test/controller/test-asset/sample/test', $myViewModel->getTemplate());
}

public function testMapsSubNamespaceToSubDirectoryWithControllerFromEventTargetShouldMatchControllerFromRouteParam()
{
$this->routeMatch->setParam(ModuleRouteListener::MODULE_NAMESPACE, 'ZendTest\Mvc\Controller');
$this->routeMatch->setParam('controller', 'TestAsset\SampleController');
$this->routeMatch->setParam('action', 'test');

$moduleRouteListener = new ModuleRouteListener;
$moduleRouteListener->onRoute($this->event);

$myViewModel = new ViewModel();
$this->event->setResult($myViewModel);
$this->listener->injectTemplate($this->event);

$template1 = $myViewModel->getTemplate();

$myViewModel = new ViewModel();
$myController = new \ZendTest\Mvc\Controller\TestAsset\SampleController();

$this->event->setTarget($myController);
$this->event->setResult($myViewModel);
$this->listener->injectTemplate($this->event);

$this->assertEquals($template1, $myViewModel->getTemplate());
}


public function testAttachesListenerAtExpectedPriority()
{
$events = new EventManager();
Expand Down

0 comments on commit 91b0a85

Please sign in to comment.