Skip to content
Permalink
Browse files

tests: added test

  • Loading branch information...
dg committed Apr 12, 2019
1 parent 4c2149e commit c128c4d7ed5bd0ebeffc423b107350cb3f95afab
Showing with 48 additions and 0 deletions.
  1. +48 −0 tests/Security.DI/SecurityExtension.authorizator.phpt
@@ -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 c128c4d

Please sign in to comment.
You can’t perform that action at this time.