Skip to content

Commit

Permalink
[#13648] - Refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed May 15, 2019
1 parent 99d9838 commit c5ca361
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 175 deletions.
29 changes: 13 additions & 16 deletions tests/unit/Firewall/Adapter/Acl/BeforeExecuteRouteCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ public function _after()
/**
* Tests Phalcon\Firewall\Adapter\Acl :: beforeExecuteRoute()
*
* @dataProvider getBeforeExecute
*
* @author Wojciech Ślawski <jurigag@gmail.com>
* @since 2017-01-19
*/
public function firewallAdapterAclBeforeExecuteRoute(UnitTester $I, Example $example)
public function firewallAdapterAclBeforeExecuteRoute(UnitTester $I)
{
$I->wantToTest('Firewall\Adapter\Acl - beforeExecuteRoute()');

Expand All @@ -112,19 +110,7 @@ public function firewallAdapterAclBeforeExecuteRoute(UnitTester $I, Example $exa
$dispatcher = $this->dispatcher;
$this->container->set('dispatcher', $dispatcher);

$returnedValue = $this->getReturnedValueFor(
$this->container,
$dispatcher,
$example[0],
$example[1],
$example[2]
);
$I->assertEquals($returnedValue, $example[3]);
}

private function getBeforeExecute(): array
{
return [
$examples = [
["one", "firstRole", "ROLE1", "allowed"],
["one", "firstRole", "ROLE2", null],
["one", "firstRole", "ROLE3", "allowed"],
Expand All @@ -142,5 +128,16 @@ private function getBeforeExecute(): array
["one", "secondRole", new RoleObject("ROLE3"), "allowed"],
["one", "secondRole", new RoleObject("ROLE4"), "allowed"],
];

foreach ($examples as $example) {
$returnedValue = $this->getReturnedValueFor(
$this->container,
$dispatcher,
$example[0],
$example[1],
$example[2]
);
$I->assertEquals($returnedValue, $example[3]);
}
}
}
33 changes: 15 additions & 18 deletions tests/unit/Firewall/Adapter/Acl/SetCacheCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ public function _after()
/**
* Tests Phalcon\Firewall\Adapter\Acl :: setCache()
*
* @dataProvider getCache
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2019-05-12
*/
public function firewallAdapterAclSetCache(UnitTester $I, Example $example)
public function firewallAdapterAclSetCache(UnitTester $I)
{
$I->wantToTest('Firewall\Adapter\Acl - setCache()');

Expand Down Expand Up @@ -154,21 +152,7 @@ function (BindingRole $user) {
$dispatcher = $this->dispatcher;
$this->container->set('dispatcher', $dispatcher);

$returnedValue = $this->getReturnedValueFor(
$this->container,
$dispatcher,
$example[0],
$example[1],
$example[2],
$example[3]
);
$I->assertEquals($returnedValue, $example[4]);
$I->assertEquals($cache->get("_PHF_")[$example[5]], $example[6]);
}

private function getCache(): array
{
return [
$examples = [
["four", "first", new BindingRole("ROLE1", 1), ['album' => 1], "allowed", 'ROLE1!Four!first', true],
["four", "first", new BindingRole("ROLE1", 2), ['album' => 1], "allowed", 'ROLE1!Four!first', true],
["four", "first", new BindingRole("ROLE2", 1), ['album' => 1], "allowed", 'ROLE2!Four!first!1!1', true],
Expand All @@ -183,5 +167,18 @@ private function getCache(): array
["three", "deny", new BindingRole("ROLE5", 2), ['album' => 1], null, 'ROLE5!*!*!2', false],
["three", "deny", new BindingRole("ROLE5", 3), ['album' => 1], "allowed", 'ROLE5!*!*!3', true],
];

foreach ($examples as $example) {
$returnedValue = $this->getReturnedValueFor(
$this->container,
$dispatcher,
$example[0],
$example[1],
$example[2],
$example[3]
);
$I->assertEquals($returnedValue, $example[4]);
$I->assertEquals($cache->get("_PHF_")[$example[5]], $example[6]);
}
}
}
33 changes: 15 additions & 18 deletions tests/unit/Firewall/Adapter/Acl/UseMultiModuleConfigurationCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ public function _after()
/**
* Tests Phalcon\Firewall\Adapter\Acl :: useMultiModuleConfiguration()
*
* @dataProvider getMultiModule
*
* @author Wojciech Ślawski <jurigag@gmail.com>
* @since 2017-01-19
*/
public function firewallAdapterAclUseMultiModuleConfiguration(UnitTester $I, Example $example)
public function firewallAdapterAclUseMultiModuleConfiguration(UnitTester $I)
{
$I->wantToTest('Firewall\Adapter\Acl - useMultiModuleConfiguration()');

Expand All @@ -113,21 +111,7 @@ public function firewallAdapterAclUseMultiModuleConfiguration(UnitTester $I, Exa
$dispatcher = $this->dispatcher;
$this->container->set('dispatcher', $dispatcher);

$returnedValue = $this->getReturnedValueFor(
$this->container,
$dispatcher,
$example[0],
$example[1],
$example[2],
$example[3],
$example[4]
);
$I->assertEquals($returnedValue, $example[5]);
}

private function getMultiModule(): array
{
return [
$examples = [
["one", "firstRole", "ROLE1", null, "Module1", "allowed"],
["one", "firstRole", "ROLE2", null, "Module1", null],
["one", "secondRole", "ROLE1", null, "Module1", null],
Expand All @@ -137,5 +121,18 @@ private function getMultiModule(): array
["one", "secondRole", "ROLE1", null, "Module2", "allowed"],
["one", "secondRole", "ROLE2", null, "Module2", null],
];

foreach ($examples as $example) {
$returnedValue = $this->getReturnedValueFor(
$this->container,
$dispatcher,
$example[0],
$example[1],
$example[2],
$example[3],
$example[4]
);
$I->assertEquals($returnedValue, $example[5]);
}
}
}
49 changes: 22 additions & 27 deletions tests/unit/Firewall/Adapter/Annotations/SetCacheCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ public function _after()
/**
* Tests Phalcon\Firewall\Adapter\Annotations :: setCache()
*
* @dataProvider getCache
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2019-05-12
*/
public function firewallAdapterAnnotationsSetCache(UnitTester $I, Example $example)
public function firewallAdapterAnnotationsSetCache(UnitTester $I)
{
$I->wantToTest('Firewall\Adapter\Annotations - setCache()');

Expand All @@ -104,40 +102,37 @@ function () {
}
);
$firewall = new Annotations(new Memory());
$firewall->setEventsManager($eventsManager)
->setRoleCallback(
function ($di) {
return $di->get('myrole');
}
)
->setAlwaysResolvingRole(true)
$firewall
->setEventsManager($eventsManager)
->setRoleCallback(
function ($di) {
return $di->get('myrole');
}
)
->setAlwaysResolvingRole(true)
;
$firewall->setCache($cache);
$eventsManager->attach('dispatch:beforeExecuteRoute', $firewall);
$this->dispatcher->setEventsManager($eventsManager);
$dispatcher = $this->dispatcher;

$di->set('dispatcher', $dispatcher);
$returnedValue = $this->getReturnedValueFor(
$di,
$dispatcher,
$example[0],
$example[1],
$example[2]
);
$I->assertEquals($returnedValue, $example[3]);
$I->assertEquals($cache->get('_PHF_')[$example[4]], $example[5]);
}

/**
* @return array
*/
private function getCache(): array
{
return [
$examples = [
["one", "firstRole", "ROLE1", "allowed", 'ROLE1!one!firstRole', true],
["one", "allowEveryone", "ROLE1", "allowed", '*!one!allowEveryone', true],
["one", "firstRole", "ROLE2", null, 'ROLE2!one!firstRole', false],
];

foreach ($examples as $example) {
$returnedValue = $this->getReturnedValueFor(
$di,
$dispatcher,
$example[0],
$example[1],
$example[2]
);
$I->assertEquals($returnedValue, $example[3]);
$I->assertEquals($cache->get('_PHF_')[$example[4]], $example[5]);
}
}
}
30 changes: 12 additions & 18 deletions tests/unit/Firewall/Adapter/Micro/Acl/AfterBindingCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@ public function _after()
/**
* Tests Phalcon\Firewall\Adapter\Micro\Acl :: afterBinding()
*
* @dataProvider getAfterBinding
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2019-05-12
*/
public function firewallAdapterMicroAclAfterBinding(UnitTester $I, Example $example)
public function firewallAdapterMicroAclAfterBinding(UnitTester $I)
{
$I->wantToTest('Firewall\Adapter\Micro\Acl - afterBinding()');

Expand Down Expand Up @@ -164,21 +162,7 @@ function (BindingRole $user, Albums $album) {
$this->micro->setModelBinder($binder);
$micro = $this->micro;

$returnedValue = $this->getMicroValueFor(
$this->container,
$micro,
$example[0],
$example[1]
);
$I->assertEquals($returnedValue, $example[2]);
}

/**
* @return array
*/
private function getAfterBinding(): array
{
return [
$examples = [
['/album/1', new BindingRole("ROLE1", 1), "allowed"],
['/album/1', new BindingRole("ROLE1", 2), false],
['/album/1', new BindingRole("ROLE2", 1), false],
Expand Down Expand Up @@ -206,5 +190,15 @@ private function getAfterBinding(): array
['/album/update/1', new BindingRole("ROLE7", 1), "allowed"],
['/album/update/1', new BindingRole("ROLE7", 2), "allowed"],
];

foreach ($examples as $example) {
$returnedValue = $this->getMicroValueFor(
$this->container,
$micro,
$example[0],
$example[1]
);
$I->assertEquals($returnedValue, $example[2]);
}
}
}
30 changes: 12 additions & 18 deletions tests/unit/Firewall/Adapter/Micro/Acl/BeforeExecuteRouteCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,10 @@ public function _after()
/**
* Tests Phalcon\Firewall\Adapter\Micro\Acl :: beforeExecuteRoute()
*
* @dataProvider getBeforeExecute
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2019-05-12
*/
public function firewallAdapterMicroAclBeforeExecuteRoute(UnitTester $I, Example $example)
public function firewallAdapterMicroAclBeforeExecuteRoute(UnitTester $I)
{
$I->wantToTest('Firewall\Adapter\Micro\Acl - beforeExecuteRoute()');

Expand All @@ -132,21 +130,7 @@ public function firewallAdapterMicroAclBeforeExecuteRoute(UnitTester $I, Example
$this->micro->setEventsManager($eventsManager);
$micro = $this->micro;

$returnedValue = $this->getMicroValueFor(
$this->container,
$micro,
$example[0],
$example[1]
);
$I->assertEquals($returnedValue, $example[2]);
}

/**
* @return array
*/
private function getBeforeExecute(): array
{
return [
$examples = [
['/test', 'ROLE1', "allowed"],
['/test', 'ROLE2', null],
['/test', 'ROLE3', "allowed"],
Expand All @@ -156,5 +140,15 @@ private function getBeforeExecute(): array
['/test', 'ROLE3', "allowed"],
['/test', 'ROLE4', "allowed"],
];

foreach ($examples as $example) {
$returnedValue = $this->getMicroValueFor(
$this->container,
$micro,
$example[0],
$example[1]
);
$I->assertEquals($returnedValue, $example[2]);
}
}
}
30 changes: 12 additions & 18 deletions tests/unit/Firewall/Adapter/Micro/Acl/SetBoundModelsKeyMapCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@ public function _after()
/**
* Tests Phalcon\Firewall\Adapter\Micro\Acl :: setBoundModelsKeyMap()
*
* @dataProvider getAfterBindingKeyMap
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2019-05-12
*/
public function firewallAdapterMicroAclSetBoundModelsKeyMap(UnitTester $I, Example $example)
public function firewallAdapterMicroAclSetBoundModelsKeyMap(UnitTester $I)
{
$I->wantToTest('Firewall\Adapter\Micro\Acl - setBoundModelsKeyMap()');

Expand Down Expand Up @@ -148,27 +146,23 @@ function (BindingRole $user, Albums $model) {
$this->micro->setModelBinder($binder);
$micro = $this->micro;

$returnedValue = $this->getMicroValueFor(
$this->container,
$micro,
$example[0],
$example[1]
);
$I->assertEquals($returnedValue, $example[2]);
}

/**
* @return array
*/
private function getAfterBindingKeyMap(): array
{
return [
$examples = [
['/album/1', new BindingRole("ROLE1", 1), "allowed"],
['/album/1', new BindingRole("ROLE1", 2), false],
['/album/1', new BindingRole("ROLE2", 1), false],
['/album/update/1', new BindingRole("ROLE2", 1), "allowed"],
['/album/update/1', new BindingRole("ROLE2", 2), false],
['/album/update/1', new BindingRole("ROLE1", 1), false],
];

foreach ($examples as $example) {
$returnedValue = $this->getMicroValueFor(
$this->container,
$micro,
$example[0],
$example[1]
);
$I->assertEquals($returnedValue, $example[2]);
}
}
}
Loading

0 comments on commit c5ca361

Please sign in to comment.