|
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 testIndex() { |
|
10
|
|
|
$client = self::createClient( |
|
11
|
|
|
array(), |
|
12
|
|
|
array( |
|
13
|
|
|
'HTTP_HOST' => 'symfony2.local', |
|
14
|
|
|
) |
|
15
|
|
|
); |
|
16
|
|
|
|
|
17
|
|
|
$crawler = $client->request('GET', '/article'); |
|
18
|
|
|
var_dump($crawler); |
|
|
|
|
|
|
19
|
|
|
$this->assertEquals(1, $crawler->filter('h2:contains("Articles - Liste")')->count()); |
|
20
|
|
|
|
|
21
|
|
|
// $this->assertContains('Articles - Liste', $crawler->filter('.container .row #content h2')->text()); |
|
|
|
|
|
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
public function testCreate() |
|
26
|
|
|
{ |
|
27
|
|
|
$client = static::createClient(); |
|
28
|
|
|
$crawler = $client->request('GET', '/article'); |
|
29
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr')); |
|
30
|
|
|
$form = $crawler->filter('form button[type="submit"]')->form(array( |
|
31
|
|
|
'article[name]' => 'Lorem ipsum dolor sit amet', |
|
32
|
|
|
'article[supplier]' => 1, |
|
33
|
|
|
'article[familyLog]' => 1, |
|
34
|
|
|
'article[zoneStorages]' => 1, |
|
35
|
|
|
'article[unitStorage]' => 1, |
|
36
|
|
|
'article[packaging]' => 10.99, |
|
37
|
|
|
'article[price]' => 10.99, |
|
38
|
|
|
'article[minstock]' => 10.99, |
|
39
|
|
|
'article[quantity]' => 0, |
|
40
|
|
|
'article[active]' => true, |
|
41
|
|
|
'article[slug]' => 'lorem-ipsum-dolor-sit-amet', |
|
42
|
|
|
) |
|
43
|
|
|
); |
|
44
|
|
|
$client->submit($form); |
|
45
|
|
|
$crawler = $client->followRedirect(); |
|
46
|
|
|
$crawler = $client->click($crawler->filter('.record_actions button')->link()); |
|
47
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr')); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testCreateError() |
|
51
|
|
|
{ |
|
52
|
|
|
$client = static::createClient(); |
|
53
|
|
|
$crawler = $client->request('GET', '/article/admin/new'); |
|
54
|
|
|
$form = $crawler->filter('form button[name="article[save]"]')->form(); |
|
55
|
|
|
$crawler = $client->submit($form); |
|
56
|
|
|
$this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count()); |
|
57
|
|
|
$this->assertTrue($client->getResponse()->isSuccessful()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @depends testCreate |
|
62
|
|
|
* |
|
63
|
|
|
public function testEdit() |
|
64
|
|
|
{ |
|
65
|
|
|
$client = static::createClient(); |
|
66
|
|
|
$crawler = $client->request('GET', '/article/'); |
|
67
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("First value")')); |
|
68
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("Changed")')); |
|
69
|
|
|
$crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link()); |
|
70
|
|
|
$form = $crawler->filter('form button[type="submit"]')->form(array( |
|
71
|
|
|
'article[name]' => 'Changed', |
|
72
|
|
|
'article[packaging]' => 10.99, |
|
73
|
|
|
'article[price]' => 10.99, |
|
74
|
|
|
'article[quantity]' => 10.99, |
|
75
|
|
|
'article[minstock]' => 10.99, |
|
76
|
|
|
'article[active]' => true, |
|
77
|
|
|
'article[slug]' => 'Changed', |
|
78
|
|
|
// ... adapt fields value here ... |
|
79
|
|
|
)); |
|
80
|
|
|
$client->submit($form); |
|
81
|
|
|
$crawler = $client->followRedirect(); |
|
82
|
|
|
$crawler = $client->click($crawler->filter('.record_actions a')->link()); |
|
83
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("First value")')); |
|
84
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("Changed")')); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @depends testCreate |
|
89
|
|
|
* |
|
90
|
|
|
public function testEditError() |
|
91
|
|
|
{ |
|
92
|
|
|
$client = static::createClient(); |
|
93
|
|
|
$crawler = $client->request('GET', '/article/'); |
|
94
|
|
|
$crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link()); |
|
95
|
|
|
$form = $crawler->filter('form button[type="submit"]')->form(array( |
|
96
|
|
|
'article[name]' => '', |
|
97
|
|
|
// ... use a required field here ... |
|
98
|
|
|
)); |
|
99
|
|
|
$crawler = $client->submit($form); |
|
100
|
|
|
$this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count()); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @depends testCreate |
|
105
|
|
|
* |
|
106
|
|
|
public function testDelete() |
|
107
|
|
|
{ |
|
108
|
|
|
$client = static::createClient(); |
|
109
|
|
|
$crawler = $client->request('GET', '/article/'); |
|
110
|
|
|
$this->assertTrue($client->getResponse()->isSuccessful()); |
|
111
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr')); |
|
112
|
|
|
$crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(0)->link()); |
|
113
|
|
|
$client->submit($crawler->filter('form#delete button[type="submit"]')->form()); |
|
114
|
|
|
$crawler = $client->followRedirect(); |
|
115
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr')); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @depends testCreate |
|
120
|
|
|
* |
|
121
|
|
|
public function testSort() |
|
122
|
|
|
{ |
|
123
|
|
|
$client = static::createClient(); |
|
124
|
|
|
$crawler = $client->request('GET', '/article/'); |
|
125
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list th')->eq(0)->filter('a i.fa-sort')); |
|
126
|
|
|
$crawler = $client->click($crawler->filter('table.records_list th a')->link()); |
|
127
|
|
|
$crawler = $client->followRedirect(); |
|
128
|
|
|
$this->assertTrue($client->getResponse()->isSuccessful()); |
|
129
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list th a i.fa-sort-up')); |
|
130
|
|
|
}*/ |
|
131
|
|
|
} |
|
132
|
|
|
|