|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Tests\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
6
|
|
|
|
|
7
|
|
View Code Duplication |
class ZoneStorageControllerTest extends WebTestCase |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
public function testCreate() |
|
10
|
|
|
{ |
|
11
|
|
|
$client = static::createClient(); |
|
12
|
|
|
$crawler = $client->request('GET', '/admin/settings/divers/zonestorage/'); |
|
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
|
|
|
'zonestorage[name]' => 'Lorem ipsum dolor sit amet', |
|
17
|
|
|
)); |
|
18
|
|
|
$client->submit($form); |
|
19
|
|
|
$crawler = $client->followRedirect(); |
|
20
|
|
|
$crawler = $client->click($crawler->filter('.record_actions a')->link()); |
|
21
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr')); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testCreateError() |
|
25
|
|
|
{ |
|
26
|
|
|
$client = static::createClient(); |
|
27
|
|
|
$crawler = $client->request('GET', '/admin/settings/divers/zonestorage/new'); |
|
28
|
|
|
$form = $crawler->filter('form button[type="submit"]')->form(); |
|
29
|
|
|
$crawler = $client->submit($form); |
|
30
|
|
|
$this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count()); |
|
31
|
|
|
$this->assertTrue($client->getResponse()->isSuccessful()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @depends testCreate |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testEdit() |
|
38
|
|
|
{ |
|
39
|
|
|
$client = static::createClient(); |
|
40
|
|
|
$crawler = $client->request('GET', '/admin/settings/divers/zonestorage/'); |
|
41
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("First value")')); |
|
42
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("Changed")')); |
|
43
|
|
|
$crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link()); |
|
44
|
|
|
$form = $crawler->filter('form button[type="submit"]')->form(array( |
|
45
|
|
|
'zonestorage[name]' => 'Changed', |
|
46
|
|
|
// ... adapt fields value here ... |
|
47
|
|
|
)); |
|
48
|
|
|
$client->submit($form); |
|
49
|
|
|
$crawler = $client->followRedirect(); |
|
50
|
|
|
$crawler = $client->click($crawler->filter('.record_actions a')->link()); |
|
51
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("First value")')); |
|
52
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("Changed")')); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @depends testCreate |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testEditError() |
|
59
|
|
|
{ |
|
60
|
|
|
$client = static::createClient(); |
|
61
|
|
|
$crawler = $client->request('GET', '/admin/settings/divers/zonestorage/'); |
|
62
|
|
|
$crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link()); |
|
63
|
|
|
$form = $crawler->filter('form button[type="submit"]')->form(array( |
|
64
|
|
|
'zonestorage[field_name]' => '', |
|
65
|
|
|
// ... use a required field here ... |
|
66
|
|
|
)); |
|
67
|
|
|
$crawler = $client->submit($form); |
|
68
|
|
|
$this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @depends testCreate |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testDelete() |
|
75
|
|
|
{ |
|
76
|
|
|
$client = static::createClient(); |
|
77
|
|
|
$crawler = $client->request('GET', '/admin/settings/divers/zonestorage/'); |
|
78
|
|
|
$this->assertTrue($client->getResponse()->isSuccessful()); |
|
79
|
|
|
$this->assertCount(1, $crawler->filter('table.records_list tbody tr')); |
|
80
|
|
|
$crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(0)->link()); |
|
81
|
|
|
$client->submit($crawler->filter('form#delete button[type="submit"]')->form()); |
|
82
|
|
|
$crawler = $client->followRedirect(); |
|
83
|
|
|
$this->assertCount(0, $crawler->filter('table.records_list tbody tr')); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.