1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Tests\Functional\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
6
|
|
|
|
7
|
|
|
class AbstractAdminController extends AbstractController |
8
|
|
|
{ |
9
|
|
|
protected function assertAdminListPageHasColumns(array $columns) |
10
|
|
|
{ |
11
|
|
|
$expectedColumns = $columns; |
12
|
|
|
$page = $this->getSessionClient()->getCrawler(); |
13
|
|
|
|
14
|
|
|
$listPageColumns = $page->filter('.sonata-ba-list-field-header')->children()->each(function(Crawler $column, $i) { |
|
|
|
|
15
|
|
|
if (false == strpos($column->attr('class'), 'sonata-ba-list-field-header-batch')) { |
|
|
|
|
16
|
|
|
return trim($column->text()); |
17
|
|
|
} |
18
|
|
|
}); |
19
|
|
|
$listPageColumns = array_filter($listPageColumns); |
20
|
|
|
|
21
|
|
|
$notHaveColumns = array_diff($expectedColumns, $listPageColumns); |
22
|
|
|
$this->assertEquals([], $notHaveColumns, sprintf( |
23
|
|
|
'Not have columns "%s" in "%s"', |
24
|
|
|
implode(', ', $notHaveColumns), |
25
|
|
|
implode(', ', $listPageColumns) |
26
|
|
|
)); |
27
|
|
|
|
28
|
|
|
$extraColumns = array_diff($listPageColumns, $expectedColumns); |
29
|
|
|
$this->assertEquals([], $extraColumns, sprintf('Found extra columns "%s"', implode(', ', $extraColumns))); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function processDeleteAction($object) |
33
|
|
|
{ |
34
|
|
|
$this->logIn(); |
35
|
|
|
|
36
|
|
|
$objectNS = get_class($object); |
37
|
|
|
$namespaceParts = explode('\\', $objectNS); |
38
|
|
|
$entityName = array_pop($namespaceParts); |
39
|
|
|
|
40
|
|
|
$page = $this->request(sprintf('/admin/%s/%s/delete?tl=en', $entityName, $object->getId()), 'GET', 200); |
41
|
|
|
// file_put_contents('/tmp/test.html', $this->getSessionClient()->getResponse()->getContent()); |
42
|
|
|
$form = $this->getConfirmDeleteFormObject($page); |
43
|
|
|
|
44
|
|
|
$this->getSessionClient()->followRedirects(true); |
45
|
|
|
$listPage = $this->getSessionClient()->submit($form); |
46
|
|
|
|
47
|
|
|
$this->assertContains( |
48
|
|
|
'has been deleted successfully.', |
49
|
|
|
trim($listPage->filter('.alert-success')->text()) |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
// Tested softdeleteable and blameable |
53
|
|
|
$id = $object->getId(); |
54
|
|
|
$this->getEm()->detach($object); |
|
|
|
|
55
|
|
|
$object = $this->getEm()->find($objectNS, $id); |
56
|
|
|
$this->assertNull($object); |
57
|
|
|
|
58
|
|
|
$this->getEm()->getFilters()->disable('softdeleteable'); |
59
|
|
|
$object = $this->getEm()->find($objectNS, $id); |
60
|
|
|
$this->assertNotNull($object, sprintf('SoftDeleteable filter is not active for "%s" entity', $entityName)); |
61
|
|
|
$this->assertEquals('admin', $object->getDeletedBy()); |
62
|
|
|
|
63
|
|
|
$this->getEm()->getFilters()->enable('softdeleteable'); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.