2018-08-26 12:23:47 +02:00
|
|
|
<?php
|
|
|
|
|
2023-02-03 20:41:59 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-08-26 12:23:47 +02:00
|
|
|
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
|
|
|
|
|
|
|
use Engelsystem\Renderer\Twig\Extensions\Session;
|
|
|
|
use Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
|
2023-02-26 11:27:41 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
2018-08-26 12:23:47 +02:00
|
|
|
|
|
|
|
class SessionTest extends ExtensionTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Session::__construct
|
|
|
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Session::getFunctions
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testGetGlobals(): void
|
2018-08-26 12:23:47 +02:00
|
|
|
{
|
2023-02-26 11:27:41 +01:00
|
|
|
$session = new SymfonySession(new MockArraySessionStorage());
|
2018-08-26 12:23:47 +02:00
|
|
|
|
|
|
|
$extension = new Session($session);
|
|
|
|
$functions = $extension->getFunctions();
|
|
|
|
|
|
|
|
$this->assertExtensionExists('session_get', [$session, 'get'], $functions);
|
2021-10-04 21:45:06 +02:00
|
|
|
$this->assertExtensionExists('session_set', [$session, 'set'], $functions);
|
2023-02-26 11:27:41 +01:00
|
|
|
$this->assertExtensionExists('session_pop', [$extension, 'sessionPop'], $functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Session::sessionPop
|
|
|
|
*/
|
|
|
|
public function testSessionPop(): void
|
|
|
|
{
|
|
|
|
$session = new SymfonySession(new MockArraySessionStorage());
|
|
|
|
$session->set('test', 'value');
|
|
|
|
|
|
|
|
$extension = new Session($session);
|
|
|
|
|
|
|
|
$result = $extension->sessionPop('test');
|
|
|
|
$this->assertEquals('value', $result);
|
|
|
|
$this->assertFalse($session->has('test'));
|
|
|
|
|
|
|
|
$result = $extension->sessionPop('foo', 'default value');
|
|
|
|
$this->assertEquals('default value', $result);
|
2018-08-26 12:23:47 +02:00
|
|
|
}
|
|
|
|
}
|