Completed
Push — master ( 080928...f7c290 )
by
unknown
15:37
created

tests/WebTest/Admin/ContentAdminTest.php (5 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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);
0 ignored issues
show
It seems like $res defined by $this->client->getResponse() on line 18 can be null; however, Symfony\Cmf\Component\Te...assertResponseSuccess() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
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);
0 ignored issues
show
It seems like $res defined by $this->client->getResponse() on line 27 can be null; however, Symfony\Cmf\Component\Te...assertResponseSuccess() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
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);
0 ignored issues
show
It seems like $res defined by $this->client->getResponse() on line 44 can be null; however, Symfony\Cmf\Component\Te...assertResponseSuccess() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
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);
0 ignored issues
show
It seems like $res defined by $this->client->getResponse() on line 58 can be null; however, Symfony\Cmf\Component\Te...assertResponseSuccess() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
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);
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');
81
        $res = $this->client->getResponse();
82
83
        if ($res->getStatusCode() !== 200) {
84
            echo $res->getContent();
85
        }
86
        $this->assertResponseSuccess($res);
0 ignored issues
show
It seems like $res defined by $this->client->getResponse() on line 81 can be null; however, Symfony\Cmf\Component\Te...assertResponseSuccess() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
87
    }
88
}
89