Skip to content
This repository has been archived by the owner on Nov 27, 2021. It is now read-only.

Commit

Permalink
Prepare tests for authentication. See #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdok committed Apr 1, 2016
1 parent 1017304 commit b9ad104
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 41 deletions.
32 changes: 4 additions & 28 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Support\Facades\Validator;

/**
* Class AuthController.
Expand Down Expand Up @@ -37,41 +35,19 @@ class AuthController extends Controller

/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}

/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
}

/**
* Create a new user instance after a valid registration.
* Get the login page view.
*
* @param array $data
* @return User
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
protected function create(array $data)
public function getLogin()
{
return User::create([
'name' => $data[ 'name' ],
'email' => $data[ 'email' ],
'password' => bcrypt($data[ 'password' ]),
]);
return view('auth.login');
}
}
13 changes: 13 additions & 0 deletions app/Http/Controllers/ExceptionsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests;

class ExceptionsController extends Controller
{
public function notFound()
{
return 404;
}
}
4 changes: 4 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
});

Route::group(['middleware' => ['web']], function () {
Route::get('auth/login', ['as' => 'auth.login', 'uses' => 'Auth\AuthController@getLogin']);
});

Route::group(['middleware' => ['api'], 'prefix' => 'api'], function () {
Route::any('{any}', ['as' => 'api.exception.not_found', 'uses' => 'Api\ExceptionsController@notFound'])
->where('any', '(.*)?');
});

Route::any('{any}', ['as' => 'exception.not_found', 'uses' => 'ExceptionsController@notFound'])
->where('any', '(.*)?');
13 changes: 1 addition & 12 deletions database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<?php

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/

use App\User;

$factory->define(User::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'email' => $faker->safeEmail,
'email' => $faker->unique()->email,
'remember_token' => str_random(10),
];
});
Empty file.
19 changes: 18 additions & 1 deletion tests/functional/api/tutor/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,32 @@
*/
namespace Tests\functional\api\tutor;

use App\Sass\Repositories\User\DbUserRepository;
use App\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

/**
* Class AuthenticationTest.
*/
class AuthenticationTest extends TestCase
{
use DatabaseMigrations;

/** @test */
public function it_requests_browser_login_button()
public function it_initializes_login_process()
{
$userRepository = new DbUserRepository();
$tutor = factory(User::class)->create();
$userRepository->assignTutorRole($tutor);

$this->actingAs($tutor)
->visit(route('auth.login'))
->seePageIs(route('auth.login'))
->see('<title>Login &middot; SASS')
->type($tutor->email, 'email')
->press('Login')
->seePageIs(route('auth.login.pin'))
->see('If that email exists, we will send you an email with a one time password, expiring in 5 minutes.');
}
}

0 comments on commit b9ad104

Please sign in to comment.