AbstractAdminController::processDeleteAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
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) {
0 ignored issues
show
Unused Code introduced by
The parameter $i is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
15
            if (false == strpos($column->attr('class'), 'sonata-ba-list-field-header-batch')) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($column->attr('cl...st-field-header-batch') of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\ORM\EntityManager::detach() has been deprecated with message: 2.7 This method is being removed from the ORM and won't have any replacement

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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