ContentAdminTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 82
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testContentWithChildEdit() 0 16 1
A testContentWithChildrenEdit() 0 13 1
A testContentCreate() 0 22 1
A testShowContent() 0 10 2
A setUp() 0 5 1
A testContentList() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\WebTest\Admin;
15
16
use Sonata\DoctrinePHPCRAdminBundle\Tests\Fixtures\App\DataFixtures\Phpcr\LoadTreeData;
17
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;
18
19
class ContentAdminTest extends BaseTestCase
20
{
21
    protected function setUp(): void
22
    {
23
        $this->db('PHPCR')->loadFixtures([LoadTreeData::class]);
24
        $this->client = $this->createClient();
25
    }
26
27
    public function testContentList(): void
28
    {
29
        $crawler = $this->client->request('GET', '/admin/fixtures/app/content/list');
30
        $res = $this->client->getResponse();
31
32
        $this->assertResponseSuccess($res);
33
        $this->assertCount(1, $crawler->filter('html:contains("Content 1")'));
34
    }
35
36
    public function testContentWithChildEdit(): void
37
    {
38
        $crawler = $this->client->request('GET', '/admin/fixtures/app/content/test/content/content-1/edit');
39
        $res = $this->client->getResponse();
40
41
        $this->assertResponseSuccess($res);
42
        $this->assertCount(1, $crawler->filter('input[value="content-1"]'));
43
        $this->assertCount(1, $crawler->filter('input[value="Content 1"]'));
44
        $this->assertCount(1, $crawler->filter('input[value="/test/content"]'));
45
        $this->assertCount(1, $crawler->filter('input[value="/test/routes/route-1"]'));
46
        // ToDo: Sub Admin for child association
47
        $this->assertCount(1, $crawler->filter('div[id$="child"] select'));
48
49
        // see the routes selection of a ModelType
50
        $this->assertCount(1, $crawler->filter('div[id$="_routes"] select'));
51
    }
52
53
    public function testContentWithChildrenEdit(): void
54
    {
55
        $crawler = $this->client->request('GET', '/admin/fixtures/app/content/test/content/content-2/edit');
56
        $res = $this->client->getResponse();
57
58
        $this->assertResponseSuccess($res);
59
        $this->assertCount(1, $crawler->filter('input[value="content-2"]'));
60
        $this->assertCount(1, $crawler->filter('input[value="Content 2"]'));
61
        $this->assertCount(1, $crawler->filter('input[value="/test/content"]'));
62
63
        // see the children table view of a CollectionType
64
        $this->assertCount(1, $crawler->filter('div[id$="_children"] table'));
65
    }
66
67
    public function testContentCreate(): void
68
    {
69
        $crawler = $this->client->request('GET', '/admin/fixtures/app/content/create');
70
        $res = $this->client->getResponse();
71
        $this->assertResponseSuccess($res);
72
73
        $button = $crawler->selectButton('Create');
74
        $form = $button->form();
75
        $node = $form->getFormNode();
76
        $actionUrl = $node->getAttribute('action');
77
        $uniqId = substr(strstr($actionUrl, '='), 1);
78
79
        $form[$uniqId.'[parentDocument]'] = '/test/content';
80
        $form[$uniqId.'[name]'] = 'foo-test';
81
        $form[$uniqId.'[title]'] = 'Foo Test';
82
83
        $this->client->submit($form);
0 ignored issues
show
Documentation introduced by
$form is of type array<string,string>, but the function expects a object<Symfony\Component\DomCrawler\Form>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
        $res = $this->client->getResponse();
85
86
        // If we have a 302 redirect, then all is well
87
        $this->assertSame(302, $res->getStatusCode());
88
    }
89
90
    public function testShowContent(): void
91
    {
92
        $crawler = $this->client->request('GET', '/admin/fixtures/app/content/test/content/content-1/show');
0 ignored issues
show
Unused Code introduced by
$crawler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
93
        $res = $this->client->getResponse();
94
95
        if (200 !== $res->getStatusCode()) {
96
            echo $res->getContent();
97
        }
98
        $this->assertResponseSuccess($res);
99
    }
100
}
101