PageLayoutTest::testCreateWithAssets()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 31
rs 9.552
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Form\Factory;
6
7
use AbterPhp\Framework\Html\INode;
8
use AbterPhp\Framework\I18n\ITranslator;
9
use AbterPhp\Website\Domain\Entities\PageLayout as Entity;
10
use AbterPhp\Website\Form\Factory\PageLayout\Assets as AssetsFactory;
11
use Opulence\Http\Requests\RequestMethods;
12
use Opulence\Sessions\ISession;
13
use Opulence\Sessions\Session;
14
use PHPUnit\Framework\MockObject\MockObject;
15
use PHPUnit\Framework\TestCase;
16
17
class PageLayoutTest extends TestCase
18
{
19
    /** @var PageLayout - System Under Test */
20
    protected $sut;
21
22
    /** @var ISession|MockObject */
23
    protected $sessionMock;
24
25
    /** @var ITranslator|MockObject */
26
    protected $translatorMock;
27
28
    /** @var AssetsFactory|MockObject */
29
    protected $assetsFactoryMock;
30
31
    public function setUp(): void
32
    {
33
        parent::setUp();
34
35
        $this->sessionMock = $this->createMock(Session::class);
36
        $this->sessionMock->expects($this->any())->method('get')->willReturnArgument(0);
37
38
        $this->translatorMock = $this->createMock(ITranslator::class);
39
        $this->translatorMock->expects($this->any())->method('translate')->willReturnArgument(0);
40
41
        $this->assetsFactoryMock = $this->createMock(AssetsFactory::class);
42
43
        $this->sut = new PageLayout($this->sessionMock, $this->translatorMock, $this->assetsFactoryMock);
44
    }
45
46
    public function testCreate()
47
    {
48
        $action     = 'foo';
49
        $method     = RequestMethods::POST;
50
        $showUrl    = 'bar';
51
        $entityId   = 'c5098ee4-ab53-4d96-9d23-bde122f8f09b';
52
        $name       = 'Blah';
53
        $identifier = 'blah';
54
        $body       = 'mah';
55
56
        /** @var Entity|MockObject $entityMock */
57
        $entityMock = $this->createMock(Entity::class);
58
59
        $entityMock->expects($this->any())->method('getId')->willReturn($entityId);
60
        $entityMock->expects($this->any())->method('getIdentifier')->willReturn($identifier);
61
        $entityMock->expects($this->any())->method('getName')->willReturn($name);
62
        $entityMock->expects($this->any())->method('getBody')->willReturn($body);
63
64
        $this->assetsFactoryMock->expects($this->any())->method('create')->willReturn([]);
65
66
        $form = (string)$this->sut->create($action, $method, $showUrl, $entityMock);
67
68
        $this->assertStringContainsString($action, $form);
69
        $this->assertStringContainsString($showUrl, $form);
70
        $this->assertStringContainsString('CSRF', $form);
71
        $this->assertStringContainsString('POST', $form);
72
        $this->assertStringContainsString('name', $form);
73
        $this->assertStringContainsString('identifier', $form);
74
        $this->assertStringContainsString('body', $form);
75
        $this->assertStringContainsString('button', $form);
76
    }
77
78
    public function testCreateWithAssets()
79
    {
80
        $action     = 'foo';
81
        $method     = RequestMethods::POST;
82
        $showUrl    = 'bar';
83
        $entityId   = 'c5098ee4-ab53-4d96-9d23-bde122f8f09b';
84
        $name       = 'Blah';
85
        $identifier = 'blah';
86
        $body       = 'mah';
87
88
        /** @var Entity|MockObject $entityMock */
89
        $entityMock = $this->createMock(Entity::class);
90
91
        $entityMock->expects($this->any())->method('getId')->willReturn($entityId);
92
        $entityMock->expects($this->any())->method('getName')->willReturn($name);
93
        $entityMock->expects($this->any())->method('getIdentifier')->willReturn($identifier);
94
        $entityMock->expects($this->any())->method('getBody')->willReturn($body);
95
96
        $assetNodes = [$this->createMock(INode::class)];
97
        $this->assetsFactoryMock->expects($this->any())->method('create')->willReturn($assetNodes);
98
99
        $form = (string)$this->sut->create($action, $method, $showUrl, $entityMock);
100
101
        $this->assertStringContainsString($action, $form);
102
        $this->assertStringContainsString($showUrl, $form);
103
        $this->assertStringContainsString('CSRF', $form);
104
        $this->assertStringContainsString('POST', $form);
105
        $this->assertStringContainsString('name', $form);
106
        $this->assertStringContainsString('identifier', $form);
107
        $this->assertStringContainsString('body', $form);
108
        $this->assertStringContainsString('button', $form);
109
    }
110
}
111