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