From 97a2245d22ba09b29f4f7fccb7ef9602003c092c Mon Sep 17 00:00:00 2001 From: Tim Joosten Date: Tue, 27 Mar 2018 21:41:51 +0200 Subject: [PATCH] Implement tests (#111) --- routes/web.php | 10 ++-- tests/CreatesUsers.php | 60 +++++++++++++++++++++++ tests/Feature/Backend/HomeRouteTest.php | 43 ++++++++++++++++ tests/Feature/ExampleTest.php | 19 ------- tests/Feature/Frontend/CalendarTest.php | 26 ++++++++++ tests/Feature/Frontend/DisclaimerTest.php | 26 ++++++++++ tests/Feature/Frontend/HomeRouteTest.php | 26 ++++++++++ tests/Feature/Frontend/VisionTest.php | 26 ++++++++++ tests/TestCase.php | 2 +- 9 files changed, 213 insertions(+), 25 deletions(-) create mode 100644 tests/CreatesUsers.php create mode 100644 tests/Feature/Backend/HomeRouteTest.php delete mode 100755 tests/Feature/ExampleTest.php create mode 100644 tests/Feature/Frontend/CalendarTest.php create mode 100644 tests/Feature/Frontend/DisclaimerTest.php create mode 100644 tests/Feature/Frontend/HomeRouteTest.php create mode 100644 tests/Feature/Frontend/VisionTest.php diff --git a/routes/web.php b/routes/web.php index fe80479..1c857a0 100755 --- a/routes/web.php +++ b/routes/web.php @@ -24,8 +24,8 @@ /** TESTING needed */ Route::patch('/admin/account/instellingen/beveiliging', 'Auth\AccountSettingsController@updateSecurity')->name('account.settings.security'); // Home routes -/** TESTING needed */ Route::get('/', 'Frontend\HomeController@index')->name('home.front'); -/** TESTING needed */ Route::get('/admin/home', 'HomeController@index')->name('home'); +Route::get('/', 'Frontend\HomeController@index')->name('home.front'); +Route::get('/admin/home', 'HomeController@index')->name('home'); // Address book routes /** TESTING needed */ Route::get('/admin/contacten', 'Backend\ContactsController@index')->name('admin.contacts.index'); @@ -36,8 +36,8 @@ /** TESTING needed */ Route::post('/admin/contacten/opslaan', 'Backend\ContactsController@store')->name('admin.contacts.store'); // Frontend -/** TESTING needed */ Route::get('/disclaimer', 'DisclaimerController@index')->name('disclaimer.index'); -/** TESTING needed */ Route::get('/visie', 'Frontend\VisieController@index')->name('visie.index'); +Route::get('/disclaimer', 'DisclaimerController@index')->name('disclaimer.index'); +Route::get('/visie', 'Frontend\VisieController@index')->name('visie.index'); // Logs routes /** TESTING needed */ Route::get('/admin/logs', 'LogsController@index')->name('admin.logs.index'); @@ -105,7 +105,7 @@ /** TESTING needed */ Route::get('admin/article/status/{article}/{status}', 'Backend\ArticleStatusController@update')->name('admin.status.change'); // Calendar routes -/** TESTING needed */ Route::get('/kalender', 'Frontend\CalendarController@index')->name('calendar.index'); +Route::get('/kalender', 'Frontend\CalendarController@index')->name('calendar.index'); /** TESTING needed */ Route::get('/admin/kalender/status/{event}/{status}', 'Backend\CalendarController@status')->name('admin.calendar.status'); /** TESTING needed */ Route::get('/admin/kalender', 'Backend\CalendarController@index')->name('admin.calendar.index'); diff --git a/tests/CreatesUsers.php b/tests/CreatesUsers.php new file mode 100644 index 0000000..fed4f22 --- /dev/null +++ b/tests/CreatesUsers.php @@ -0,0 +1,60 @@ + + * @copyright 2018 Tim Joosten and his contributors + * @package Tests\Traits + */ +trait CreatesUsers +{ + /** + * Function for creating a newly role in the testing db. + * + * @param string $name The name for the role that has to be created. + * @return string + */ + protected function createRole(string $name): string + { + return factory(Role::class)->create(['name' => $name])->name; + } + + /** + * Create an normal user in the system + * + * @return \ActivismeBe\User + */ + public function createNormalUser(): User + { + return factory(User::class)->create() + ->assignRole($this->createRole('user')); + } + + /** + * Create an admin user in the system + * + * @return \ActivismeBe\User + */ + public function createAdminUser(): User + { + return factory(User::class)->create() + ->assignRole($this->createRole('admin')); + } + + /** + * Create an blocked user in the system. + * + * @return \ActivismeBe\User + */ + public function createBlockedUser(): User + { + $user = factory(User::class)->create()->ban(); + return User::find($user->id); + } +} \ No newline at end of file diff --git a/tests/Feature/Backend/HomeRouteTest.php b/tests/Feature/Backend/HomeRouteTest.php new file mode 100644 index 0000000..b798216 --- /dev/null +++ b/tests/Feature/Backend/HomeRouteTest.php @@ -0,0 +1,43 @@ + + * @copyright 2018 Tim Joosten + * @package Tests\Feature\Backend + */ +class HomeRouteTest extends TestCase +{ + use RefreshDatabase; + + /** + * @test + * @testdox Test if an unauthenticated user can't access the home index page. + */ + public function unAuthenticated(): void + { + $this->get(route('home')) + ->assertStatus(302) + ->assertRedirect(route('login')); + } + + /** + * @test + * @testdox Test if a authenticated user can view the home index page. + */ + public function authenticated(): void + { + $user = $this->createNormalUser(); + + $this->actingAs($user) + ->get(route('home')) + ->assertStatus(200); + } +} diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100755 index f3c9b83..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue(true); - } -} diff --git a/tests/Feature/Frontend/CalendarTest.php b/tests/Feature/Frontend/CalendarTest.php new file mode 100644 index 0000000..eb303a9 --- /dev/null +++ b/tests/Feature/Frontend/CalendarTest.php @@ -0,0 +1,26 @@ + + * @copyright 2018 Tim Joosten + * @package Tests\Feature\Frontend + */ +class CalendarTest extends TestCase +{ + /** + * @test + * @testdox Test if the calendar index page is accessible + */ + public function IndexPage(): void + { + $this->get(route('calendar.index'))->assertStatus(200); + } +} diff --git a/tests/Feature/Frontend/DisclaimerTest.php b/tests/Feature/Frontend/DisclaimerTest.php new file mode 100644 index 0000000..3ae1620 --- /dev/null +++ b/tests/Feature/Frontend/DisclaimerTest.php @@ -0,0 +1,26 @@ + + * @copyright 2018 Tim Joosten + * @package Tests\Feature\Frontend + */ +class DisclaimerTest extends TestCase +{ + /** + * @test + * @testdox Test is a quest can view the disclaimer page without errors + */ + public function indexTest(): void + { + $this->get(route('disclaimer.index'))->assertStatus(200); + } +} diff --git a/tests/Feature/Frontend/HomeRouteTest.php b/tests/Feature/Frontend/HomeRouteTest.php new file mode 100644 index 0000000..276a7eb --- /dev/null +++ b/tests/Feature/Frontend/HomeRouteTest.php @@ -0,0 +1,26 @@ + + * @copyright 2018 Tim Joosten + * @package Tests\Feature\Frontend + */ +class HomeRouteTest extends TestCase +{ + /** + * @test + * @testdox Test if the application index page is accesable. + */ + public function HomeView(): void + { + $this->get(route('home.front'))->assertStatus(200); + } +} diff --git a/tests/Feature/Frontend/VisionTest.php b/tests/Feature/Frontend/VisionTest.php new file mode 100644 index 0000000..6a97746 --- /dev/null +++ b/tests/Feature/Frontend/VisionTest.php @@ -0,0 +1,26 @@ + + * @copyright 2018 Tim Joosten + * @package Tests\Feature\Frontend + */ +class VisionTest extends TestCase +{ + /** + * @test + * @testdox Test if the quest can view the vision page without errors + */ + public function visionIndex() + { + $this->get(route('visie.index'))->assertStatus(200); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 2932d4a..0060b01 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,5 +6,5 @@ abstract class TestCase extends BaseTestCase { - use CreatesApplication; + use CreatesApplication, CreatesUsers; }