|
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()); |
|
|
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.