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

tests/WebTest/Admin/ContentAdminTest.php (1 issue)

Check for unnecessary variable assignments.

Unused Code Major

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);
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);
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
$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