|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Tests\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
6
|
|
|
|
|
7
|
|
|
class DefaultControllerTest extends WebTestCase |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* PHPUnit's data providers allow to execute the same tests repeated times |
|
11
|
|
|
* using a different set of data each time. |
|
12
|
|
|
* See http://symfony.com/doc/current/cookbook/form/unit_testing.html#testing-against-different-sets-of-data. |
|
13
|
|
|
* |
|
14
|
|
|
* @dataProvider getPublicUrls |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testPublicUrls($url) |
|
17
|
|
|
{ |
|
18
|
|
|
$client = self::createClient(); |
|
19
|
|
|
$client->request('GET', $url); |
|
20
|
|
|
$this->assertTrue( |
|
21
|
|
|
$client->getResponse()->isSuccessful(), |
|
22
|
|
|
sprintf('The "%s" public URL loads correctly.', $url) |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The application contains a lot of secure URLs which shouldn't be |
|
28
|
|
|
* publicly accessible. This tests ensures that whenever a user tries to |
|
29
|
|
|
* access one of those pages, a redirection to the login form is performed. |
|
30
|
|
|
* |
|
31
|
|
|
* @dataProvider getSecureUrls |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testSecureUrls($url) |
|
34
|
|
|
{ |
|
35
|
|
|
$client = self::createClient(); |
|
36
|
|
|
$client->request('GET', $url); |
|
37
|
|
|
$this->assertTrue($client->getResponse()->isRedirect()); |
|
38
|
|
|
$this->assertEquals( |
|
39
|
|
|
'http://localhost/login', |
|
40
|
|
|
$client->getResponse()->getTargetUrl(), |
|
41
|
|
|
sprintf('The "%s" secure URL redirects to the login form.', $url) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function getPublicUrls() |
|
46
|
|
|
{ |
|
47
|
|
|
return array( |
|
48
|
|
|
array('/'), |
|
49
|
|
|
array('/article/'), |
|
50
|
|
|
array('/supplier/'), |
|
51
|
|
|
array('/inventory/'), |
|
52
|
|
|
array('/login'), |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getSecureUrls() |
|
57
|
|
|
{ |
|
58
|
|
|
return array( |
|
59
|
|
|
array('/admin/user/'), |
|
60
|
|
|
array('/admin/group/'), |
|
61
|
|
|
array('/admin/settings/company/'), |
|
62
|
|
|
array('/admin/settings/application/'), |
|
63
|
|
|
array('/admin/settings/divers/familylog/'), |
|
64
|
|
|
array('/admin/settings/divers/zonestorage/'), |
|
65
|
|
|
array('/admin/settings/divers/unitstorage/'), |
|
66
|
|
|
array('/admin/settings/divers/tva/'), |
|
67
|
|
|
array('/article/admin/new'), |
|
68
|
|
|
array('/supplier/admin/new'), |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testIndex() { |
|
73
|
|
|
$client = static::createClient(); |
|
74
|
|
|
|
|
75
|
|
|
$crawler = $client->request('GET', '/'); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
78
|
|
|
$this->assertContains('Accueil', $crawler->filter('.container .row #content h2')->text()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|