engelsystem/tests/Unit/Renderer/Twig/Extensions/GlobalsTest.php

56 lines
1.7 KiB
PHP
Raw Normal View History

2018-08-26 12:23:47 +02:00
<?php
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
2018-09-02 02:09:56 +02:00
use Carbon\Carbon;
2018-08-26 12:23:47 +02:00
use Engelsystem\Renderer\Twig\Extensions\Globals;
2018-09-02 02:09:56 +02:00
use PHPUnit\Framework\MockObject\MockObject;
2018-08-26 12:23:47 +02:00
class GlobalsTest extends ExtensionTest
{
/**
* @covers \Engelsystem\Renderer\Twig\Extensions\Globals::getGlobals
2018-09-02 02:09:56 +02:00
* @covers \Engelsystem\Renderer\Twig\Extensions\Globals::filterEventConfig
2018-08-26 12:23:47 +02:00
*/
public function testGetGlobals()
{
2018-09-02 02:09:56 +02:00
global $user;
$user = [];
/** @var Globals|MockObject $extension */
$extension = $this->getMockBuilder(Globals::class)
->setMethods(['getEventConfig'])
->getMock();
$extension->expects($this->exactly(2))
->method('getEventConfig')
->willReturnOnConsecutiveCalls(
null,
[
'lorem' => 'ipsum',
'event_end_date' => 1234567890,
]
);
2018-08-26 12:23:47 +02:00
$globals = $extension->getGlobals();
$this->assertGlobalsExists('user', [], $globals);
2018-09-02 02:09:56 +02:00
$this->assertGlobalsExists('event_config', [], $globals);
2018-08-26 12:23:47 +02:00
$user['foo'] = 'bar';
$globals = $extension->getGlobals();
$this->assertGlobalsExists('user', ['foo' => 'bar'], $globals);
2018-09-02 02:09:56 +02:00
$this->assertGlobalsExists('event_config', ['lorem' => 'ipsum'], $globals);
$config = $globals['event_config'];
$this->assertArrayHasKey('event_end_date', $config);
/** @var Carbon $eventEndDate */
$eventEndDate = $config['event_end_date'];
$this->assertInstanceOf(Carbon::class, $eventEndDate);
$eventEndDate->setTimezone('UTC');
$this->assertEquals('2009-02-13 23:31:30', $eventEndDate->format('Y-m-d H:i:s'));
2018-08-26 12:23:47 +02:00
}
}