1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Tests\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
6
|
|
|
|
7
|
|
|
class GroupControllerTest extends WebTestCase { |
8
|
|
|
|
9
|
|
|
public function testCreate() { |
10
|
|
|
$client = static::createClient(); |
11
|
|
|
$crawler = $client->request('GET', '/admin/groups/'); |
12
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr')); |
13
|
|
|
$crawler = $client->click($crawler->filter('.new_entry a')->link()); |
14
|
|
|
$form = $crawler->filter('form button[type="submit"]')->form(array( |
15
|
|
|
)); |
16
|
|
|
$client->submit($form); |
17
|
|
|
$crawler = $client->followRedirect(); |
18
|
|
|
$crawler = $client->click($crawler->filter('.record_actions a')->link()); |
19
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr')); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testCreateError() { |
23
|
|
|
$client = static::createClient(); |
24
|
|
|
$crawler = $client->request('GET', '/admin/groups/new'); |
25
|
|
|
$form = $crawler->filter('form button[type="submit"]')->form(); |
26
|
|
|
$crawler = $client->submit($form); |
27
|
|
|
$this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count()); |
28
|
|
|
$this->assertTrue($client->getResponse()->isSuccessful()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @depends testCreate |
33
|
|
|
*/ |
34
|
|
|
public function testEdit() { |
35
|
|
|
$client = static::createClient(); |
36
|
|
|
$crawler = $client->request('GET', '/admin/groups/'); |
37
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("First value")')); |
38
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("Changed")')); |
39
|
|
|
$crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link()); |
40
|
|
|
$form = $crawler->filter('form button[type="submit"]')->form(array( |
41
|
|
|
// ... adapt fields value here ... |
42
|
|
|
)); |
43
|
|
|
$client->submit($form); |
44
|
|
|
$crawler = $client->followRedirect(); |
45
|
|
|
$crawler = $client->click($crawler->filter('.record_actions a')->link()); |
46
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("First value")')); |
47
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("Changed")')); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @depends testCreate |
52
|
|
|
*/ |
53
|
|
|
public function testEditError() { |
54
|
|
|
$client = static::createClient(); |
55
|
|
|
$crawler = $client->request('GET', '/admin/groups/'); |
56
|
|
|
$crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link()); |
57
|
|
|
$form = $crawler->filter('form button[type="submit"]')->form(array( |
58
|
|
|
'group[field_name]' => '', |
59
|
|
|
// ... use a required field here ... |
60
|
|
|
)); |
61
|
|
|
$crawler = $client->submit($form); |
62
|
|
|
$this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @depends testCreate |
67
|
|
|
*/ |
68
|
|
|
public function testDelete() { |
69
|
|
|
$client = static::createClient(); |
70
|
|
|
$crawler = $client->request('GET', '/admin/groups/'); |
71
|
|
|
$this->assertTrue($client->getResponse()->isSuccessful()); |
72
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr')); |
73
|
|
|
$crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(0)->link()); |
74
|
|
|
$client->submit($crawler->filter('form#delete button[type="submit"]')->form()); |
75
|
|
|
$crawler = $client->followRedirect(); |
76
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr')); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|