summaryrefslogtreecommitdiff
path: root/tests/Unit/Renderer
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-10-08 19:30:37 +0200
committermsquare <msquare@notrademark.de>2018-10-31 13:43:23 +0100
commitd15946df2dfb0ae2f0ca9371e5c8071df91ab45a (patch)
tree49601aafd74da5a781920543ed92bbd180fe5e89 /tests/Unit/Renderer
parent8e62c4c52c27f9432820915deeb699c3d1f58ce7 (diff)
Changed `src/` code and templates to use the new user model
Diffstat (limited to 'tests/Unit/Renderer')
-rw-r--r--tests/Unit/Renderer/Twig/Extensions/AuthenticationTest.php31
-rw-r--r--tests/Unit/Renderer/Twig/Extensions/GlobalsTest.php21
2 files changed, 41 insertions, 11 deletions
diff --git a/tests/Unit/Renderer/Twig/Extensions/AuthenticationTest.php b/tests/Unit/Renderer/Twig/Extensions/AuthenticationTest.php
index 0a72c0e7..b67d4eed 100644
--- a/tests/Unit/Renderer/Twig/Extensions/AuthenticationTest.php
+++ b/tests/Unit/Renderer/Twig/Extensions/AuthenticationTest.php
@@ -2,16 +2,23 @@
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
+use Engelsystem\Helpers\Authenticator;
+use Engelsystem\Models\User\User;
use Engelsystem\Renderer\Twig\Extensions\Authentication;
+use PHPUnit\Framework\MockObject\MockObject;
class AuthenticationTest extends ExtensionTest
{
/**
+ * @covers \Engelsystem\Renderer\Twig\Extensions\Authentication::__construct
* @covers \Engelsystem\Renderer\Twig\Extensions\Authentication::getFunctions
*/
public function testGetFunctions()
{
- $extension = new Authentication();
+ /** @var Authenticator|MockObject $auth */
+ $auth = $this->createMock(Authenticator::class);
+
+ $extension = new Authentication($auth);
$functions = $extension->getFunctions();
$this->assertExtensionExists('is_user', [$extension, 'isAuthenticated'], $functions);
@@ -25,15 +32,24 @@ class AuthenticationTest extends ExtensionTest
*/
public function testIsAuthenticated()
{
- global $user;
- $user = [];
+ /** @var Authenticator|MockObject $auth */
+ $auth = $this->createMock(Authenticator::class);
+ $user = new User();
+
+ $auth->expects($this->exactly(4))
+ ->method('user')
+ ->willReturnOnConsecutiveCalls(
+ null,
+ null,
+ $user,
+ $user
+ );
- $extension = new Authentication();
+ $extension = new Authentication($auth);
$this->assertFalse($extension->isAuthenticated());
$this->assertTrue($extension->isGuest());
- $user = ['lorem' => 'ipsum'];
$this->assertTrue($extension->isAuthenticated());
$this->assertFalse($extension->isGuest());
}
@@ -46,7 +62,10 @@ class AuthenticationTest extends ExtensionTest
global $privileges;
$privileges = [];
- $extension = new Authentication();
+ /** @var Authenticator|MockObject $auth */
+ $auth = $this->createMock(Authenticator::class);
+
+ $extension = new Authentication($auth);
$this->assertFalse($extension->checkAuth('foo.bar'));
diff --git a/tests/Unit/Renderer/Twig/Extensions/GlobalsTest.php b/tests/Unit/Renderer/Twig/Extensions/GlobalsTest.php
index 6441904b..a317ad97 100644
--- a/tests/Unit/Renderer/Twig/Extensions/GlobalsTest.php
+++ b/tests/Unit/Renderer/Twig/Extensions/GlobalsTest.php
@@ -2,25 +2,36 @@
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
+use Engelsystem\Helpers\Authenticator;
+use Engelsystem\Models\User\User;
use Engelsystem\Renderer\Twig\Extensions\Globals;
+use PHPUnit\Framework\MockObject\MockObject;
class GlobalsTest extends ExtensionTest
{
/**
+ * @covers \Engelsystem\Renderer\Twig\Extensions\Globals::__construct
* @covers \Engelsystem\Renderer\Twig\Extensions\Globals::getGlobals
*/
public function testGetGlobals()
{
- global $user;
- $user = [];
+ /** @var Authenticator|MockObject $auth */
+ $auth = $this->createMock(Authenticator::class);
+ $user = new User();
- $extension = new Globals();
+ $auth->expects($this->exactly(2))
+ ->method('user')
+ ->willReturnOnConsecutiveCalls(
+ null,
+ $user
+ );
+
+ $extension = new Globals($auth);
$globals = $extension->getGlobals();
$this->assertGlobalsExists('user', [], $globals);
- $user['foo'] = 'bar';
$globals = $extension->getGlobals();
- $this->assertGlobalsExists('user', ['foo' => 'bar'], $globals);
+ $this->assertGlobalsExists('user', $user, $globals);
}
}