-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathCrudTestIndexAsserts.php
More file actions
149 lines (116 loc) · 7.07 KB
/
Copy pathCrudTestIndexAsserts.php
File metadata and controls
149 lines (116 loc) · 7.07 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace EasyCorp\Bundle\EasyAdminBundle\Test\Trait;
trait CrudTestIndexAsserts
{
use CrudTestSelectors;
protected static function assertIndexFullEntityCount(int $expectedIndexFullEntityCount, ?string $message = null): void
{
if (0 > $expectedIndexFullEntityCount) {
throw new \InvalidArgumentException();
}
if (0 === $expectedIndexFullEntityCount) {
$message ??= 'There should be no results found in the index table';
static::assertSelectorTextSame('.no-results', 'No results found.', $message);
return;
}
$message ??= sprintf('There should be a total of %d results found in the index table', $expectedIndexFullEntityCount);
static::assertSelectorNotExists('.no-results');
static::assertSelectorTextSame('.list-pagination-counter strong', (string) $expectedIndexFullEntityCount, $message);
}
protected function assertIndexPageEntityCount(int $expectedIndexPageEntityCount, ?string $message = null): void
{
if (0 > $expectedIndexPageEntityCount) {
throw new \InvalidArgumentException();
}
if (0 === $expectedIndexPageEntityCount) {
$message ??= 'There should be no results found in the index table';
static::assertSelectorExists('tr.no-results', $message);
return;
}
$message ??= sprintf('There should be %d results found in the current index page', $expectedIndexPageEntityCount);
static::assertSelectorNotExists('tr.no-results');
static::assertSelectorExists('tbody tr');
$indexPageEntityRows = $this->client->getCrawler()->filter('tbody tr');
static::assertEquals($expectedIndexPageEntityCount, $indexPageEntityRows->count(), $message);
}
protected function assertIndexPagesCount(int $expectedIndexPagesCount, ?string $message = null): void
{
if (0 >= $expectedIndexPagesCount) {
throw new \InvalidArgumentException();
}
$message ??= sprintf('There should be a total of %d pages in the index page', $expectedIndexPagesCount);
$pageItemsSelector = '.list-pagination-paginator ul.pagination li.page-item';
static::assertSelectorExists($pageItemsSelector);
$pageItems = $this->client->getCrawler()->filter($pageItemsSelector);
$lastNumberedPageItem = $pageItems->slice($pageItems->count() - 2, 1);
static::assertEquals((string) $expectedIndexPagesCount, $lastNumberedPageItem->filter('a')->text(), $message);
}
protected function assertIndexEntityActionExists(string $action, string|int $entityId, ?string $message = null): void
{
$message ??= sprintf('The action %s has not been found for entity id %s', $action, (string) $entityId);
$entityRow = $this->client->getCrawler()->filter($this->getIndexEntityRowSelector($entityId));
self::assertCount(1, $entityRow, sprintf('The entity %s is not existing in the table', (string) $entityId));
$action = $entityRow->first()->filter($this->getActionSelector($action));
self::assertCount(1, $action, $message);
}
protected function assertIndexEntityActionNotExists(string $action, string|int $entityId, ?string $message = null): void
{
$message ??= sprintf('The action %s has been found for entity id %s', $action, (string) $entityId);
$entityRow = $this->client->getCrawler()->filter($this->getIndexEntityRowSelector($entityId));
self::assertCount(1, $entityRow, sprintf('The entity %s is not existing in the table', (string) $entityId));
$action = $entityRow->first()->filter($this->getActionSelector($action));
self::assertCount(0, $action, $message);
}
protected function assertIndexEntityActionTextSame(string $action, string $actionDisplay, string|int $entityId, ?string $message = null): void
{
$this->assertIndexEntityActionExists($action, $entityId);
$message ??= sprintf('The action %s is not labelled with the following text : %s', $action, $actionDisplay);
self::assertSelectorTextSame($this->getIndexEntityActionSelector($action, $entityId), $actionDisplay, $message);
}
protected function assertIndexEntityActionNotTextSame(string $action, string $actionDisplay, string|int $entityId, ?string $message = null): void
{
$this->assertIndexEntityActionExists($action, $entityId);
$message ??= sprintf('The action %s is labelled with the following text : %s', $action, $actionDisplay);
self::assertSelectorTextNotContains($this->getIndexEntityActionSelector($action, $entityId), $actionDisplay, $message);
}
protected function assertGlobalActionExists(string $action, ?string $message = null): void
{
$message ??= sprintf('The global action %s does not exist', $action);
self::assertSelectorExists($this->getGlobalActionSelector($action), $message);
}
protected function assertGlobalActionNotExists(string $action, ?string $message = null): void
{
$message ??= sprintf('The global action %s does exist', $action);
self::assertSelectorNotExists($this->getGlobalActionSelector($action), $message);
}
protected function assertGlobalActionDisplays(string $action, string $actionDisplay, ?string $message = null): void
{
$message ??= sprintf('The global action %s does not display %s', $action, $actionDisplay);
self::assertSelectorTextSame($this->getGlobalActionSelector($action), $actionDisplay, $message);
}
protected function assertGlobalActionNotDisplays(string $action, string $actionDisplay, ?string $message = null): void
{
$message ??= sprintf('The global action %s does display %s', $action, $actionDisplay);
self::assertSelectorTextNotContains($this->getGlobalActionSelector($action), $actionDisplay, $message);
}
protected function assertIndexColumnExists(string $columnName, ?string $message = null): void
{
$message ??= sprintf('The column %s is not existing', $columnName);
self::assertSelectorExists($this->getIndexHeaderColumnSelector($columnName), $message);
}
protected function assertIndexColumnNotExists(string $columnName, ?string $message = null): void
{
$message ??= sprintf('The column %s is existing', $columnName);
self::assertSelectorNotExists($this->getIndexHeaderColumnSelector($columnName), $message);
}
protected function assertIndexColumnHeaderContains(string $columnName, string $columnHeaderValue, ?string $message = null): void
{
$message ??= sprintf('The column %s does not contain %s', $columnName, $columnHeaderValue);
self::assertSelectorTextSame($this->getIndexHeaderColumnSelector($columnName), $columnHeaderValue, $message);
}
protected function assertIndexColumnHeaderNotContains(string $columnName, string $columnHeaderValue, ?string $message = null): void
{
$message ??= sprintf('The column %s contains %s', $columnName, $columnHeaderValue);
self::assertSelectorTextNotContains($this->getIndexHeaderColumnSelector($columnName), $columnHeaderValue, $message);
}
}