Skip to content
This repository has been archived by the owner on Apr 7, 2018. It is now read-only.

Commit

Permalink
Implement tests (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjoosten authored Mar 27, 2018
1 parent 549b8a4 commit 97a2245
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 25 deletions.
10 changes: 5 additions & 5 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
60 changes: 60 additions & 0 deletions tests/CreatesUsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Tests;

use ActivismeBe\User;
use Spatie\Permission\Models\Role;

/**
* Helper traits for creating logins
*
* @author Tim Joosten <[email protected]>
* @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);
}
}
43 changes: 43 additions & 0 deletions tests/Feature/Backend/HomeRouteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Tests\Feature\Backend;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

/**
* Class HomeRouteTest
*
* @author Tim Joosten <[email protected]>
* @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);
}
}
19 changes: 0 additions & 19 deletions tests/Feature/ExampleTest.php

This file was deleted.

26 changes: 26 additions & 0 deletions tests/Feature/Frontend/CalendarTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\Feature\Frontend;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

/**
* Class CalendarTest
*
* @author Tim Joosten <[email protected]>
* @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);
}
}
26 changes: 26 additions & 0 deletions tests/Feature/Frontend/DisclaimerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\Feature\Frontend;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

/**
* Class DisclaimerTest
*
* @author Tim Joosten <[email protected]>
* @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);
}
}
26 changes: 26 additions & 0 deletions tests/Feature/Frontend/HomeRouteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\Feature\Frontend;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

/**
* Class HomeRouteTest
*
* @author Tim Joosten <[email protected]>
* @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);
}
}
26 changes: 26 additions & 0 deletions tests/Feature/Frontend/VisionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\Feature\Frontend;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

/**
* Class VisionTest
*
* @author Tim Joosten <[email protected]>
* @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);
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use CreatesApplication, CreatesUsers;
}

0 comments on commit 97a2245

Please sign in to comment.