Completed
Push — master ( eb83f4...bb238e )
by Maximilian
14s
created

ContentAdminTest::testContentWithChildEdit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
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\LoadTreeData'));
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 testContentWithChildEdit()
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
        $this->assertCount(1, $crawler->filter('input[value="Content 1"]'));
32
        $this->assertCount(1, $crawler->filter('input[value="/test/content"]'));
33
        $this->assertCount(1, $crawler->filter('input[value="/test/routes/route-1"]'));
34
        // ToDo: Sub Admin for child association
35
        $this->assertCount(1, $crawler->filter('div[id$="child"] select'));
36
37
        // see the routes selection of a ModelType
38
        $this->assertCount(1, $crawler->filter('div[id$="_routes"] select'));
39
    }
40
41
    public function testContentWithChildrenEdit()
42
    {
43
        $crawler = $this->client->request('GET', '/admin/tests/resources/content/test/content/content-2/edit');
44
        $res = $this->client->getResponse();
45
46
        $this->assertResponseSuccess($res);
47
        $this->assertCount(1, $crawler->filter('input[value="content-2"]'));
48
        $this->assertCount(1, $crawler->filter('input[value="Content 2"]'));
49
        $this->assertCount(1, $crawler->filter('input[value="/test/content"]'));
50
51
        // see the children table view of a CollectionType
52
        $this->assertCount(1, $crawler->filter('div[id$="_children"] table'));
53
    }
54
55
    public function testContentCreate()
56
    {
57
        $crawler = $this->client->request('GET', '/admin/tests/resources/content/create');
58
        $res = $this->client->getResponse();
59
        $this->assertResponseSuccess($res);
60
61
        $button = $crawler->selectButton('Create');
62
        $form = $button->form();
63
        $node = $form->getFormNode();
64
        $actionUrl = $node->getAttribute('action');
65
        $uniqId = substr(strstr($actionUrl, '='), 1);
66
67
        $form[$uniqId.'[parentDocument]'] = '/test/content';
68
        $form[$uniqId.'[name]'] = 'foo-test';
69
        $form[$uniqId.'[title]'] = 'Foo Test';
70
71
        $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...
72
        $res = $this->client->getResponse();
73
74
        // If we have a 302 redirect, then all is well
75
        $this->assertEquals(302, $res->getStatusCode());
76
    }
77
78
    public function testShowContent()
79
    {
80
        $crawler = $this->client->request('GET', '/admin/tests/resources/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...
81
        $res = $this->client->getResponse();
82
83
        if ($res->getStatusCode() !== 200) {
84
            echo $res->getContent();
85
        }
86
        $this->assertResponseSuccess($res);
87
    }
88
}
89