|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Website\Grid\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Admin\Grid\Factory\GridFactory; |
|
8
|
|
|
use AbterPhp\Admin\Grid\Factory\PaginationFactory; |
|
9
|
|
|
use AbterPhp\Framework\Grid\IGrid; |
|
10
|
|
|
use AbterPhp\Website\Domain\Entities\Page as Entity; |
|
11
|
|
|
use AbterPhp\Website\Domain\Entities\PageCategory; |
|
|
|
|
|
|
12
|
|
|
use AbterPhp\Website\Grid\Factory\Table\Page as TableFactory; |
|
13
|
|
|
use AbterPhp\Website\Grid\Filters\Page as Filters; |
|
14
|
|
|
use Opulence\Routing\Urls\UrlGenerator; |
|
15
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class PageTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var Page - System Under Test */ |
|
21
|
|
|
protected $sut; |
|
22
|
|
|
|
|
23
|
|
|
/** @var MockObject|UrlGenerator */ |
|
24
|
|
|
protected $urlGeneratorMock; |
|
25
|
|
|
|
|
26
|
|
|
/** @var MockObject|PaginationFactory */ |
|
27
|
|
|
protected $paginationFactoryMock; |
|
28
|
|
|
|
|
29
|
|
|
/** @var MockObject|TableFactory */ |
|
30
|
|
|
protected $tableFactoryMock; |
|
31
|
|
|
|
|
32
|
|
|
/** @var MockObject|GridFactory */ |
|
33
|
|
|
protected $gridFactoryMock; |
|
34
|
|
|
|
|
35
|
|
|
/** @var MockObject|Filters */ |
|
36
|
|
|
protected $filtersMock; |
|
37
|
|
|
|
|
38
|
|
|
public function setUp(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->urlGeneratorMock = $this->createMock(UrlGenerator::class); |
|
41
|
|
|
$this->paginationFactoryMock = $this->createMock(PaginationFactory::class); |
|
42
|
|
|
$this->tableFactoryMock = $this->createMock(TableFactory::class); |
|
43
|
|
|
$this->gridFactoryMock = $this->createMock(GridFactory::class); |
|
44
|
|
|
$this->filtersMock = $this->createMock(Filters::class); |
|
45
|
|
|
|
|
46
|
|
|
$this->sut = new Page( |
|
47
|
|
|
$this->urlGeneratorMock, |
|
48
|
|
|
$this->paginationFactoryMock, |
|
49
|
|
|
$this->tableFactoryMock, |
|
50
|
|
|
$this->gridFactoryMock, |
|
51
|
|
|
$this->filtersMock |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testCreateGrid() |
|
56
|
|
|
{ |
|
57
|
|
|
$params = []; |
|
58
|
|
|
$baseUrl = ''; |
|
59
|
|
|
|
|
60
|
|
|
$actualResult = $this->sut->createGrid($params, $baseUrl); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertInstanceOf(IGrid::class, $actualResult); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testGetCategoryNameIsEmptyStringIfNoCategoryIsSet() |
|
66
|
|
|
{ |
|
67
|
|
|
$entity = new Entity('', '', '', '', '', '', false); |
|
68
|
|
|
|
|
69
|
|
|
$actualResult = $this->sut->getCategoryName($entity); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertSame('<i class="material-icons pmd-sm">remove</i>', $actualResult); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testGetCategoryReturnsCategoryNameIfSet() |
|
75
|
|
|
{ |
|
76
|
|
|
$categoryName = 'foo'; |
|
77
|
|
|
$category = new PageCategory('', $categoryName, ''); |
|
78
|
|
|
$entity = new Entity('', '', '', '', '', '', false, $category); |
|
79
|
|
|
|
|
80
|
|
|
$actualResult = $this->sut->getCategoryName($entity); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertSame($categoryName, $actualResult); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testIsPublishedIfPageIsDraft() |
|
86
|
|
|
{ |
|
87
|
|
|
$entity = new Entity('', '', '', '', '', '', true); |
|
88
|
|
|
|
|
89
|
|
|
$actualResult = $this->sut->isPublished($entity); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertStringContainsString('is-danger', $actualResult); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testIsPublishedIfPageIsNotDraft() |
|
95
|
|
|
{ |
|
96
|
|
|
$entity = new Entity('', '', '', '', '', '', false); |
|
97
|
|
|
|
|
98
|
|
|
$actualResult = $this->sut->isPublished($entity); |
|
99
|
|
|
|
|
100
|
|
|
$this->assertStringContainsString('is-success', $actualResult); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: