summaryrefslogtreecommitdiff
path: root/tests/Unit/Renderer/Twig/Extensions/GlobalsTest.php
blob: cdd9cd2a95bf2a6fc92ce06d685445ce359b77a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;

use Carbon\Carbon;
use Engelsystem\Renderer\Twig\Extensions\Globals;
use PHPUnit\Framework\MockObject\MockObject;

class GlobalsTest extends ExtensionTest
{
    /**
     * @covers \Engelsystem\Renderer\Twig\Extensions\Globals::getGlobals
     * @covers \Engelsystem\Renderer\Twig\Extensions\Globals::filterEventConfig
     */
    public function testGetGlobals()
    {
        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,
                ]
            );

        $globals = $extension->getGlobals();

        $this->assertGlobalsExists('user', [], $globals);
        $this->assertGlobalsExists('event_config', [], $globals);

        $user['foo'] = 'bar';

        $globals = $extension->getGlobals();
        $this->assertGlobalsExists('user', ['foo' => 'bar'], $globals);
        $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'));
    }
}