Skip to content

Commit e11a6e9

Browse files
committed
minor #444 Added more tests for the backend (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Added more tests for the backend This complements the new tests added in #434. Commits ------- 4cfce12 Added more tests for the backend
2 parents ae9381d + 4cfce12 commit e11a6e9

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

tests/AppBundle/Controller/Admin/BlogControllerTest.php

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,55 @@
2727
* Execute the application tests using this command (requires PHPUnit to be installed):
2828
*
2929
* $ cd your-symfony-project/
30-
* $ phpunit -c app
30+
* $ ./vendor/bin/phpunit
3131
*/
3232
class BlogControllerTest extends WebTestCase
3333
{
34-
public function testRegularUsersCannotAccessToTheBackend()
34+
/**
35+
* @dataProvider getUrlsForRegularUsers
36+
*/
37+
public function testRegularUsers($httpMethod, $url, $statusCode)
3538
{
3639
$client = static::createClient([], [
3740
'PHP_AUTH_USER' => 'john_user',
3841
'PHP_AUTH_PW' => 'kitten',
3942
]);
4043

41-
$client->request('GET', '/en/admin/post/');
44+
$client->request($httpMethod, $url);
45+
$this->assertEquals($statusCode, $client->getResponse()->getStatusCode());
46+
}
4247

43-
$this->assertEquals(Response::HTTP_FORBIDDEN, $client->getResponse()->getStatusCode());
48+
public function getUrlsForRegularUsers()
49+
{
50+
yield ['GET', '/en/admin/post/', Response::HTTP_FORBIDDEN];
51+
yield ['GET', '/en/admin/post/1', Response::HTTP_FORBIDDEN];
52+
yield ['GET', '/en/admin/post/1/edit', Response::HTTP_FORBIDDEN];
53+
yield ['POST', '/en/admin/post/1/delete', Response::HTTP_FORBIDDEN];
4454
}
4555

46-
public function testAdministratorUsersCanAccessToTheBackend()
56+
/**
57+
* @dataProvider getUrlsForAdminUsers
58+
*/
59+
public function testAdminUsers($httpMethod, $url, $statusCode)
4760
{
4861
$client = static::createClient([], [
4962
'PHP_AUTH_USER' => 'anna_admin',
5063
'PHP_AUTH_PW' => 'kitten',
5164
]);
5265

53-
$client->request('GET', '/en/admin/post/');
66+
$client->request($httpMethod, $url);
67+
$this->assertEquals($statusCode, $client->getResponse()->getStatusCode());
68+
}
5469

55-
$this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
70+
public function getUrlsForAdminUsers()
71+
{
72+
yield ['GET', '/en/admin/post/', Response::HTTP_OK];
73+
yield ['GET', '/en/admin/post/1', Response::HTTP_OK];
74+
yield ['GET', '/en/admin/post/1/edit', Response::HTTP_OK];
75+
yield ['POST', '/en/admin/post/1/delete', Response::HTTP_FOUND];
5676
}
5777

58-
public function testIndex()
78+
public function testBackendHomepage()
5979
{
6080
$client = static::createClient([], [
6181
'PHP_AUTH_USER' => 'anna_admin',
@@ -70,26 +90,4 @@ public function testIndex()
7090
'The backend homepage displays all the available posts.'
7191
);
7292
}
73-
74-
/**
75-
* @dataProvider getPostUrls
76-
*/
77-
public function testOnlyAuthorCanAccessToThePostInTheBackend($method, $url, $statusCode)
78-
{
79-
$client = static::createClient([], [
80-
'PHP_AUTH_USER' => 'anna_admin',
81-
'PHP_AUTH_PW' => 'kitten',
82-
]);
83-
84-
$client->request($method, $url);
85-
86-
$this->assertEquals($statusCode, $client->getResponse()->getStatusCode());
87-
}
88-
89-
public function getPostUrls()
90-
{
91-
yield ['GET', '/en/admin/post/1', Response::HTTP_OK];
92-
yield ['GET', '/en/admin/post/1/edit', Response::HTTP_OK];
93-
yield ['POST', '/en/admin/post/1/delete', Response::HTTP_FOUND];
94-
}
9593
}

tests/AppBundle/Controller/BlogControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Execute the application tests using this command (requires PHPUnit to be installed):
2323
*
2424
* $ cd your-symfony-project/
25-
* $ phpunit -c app
25+
* $ ./vendor/bin/phpunit
2626
*/
2727
class BlogControllerTest extends WebTestCase
2828
{

tests/AppBundle/Controller/DefaultControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Execute the application tests using this command (requires PHPUnit to be installed):
2222
*
2323
* $ cd your-symfony-project/
24-
* $ phpunit -c app
24+
* $ ./vendor/bin/phpunit
2525
*/
2626
class DefaultControllerTest extends WebTestCase
2727
{

tests/AppBundle/Utils/SluggerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Execute the application tests using this command (requires PHPUnit to be installed):
2222
*
2323
* $ cd your-symfony-project/
24-
* $ phpunit -c app
24+
* $ ./vendor/bin/phpunit
2525
*/
2626
class SluggerTest extends \PHPUnit_Framework_TestCase
2727
{

0 commit comments

Comments
 (0)