1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Contact\Template\Loader; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Contact\Form\Factory\Contact as FormFactory; |
8
|
|
|
use AbterPhp\Framework\Form\IForm; |
9
|
|
|
use AbterPhp\Framework\I18n\ITranslator; |
10
|
|
|
use AbterPhp\Framework\Template\Data; |
11
|
|
|
use AbterPhp\Framework\Template\ParsedTemplate; |
12
|
|
|
use Opulence\Events\Dispatchers\IEventDispatcher; |
13
|
|
|
use Opulence\Routing\Urls\UrlGenerator; |
14
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class ContactTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** @var Contact - System Under Test */ |
20
|
|
|
protected $sut; |
21
|
|
|
|
22
|
|
|
/** @var UrlGenerator|MockObject */ |
23
|
|
|
protected $urlGeneratorMock; |
24
|
|
|
|
25
|
|
|
/** @var FormFactory|MockObject */ |
26
|
|
|
protected $formFactoryMock; |
27
|
|
|
|
28
|
|
|
/** @var ITranslator|MockObject */ |
29
|
|
|
protected $translatorMock; |
30
|
|
|
|
31
|
|
|
/** @var IEventDispatcher|MockObject */ |
32
|
|
|
protected $eventDispatcherMock; |
33
|
|
|
|
34
|
|
|
public function setUp(): void |
35
|
|
|
{ |
36
|
|
|
$this->urlGeneratorMock = $this->createMock(UrlGenerator::class); |
37
|
|
|
$this->formFactoryMock = $this->createMock(FormFactory::class); |
38
|
|
|
$this->translatorMock = $this->createMock(ITranslator::class); |
39
|
|
|
$this->eventDispatcherMock = $this->createMock(IEventDispatcher::class); |
40
|
|
|
|
41
|
|
|
$this->sut = new Contact( |
42
|
|
|
$this->urlGeneratorMock, |
43
|
|
|
$this->formFactoryMock, |
44
|
|
|
$this->translatorMock, |
45
|
|
|
$this->eventDispatcherMock |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testLoadWithoutParsedTemplates() |
50
|
|
|
{ |
51
|
|
|
$parsedTemplates = []; |
52
|
|
|
|
53
|
|
|
$actualResult = $this->sut->load($parsedTemplates); |
54
|
|
|
|
55
|
|
|
$this->assertSame([], $actualResult); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testLoadWithOneParsedTemplates() |
59
|
|
|
{ |
60
|
|
|
$urlStub = 'https://example.com/'; |
61
|
|
|
$formHtml = '<form />'; |
62
|
|
|
|
63
|
|
|
$formStub = $this->createMock(IForm::class); |
64
|
|
|
$formStub->expects($this->any())->method('__toString')->willReturn($formHtml); |
65
|
|
|
|
66
|
|
|
$this->urlGeneratorMock->expects($this->any())->method('createFromName')->willReturn($urlStub); |
67
|
|
|
$this->formFactoryMock->expects($this->any())->method('create')->willReturn($formStub); |
68
|
|
|
|
69
|
|
|
$parsedTemplates = ['foo' => $this->createMock(ParsedTemplate::class)]; |
70
|
|
|
|
71
|
|
|
$actualResult = $this->sut->load($parsedTemplates); |
72
|
|
|
|
73
|
|
|
$this->assertIsArray($actualResult); |
74
|
|
|
$this->assertCount(1, $actualResult); |
75
|
|
|
$this->assertInstanceOf(Data::class, $actualResult[0]); |
76
|
|
|
$this->assertSame([$formHtml], $actualResult[0]->getTemplates()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testHasAnyChangedSinceReturnsWhenCalledWithoutIdentifiers() |
80
|
|
|
{ |
81
|
|
|
$identifiers = []; |
82
|
|
|
|
83
|
|
|
$actualResult = $this->sut->hasAnyChangedSince($identifiers, ''); |
84
|
|
|
|
85
|
|
|
$this->assertFalse($actualResult); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testHasAnyChangedSinceReturnsTrueWhenCalledWithIdentifiers() |
89
|
|
|
{ |
90
|
|
|
$identifiers = ['foo', 'bar']; |
91
|
|
|
|
92
|
|
|
$actualResult = $this->sut->hasAnyChangedSince($identifiers, ''); |
93
|
|
|
|
94
|
|
|
$this->assertTrue($actualResult); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|