Completed
Pull Request — master (#485)
by Maximilian
01:47
created

StaticContentAdminTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 49
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testContentList() 0 8 1
A testContentEdit() 0 8 1
A testContentCreate() 0 22 1
1
<?php
2
3
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\WebTest\Admin;
4
5
use Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\DataFixtures\Phpcr\LoadAssociationData;
6
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;
7
8
class StaticContentAdminTest extends BaseTestCase
9
{
10
    public function setUp()
11
    {
12
        $this->db('PHPCR')->loadFixtures([LoadAssociationData::class]);
13
        $this->client = $this->createClient();
14
    }
15
16
    public function testContentList()
17
    {
18
        $crawler = $this->client->request('GET', '/admin/tests/resources/content/list');
19
        $res = $this->client->getResponse();
20
21
        $this->assertResponseSuccess($res);
22
        $this->assertCount(1, $crawler->filter('html:contains("Content 1")'));
23
    }
24
25
    public function testContentEdit()
26
    {
27
        $crawler = $this->client->request('GET', '/admin/tests/resources/content/test/content/content-1/edit');
28
        $res = $this->client->getResponse();
29
30
        $this->assertResponseSuccess($res);
31
        $this->assertCount(1, $crawler->filter('input[value="content-1"]'));
32
    }
33
34
    public function testContentCreate()
35
    {
36
        $crawler = $this->client->request('GET', '/admin/tests/resources/content/create');
37
        $res = $this->client->getResponse();
38
        $this->assertResponseSuccess($res);
39
40
        $button = $crawler->selectButton('Create');
41
        $form = $button->form();
42
        $node = $form->getFormNode();
43
        $actionUrl = $node->getAttribute('action');
44
        $uniqId = substr(strstr($actionUrl, '='), 1);
45
46
        $form[$uniqId.'[parentDocument]'] = '/test/content';
47
        $form[$uniqId.'[name]'] = 'foo-test';
48
        $form[$uniqId.'[title]'] = 'Foo Test';
49
50
        $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...
51
        $res = $this->client->getResponse();
52
53
        // If we have a 302 redirect, then all is well
54
        $this->assertEquals(302, $res->getStatusCode());
55
    }
56
}
57