Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
Enhancement: Assert ModuleController::viewAction() is not dispatched to
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Mar 6, 2015
1 parent 063fb6d commit 6d69a74
Showing 1 changed file with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,92 @@ public function testViewActionCanBeAccessed()
$this->assertActionName('view');
}

/**
* @dataProvider providerTakenUrls
*
* @param string $url
*/
public function testViewActionIsNotDispatchedToIfUrlIsTaken($url)
{
$moduleMapper = $this->getMockBuilder(Mapper\Module::class)
->disableOriginalConstructor()
->getMock()
;

$moduleMapper
->expects($this->any())
->method('findByName')
->willReturn(new Entity\Module())
;

$repositoryRetriever = $this->getMockBuilder(RepositoryRetriever::class)
->disableOriginalConstructor()
->getMock()
;

$repositoryRetriever
->expects($this->any())
->method('getUserRepositoryMetadata')
->willReturn(new stdClass())
;

$this->getApplicationServiceLocator()
->setAllowOverride(true)
->setService(
Mapper\Module::class,
$moduleMapper
)
->setService(
RepositoryRetriever::class,
$repositoryRetriever
)
;

$this->dispatch($url);

$routeMatch = $this->getApplication()->getMvcEvent()->getRouteMatch();

$controller = $routeMatch->getParam('controller');
$action = $routeMatch->getParam('action');

$unexpectedController = Controller\ModuleController::class;
$unexpectedAction = 'view';

$isController = strtolower($controller) === strtolower($unexpectedController);
$isAction = strtolower($action) === $unexpectedAction;

$this->assertFalse(
$isController && $isAction,
sprintf(
'Failed to assert that the url "%s" is not dispatched to "%s::%sAction()"',
$url,
$unexpectedController,
$unexpectedAction
)
);
}

/**
* @return array
*/
public function providerTakenUrls()
{
return [
[
'/module/add',
],
[
'/module/list',
],
[
'/module/remove',
],
[
'/user/anyone',
],
];
}

/**
* @link http://stackoverflow.com/a/15907250
*
Expand Down

0 comments on commit 6d69a74

Please sign in to comment.