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

ContentAdminTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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