Fixed globals and design unit tests
This commit is contained in:
parent
5f7fcb9018
commit
03185f8865
|
@ -37,19 +37,20 @@ class DesignControllerTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testIndexSetTheme()
|
public function testIndexSetTheme()
|
||||||
{
|
{
|
||||||
|
$theme = ['name' => 'Meaning of Live'];
|
||||||
/** @var Response|MockObject $response */
|
/** @var Response|MockObject $response */
|
||||||
$response = $this->createMock(Response::class);
|
$response = $this->createMock(Response::class);
|
||||||
$response->expects($this->once())
|
$response->expects($this->once())
|
||||||
->method('withView')
|
->method('withView')
|
||||||
->willReturnCallback(function (string $view, array $data) use ($response) {
|
->willReturnCallback(function (string $view, array $data) use ($response, $theme) {
|
||||||
$this->assertTrue(isset($data['theme']));
|
$this->assertTrue(isset($data['theme']));
|
||||||
$this->assertEquals('42', $data['theme']);
|
$this->assertEquals($theme, $data['theme']);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
});
|
});
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request->attributes->set('theme', '42');
|
$request->attributes->set('theme', '42');
|
||||||
$config = new Config(['themes' => [42 => [ 'name' => 'Meaning of Live']]]);
|
$config = new Config(['themes' => [42 => $theme]]);
|
||||||
|
|
||||||
$controller = new DesignController($response, $config);
|
$controller = new DesignController($response, $config);
|
||||||
$controller->index($request);
|
$controller->index($request);
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
||||||
|
|
||||||
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
use Engelsystem\Test\Unit\TestCase;
|
||||||
use Exception;
|
use Exception;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Twig\Node\Node as TwigNode;
|
use Twig\Node\Node as TwigNode;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
|
|
|
@ -2,25 +2,36 @@
|
||||||
|
|
||||||
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
||||||
|
|
||||||
|
use Engelsystem\Config\Config;
|
||||||
use Engelsystem\Helpers\Authenticator;
|
use Engelsystem\Helpers\Authenticator;
|
||||||
use Engelsystem\Http\Request;
|
use Engelsystem\Http\Request;
|
||||||
|
use Engelsystem\Models\User\Settings;
|
||||||
use Engelsystem\Models\User\User;
|
use Engelsystem\Models\User\User;
|
||||||
use Engelsystem\Renderer\Twig\Extensions\Globals;
|
use Engelsystem\Renderer\Twig\Extensions\Globals;
|
||||||
|
use Engelsystem\Test\Unit\HasDatabase;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
class GlobalsTest extends ExtensionTest
|
class GlobalsTest extends ExtensionTest
|
||||||
{
|
{
|
||||||
|
use HasDatabase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Engelsystem\Renderer\Twig\Extensions\Globals::__construct
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Globals::__construct
|
||||||
* @covers \Engelsystem\Renderer\Twig\Extensions\Globals::getGlobals
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Globals::getGlobals
|
||||||
*/
|
*/
|
||||||
public function testGetGlobals()
|
public function testGetGlobals()
|
||||||
{
|
{
|
||||||
|
$this->initDatabase();
|
||||||
|
|
||||||
/** @var Authenticator|MockObject $auth */
|
/** @var Authenticator|MockObject $auth */
|
||||||
$auth = $this->createMock(Authenticator::class);
|
$auth = $this->createMock(Authenticator::class);
|
||||||
/** @var Request|MockObject $request */
|
/** @var Request|MockObject $request */
|
||||||
$request = $this->createMock(Request::class);
|
$request = $this->createMock(Request::class);
|
||||||
$user = new User();
|
$theme = ['name' => 'Testtheme', 'navbar_classes' => 'something'];
|
||||||
|
$theme2 = ['name' => 'Bar'];
|
||||||
|
$user = new User(['name' => '', 'email' => '', 'password' => '', 'api_key' => '']);
|
||||||
|
$userSettings = new Settings(['theme' => 42, 'language' => '']);
|
||||||
|
$config = new Config(['theme' => 23, 'themes' => [42 => $theme, 23 => $theme2]]);
|
||||||
|
|
||||||
$auth->expects($this->exactly(2))
|
$auth->expects($this->exactly(2))
|
||||||
->method('user')
|
->method('user')
|
||||||
|
@ -29,13 +40,25 @@ class GlobalsTest extends ExtensionTest
|
||||||
$user
|
$user
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$userSettings->user()
|
||||||
|
->associate($user)
|
||||||
|
->save();
|
||||||
|
|
||||||
|
$this->app->instance('config', $config);
|
||||||
|
|
||||||
$extension = new Globals($auth, $request);
|
$extension = new Globals($auth, $request);
|
||||||
|
|
||||||
$globals = $extension->getGlobals();
|
$globals = $extension->getGlobals();
|
||||||
$this->assertGlobalsExists('user', [], $globals);
|
$this->assertGlobalsExists('user', [], $globals);
|
||||||
$this->assertGlobalsExists('request', $request, $globals);
|
$this->assertGlobalsExists('request', $request, $globals);
|
||||||
|
$this->assertGlobalsExists('themeId', 23, $globals);
|
||||||
|
$this->assertGlobalsExists('theme', $theme2, $globals);
|
||||||
|
|
||||||
$globals = $extension->getGlobals();
|
$globals = $extension->getGlobals();
|
||||||
$this->assertGlobalsExists('user', $user, $globals);
|
$this->assertGlobalsExists('user', $user, $globals);
|
||||||
|
$this->assertGlobalsExists('themeId', 42, $globals);
|
||||||
|
$this->assertGlobalsExists('theme', $theme, $globals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue