15
15
use AppBundle \Entity \Post ;
16
16
use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
17
17
use Symfony \Component \HttpFoundation \Response ;
18
- use Tests \ControllerTestTrait ;
19
18
20
19
/**
21
20
* Functional test for the controllers defined inside the BlogController used
34
33
*/
35
34
class BlogControllerTest extends WebTestCase
36
35
{
37
- use ControllerTestTrait;
38
36
use FixturesTrait;
39
37
40
38
/**
41
39
* @dataProvider getUrlsForRegularUsers
42
40
*/
43
41
public function testAccessDeniedForRegularUsers ($ httpMethod , $ url )
44
42
{
45
- $ client = $ this ->getUserClient ();
43
+ $ client = static ::createClient ([], [
44
+ 'PHP_AUTH_USER ' => 'john_user ' ,
45
+ 'PHP_AUTH_PW ' => 'kitten ' ,
46
+ ]);
46
47
47
48
$ client ->request ($ httpMethod , $ url );
48
49
$ this ->assertSame (Response::HTTP_FORBIDDEN , $ client ->getResponse ()->getStatusCode ());
@@ -58,7 +59,10 @@ public function getUrlsForRegularUsers()
58
59
59
60
public function testAdminBackendHomePage ()
60
61
{
61
- $ client = $ this ->getAdminClient ();
62
+ $ client = static ::createClient ([], [
63
+ 'PHP_AUTH_USER ' => 'jane_admin ' ,
64
+ 'PHP_AUTH_PW ' => 'kitten ' ,
65
+ ]);
62
66
63
67
$ crawler = $ client ->request ('GET ' , '/en/admin/post/ ' );
64
68
$ this ->assertSame (Response::HTTP_OK , $ client ->getResponse ()->getStatusCode ());
@@ -82,7 +86,10 @@ public function testAdminNewPost()
82
86
$ postSummary = $ this ->getRandomPostSummary ();
83
87
$ postContent = $ this ->getPostContent ();
84
88
85
- $ client = $ this ->getAdminClient ();
89
+ $ client = static ::createClient ([], [
90
+ 'PHP_AUTH_USER ' => 'jane_admin ' ,
91
+ 'PHP_AUTH_PW ' => 'kitten ' ,
92
+ ]);
86
93
$ crawler = $ client ->request ('GET ' , '/en/admin/post/new ' );
87
94
$ form = $ crawler ->selectButton ('Create post ' )->form ([
88
95
'post[title] ' => $ postTitle ,
@@ -103,7 +110,10 @@ public function testAdminNewPost()
103
110
104
111
public function testAdminShowPost ()
105
112
{
106
- $ client = $ this ->getAdminClient ();
113
+ $ client = static ::createClient ([], [
114
+ 'PHP_AUTH_USER ' => 'jane_admin ' ,
115
+ 'PHP_AUTH_PW ' => 'kitten ' ,
116
+ ]);
107
117
$ client ->request ('GET ' , '/en/admin/post/1 ' );
108
118
109
119
$ this ->assertSame (Response::HTTP_OK , $ client ->getResponse ()->getStatusCode ());
@@ -119,7 +129,10 @@ public function testAdminEditPost()
119
129
{
120
130
$ newBlogPostTitle = 'Blog Post Title ' .mt_rand ();
121
131
122
- $ client = $ this ->getAdminClient ();
132
+ $ client = static ::createClient ([], [
133
+ 'PHP_AUTH_USER ' => 'jane_admin ' ,
134
+ 'PHP_AUTH_PW ' => 'kitten ' ,
135
+ ]);
123
136
$ crawler = $ client ->request ('GET ' , '/en/admin/post/1/edit ' );
124
137
$ form = $ crawler ->selectButton ('Save changes ' )->form ([
125
138
'post[title] ' => $ newBlogPostTitle ,
@@ -141,7 +154,10 @@ public function testAdminEditPost()
141
154
*/
142
155
public function testAdminDeletePost ()
143
156
{
144
- $ client = $ this ->getAdminClient ();
157
+ $ client = static ::createClient ([], [
158
+ 'PHP_AUTH_USER ' => 'jane_admin ' ,
159
+ 'PHP_AUTH_PW ' => 'kitten ' ,
160
+ ]);
145
161
$ crawler = $ client ->request ('GET ' , '/en/admin/post/1 ' );
146
162
$ client ->submit ($ crawler ->filter ('#delete-form ' )->form ());
147
163
0 commit comments