You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
PHTML
57 lines
1.6 KiB
PHTML
6 years ago
|
<?php
|
||
|
|
||
|
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
||
|
|
||
|
use Engelsystem\Renderer\Twig\Extensions\Authentication;
|
||
|
|
||
|
class AuthenticationTest extends ExtensionTest
|
||
|
{
|
||
|
/**
|
||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Authentication::getFunctions
|
||
|
*/
|
||
|
public function testGetFunctions()
|
||
|
{
|
||
|
$extension = new Authentication();
|
||
|
$functions = $extension->getFunctions();
|
||
|
|
||
|
$this->assertExtensionExists('is_user', [$extension, 'isAuthenticated'], $functions);
|
||
|
$this->assertExtensionExists('is_guest', [$extension, 'isGuest'], $functions);
|
||
|
$this->assertExtensionExists('has_permission_to', [$extension, 'checkAuth'], $functions);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Authentication::isAuthenticated
|
||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Authentication::isGuest
|
||
|
*/
|
||
|
public function testIsAuthenticated()
|
||
|
{
|
||
|
global $user;
|
||
|
$user = [];
|
||
|
|
||
|
$extension = new Authentication();
|
||
|
|
||
|
$this->assertFalse($extension->isAuthenticated());
|
||
|
$this->assertTrue($extension->isGuest());
|
||
|
|
||
|
$user = ['lorem' => 'ipsum'];
|
||
|
$this->assertTrue($extension->isAuthenticated());
|
||
|
$this->assertFalse($extension->isGuest());
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Authentication::checkAuth
|
||
|
*/
|
||
|
public function testCheckAuth()
|
||
|
{
|
||
|
global $privileges;
|
||
|
$privileges = [];
|
||
|
|
||
|
$extension = new Authentication();
|
||
|
|
||
|
$this->assertFalse($extension->checkAuth('foo.bar'));
|
||
|
|
||
|
$privileges = ['foo.bar'];
|
||
|
$this->assertTrue($extension->checkAuth('foo.bar'));
|
||
|
}
|
||
|
}
|