Skip to content

Commit

Permalink
tests: added test
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 12, 2019
1 parent 23d6ae3 commit 7a1e097
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/Security.DI/SecurityExtension.authorizator.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* Test: SecurityExtension
*/

declare(strict_types=1);

use Nette\Bridges\HttpDI\HttpExtension;
use Nette\Bridges\HttpDI\SessionExtension;
use Nette\Bridges\SecurityDI\SecurityExtension;
use Nette\DI;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


$compiler = new DI\Compiler;
$compiler->addExtension('foo', new HttpExtension);
$compiler->addExtension('bar', new SessionExtension);
$compiler->addExtension('security', new SecurityExtension);

$loader = new Nette\DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
security:
roles:
guest:
member: [guest]
resources:
item:
article: item
', 'neon'));

eval($compiler->addConfig($config)->compile());
$container = new Container;

$authorizator = $container->getService('security.authorizator');
Assert::type(Nette\Security\Permission::class, $authorizator);
Assert::same($authorizator, $container->getService('nette.authorizator'));

Assert::same(['guest', 'member'], $authorizator->getRoles());
Assert::same([], $authorizator->getRoleParents('guest'));
Assert::same(['guest'], $authorizator->getRoleParents('member'));

Assert::same(['item', 'article'], $authorizator->getResources());
Assert::false($authorizator->resourceInheritsFrom('item', 'article'));
Assert::true($authorizator->resourceInheritsFrom('article', 'item'));

0 comments on commit 7a1e097

Please sign in to comment.