Completed
Push — master ( 376ce2...d23e95 )
by Laurent
04:08
created

ArticleControllerTest::testCreate()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 24
rs 8.9713
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
namespace AppBundle\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
use AppBundle\Entity\Article;
7
8
class ArticleControllerTest extends WebTestCase
9
{
10
    public function testIndex() {
11
        $client = static::createClient();
12
        $crawler = $client->request('GET', '/article/');
13
        
14
        $this->assertCount(
15
            Article::NUM_ITEMS,
16
            $crawler->filter('article.name'),
17
            'Le message montre le bon nombre d\'articles.'
18
        );
19
    }
20
21
    public function testCreate()
22
    {
23
        $client = static::createClient();
24
        $crawler = $client->request('GET', '/article');
25
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr'));
26
        $form = $crawler->filter('form button[type="submit"]')->form(array(
27
            'article[name]' => 'Lorem ipsum dolor sit amet',
28
            'article[supplier]' => 1,
29
            'article[familyLog]' => 1,
30
            'article[zoneStorages]' => 1,
31
            'article[unitStorage]' => 1,
32
            'article[packaging]' => 10.99,
33
            'article[price]' => 10.99,
34
            'article[minstock]' => 10.99,
35
            'article[quantity]' => 0,
36
            'article[active]' => true,
37
            'article[slug]' => 'lorem-ipsum-dolor-sit-amet',
38
            )
39
        );
40
        $client->submit($form);
41
//        $crawler = $client->followRedirect();
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42
//        $crawler = $client->click($crawler->filter('.record_actions button')->link());
43
//        $this->assertCount(1, $crawler->filter('table.records_list tbody tr'));
44
    }
45
46
    public function testCreateError()
47
    {
48
        $client = static::createClient();
49
        $crawler = $client->request('GET', '/article/admin/new');
50
        $form = $crawler->filter('form button[name="article[save]"]')->form();
51
        $crawler = $client->submit($form);
52
        $this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count());
53
        $this->assertTrue($client->getResponse()->isSuccessful());
54
    }
55
56
    /**
57
     * @depends testCreate
58
     */
59
    public function testEdit()
60
    {
61
        $client = static::createClient();
62
        $crawler = $client->request('GET', '/article/');
63
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("First value")'));
64
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("Changed")'));
65
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link());
66
        $form = $crawler->filter('form button[type="submit"]')->form(array(
67
            'article[name]' => 'Changed',
68
            'article[packaging]' => 10.99,
69
            'article[price]' => 10.99,
70
            'article[quantity]' => 10.99,
71
            'article[minstock]' => 10.99,
72
            'article[active]' => true,
73
            'article[slug]' => 'Changed',
74
            // ... adapt fields value here ...
75
        ));
76
        $client->submit($form);
77
        $crawler = $client->followRedirect();
78
        $crawler = $client->click($crawler->filter('.record_actions a')->link());
79
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("First value")'));
80
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("Changed")'));
81
    }
82
83
    /**
84
     * @depends testCreate
85
     */
86
    public function testEditError()
87
    {
88
        $client = static::createClient();
89
        $crawler = $client->request('GET', '/article/');
90
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link());
91
        $form = $crawler->filter('form button[type="submit"]')->form(array(
92
            'article[name]' => '',
93
            // ... use a required field here ...
94
        ));
95
        $crawler = $client->submit($form);
96
        $this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count());
97
    }
98
99
    /**
100
     * @depends testCreate
101
     */
102
    public function testDelete()
103
    {
104
        $client = static::createClient();
105
        $crawler = $client->request('GET', '/article/');
106
        $this->assertTrue($client->getResponse()->isSuccessful());
107
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr'));
108
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(0)->link());
109
        $client->submit($crawler->filter('form#delete button[type="submit"]')->form());
110
        $crawler = $client->followRedirect();
111
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr'));
112
    }    /**
113
     * @depends testCreate
114
     */
115
    public function testSort()
116
    {
117
        $client = static::createClient();
118
        $crawler = $client->request('GET', '/article/');
119
        $this->assertCount(1, $crawler->filter('table.records_list th')->eq(0)->filter('a i.fa-sort'));
120
        $crawler = $client->click($crawler->filter('table.records_list th a')->link());
121
        $crawler = $client->followRedirect();
122
        $this->assertTrue($client->getResponse()->isSuccessful());
123
        $this->assertCount(1, $crawler->filter('table.records_list th a i.fa-sort-up'));
124
    }
125
}
126