Completed
Push — master ( 3352e6...588911 )
by Laurent
03:33
created

ArticleControllerTest::testSort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace AppBundle\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7
class ArticleControllerTest extends WebTestCase
8
{
9
    public function testCreate()
10
    {
11
        $client = static::createClient();
12
        $crawler = $client->request('GET', '/articles/');
13
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr'));
14
        $crawler = $client->click($crawler->filter('.new_entry a')->link());
15
        $form = $crawler->filter('form button[type="submit"]')->form(array(
16
            'article[name]' => 'Lorem ipsum dolor sit amet',
17
            'article[packaging]' => 10.99,
18
            'article[price]' => 10.99,
19
            'article[quantity]' => 10.99,
20
            'article[minstock]' => 10.99,
21
            'article[active]' => true,
22
            'article[slug]' => 'Lorem ipsum dolor sit amet',
23
                    ));
24
        $client->submit($form);
25
        $crawler = $client->followRedirect();
26
        $crawler = $client->click($crawler->filter('.record_actions a')->link());
27
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr'));
28
    }
29
30
    public function testCreateError()
31
    {
32
        $client = static::createClient();
33
        $crawler = $client->request('GET', '/articles/new');
34
        $form = $crawler->filter('form button[type="submit"]')->form();
35
        $crawler = $client->submit($form);
36
        $this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count());
37
        $this->assertTrue($client->getResponse()->isSuccessful());
38
    }
39
40
    /**
41
     * @depends testCreate
42
     */
43
    public function testEdit()
44
    {
45
        $client = static::createClient();
46
        $crawler = $client->request('GET', '/articles/');
47
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("First value")'));
48
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("Changed")'));
49
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link());
50
        $form = $crawler->filter('form button[type="submit"]')->form(array(
51
            'article[name]' => 'Changed',
52
            'article[packaging]' => 10.99,
53
            'article[price]' => 10.99,
54
            'article[quantity]' => 10.99,
55
            'article[minstock]' => 10.99,
56
            'article[active]' => true,
57
            'article[slug]' => 'Changed',
58
            // ... adapt fields value here ...
59
        ));
60
        $client->submit($form);
61
        $crawler = $client->followRedirect();
62
        $crawler = $client->click($crawler->filter('.record_actions a')->link());
63
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("First value")'));
64
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("Changed")'));
65
    }
66
67
    /**
68
     * @depends testCreate
69
     */
70
    public function testEditError()
71
    {
72
        $client = static::createClient();
73
        $crawler = $client->request('GET', '/articles/');
74
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link());
75
        $form = $crawler->filter('form button[type="submit"]')->form(array(
76
            'article[field_name]' => '',
77
            // ... use a required field here ...
78
        ));
79
        $crawler = $client->submit($form);
80
        $this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count());
81
    }
82
83
    /**
84
     * @depends testCreate
85
     */
86
    public function testDelete()
87
    {
88
        $client = static::createClient();
89
        $crawler = $client->request('GET', '/articles/');
90
        $this->assertTrue($client->getResponse()->isSuccessful());
91
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr'));
92
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(0)->link());
93
        $client->submit($crawler->filter('form#delete button[type="submit"]')->form());
94
        $crawler = $client->followRedirect();
95
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr'));
96
    }    /**
97
     * @depends testCreate
98
     */
99
    public function testSort()
100
    {
101
        $client = static::createClient();
102
        $crawler = $client->request('GET', '/articles/');
103
        $this->assertCount(1, $crawler->filter('table.records_list th')->eq(0)->filter('a i.fa-sort'));
104
        $crawler = $client->click($crawler->filter('table.records_list th a')->link());
1 ignored issue
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...
105
        $crawler = $client->followRedirect();
106
        $this->assertTrue($client->getResponse()->isSuccessful());
107
        $this->assertCount(1, $crawler->filter('table.records_list th a i.fa-sort-up'));
108
    }
109
}
110