1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Website\Template\Loader; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Template\ParsedTemplate; |
8
|
|
|
use AbterPhp\Website\Databases\Queries\BlockCache; |
9
|
|
|
use AbterPhp\Website\Domain\Entities\Block as BlockEntity; |
10
|
|
|
use AbterPhp\Website\Orm\BlockRepo; |
11
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class BlockTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** @var Block - System Under Test */ |
17
|
|
|
protected $sut; |
18
|
|
|
|
19
|
|
|
/** @var BlockRepo|MockObject */ |
20
|
|
|
protected $repoMock; |
21
|
|
|
|
22
|
|
|
/** @var BlockCache|MockObject */ |
23
|
|
|
protected $cacheMock; |
24
|
|
|
|
25
|
|
|
public function setUp(): void |
26
|
|
|
{ |
27
|
|
|
parent::setUp(); |
28
|
|
|
|
29
|
|
|
$this->repoMock = $this->createMock(BlockRepo::class); |
30
|
|
|
|
31
|
|
|
$this->cacheMock = $this->createMock(BlockCache::class); |
32
|
|
|
|
33
|
|
|
$this->sut = new Block($this->repoMock, $this->cacheMock); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testLoadOne() |
37
|
|
|
{ |
38
|
|
|
$identifier = 'block-1'; |
39
|
|
|
|
40
|
|
|
$entity = new BlockEntity('', $identifier, '', '', ''); |
41
|
|
|
|
42
|
|
|
$this->repoMock |
43
|
|
|
->expects($this->any()) |
44
|
|
|
->method('getWithLayoutByIdentifiers') |
45
|
|
|
->willReturn([$entity]); |
46
|
|
|
|
47
|
|
|
$parsedTemplates = [ |
48
|
|
|
$identifier => [new ParsedTemplate('block', $identifier)], |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
$templateDataCollection = $this->sut->load($parsedTemplates); |
52
|
|
|
|
53
|
|
|
$this->assertCount(1, $templateDataCollection); |
54
|
|
|
foreach ($templateDataCollection as $templateData) { |
55
|
|
|
$this->assertSame($identifier, $templateData->getIdentifier()); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testHasAnyChangedSinceCallsBlockCache() |
60
|
|
|
{ |
61
|
|
|
$identifiers = ['foo', 'bar', 'baz']; |
62
|
|
|
$cacheTime = 'foo'; |
63
|
|
|
$expectedResult = true; |
64
|
|
|
|
65
|
|
|
$this->cacheMock |
66
|
|
|
->expects($this->once()) |
67
|
|
|
->method('hasAnyChangedSince') |
68
|
|
|
->with($identifiers, $cacheTime) |
69
|
|
|
->willReturn($expectedResult); |
70
|
|
|
|
71
|
|
|
$actualResult = $this->sut->hasAnyChangedSince($identifiers, $cacheTime); |
72
|
|
|
|
73
|
|
|
$this->assertSame($expectedResult, $actualResult); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|