Merge pull request #113 from jonnybarnes/feature/admin-login
Protect admin routes with new eloquent sessions
This commit is contained in:
commit
0d2f38ceac
12 changed files with 194 additions and 108 deletions
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\View\View;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
|
||||||
|
@ -40,4 +39,31 @@ class AuthController extends Controller
|
||||||
|
|
||||||
return redirect()->route('login');
|
return redirect()->route('login');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form to logout a user.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function showLogout()
|
||||||
|
{
|
||||||
|
if (Auth::check() === false) {
|
||||||
|
// The user is not logged in, just redirect them home
|
||||||
|
return redirect('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('logout');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log the user out from their current session.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse;
|
||||||
|
*/
|
||||||
|
public function logout(): RedirectResponse
|
||||||
|
{
|
||||||
|
Auth::logout();
|
||||||
|
|
||||||
|
return redirect('/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class MyAuthMiddleware
|
class MyAuthMiddleware
|
||||||
{
|
{
|
||||||
|
@ -18,7 +19,7 @@ class MyAuthMiddleware
|
||||||
*/
|
*/
|
||||||
public function handle(Request $request, Closure $next)
|
public function handle(Request $request, Closure $next)
|
||||||
{
|
{
|
||||||
if ($request->session()->has('loggedin') !== true) {
|
if (Auth::check($request->user()) == false) {
|
||||||
//they’re not logged in, so send them to login form
|
//they’re not logged in, so send them to login form
|
||||||
return redirect()->route('login');
|
return redirect()->route('login');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Faker\Generator as Faker;
|
use Faker\Generator as Faker;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -12,12 +13,12 @@ use Faker\Generator as Faker;
|
||||||
| model instances for testing / seeding your application's database.
|
| model instances for testing / seeding your application's database.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
$factory->define(App\User::class, function (Faker $faker) {
|
$factory->define(App\Models\User::class, function (Faker $faker) {
|
||||||
static $password;
|
static $password;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'name' => $faker->name,
|
'name' => mb_strtolower($faker->firstName),
|
||||||
'email' => $faker->unique()->safeEmail,
|
|
||||||
'password' => $password ?: $password = bcrypt('secret'),
|
'password' => $password ?: $password = bcrypt('secret'),
|
||||||
'remember_token' => str_random(10),
|
'remember_token' => Str::random(10),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
10
resources/views/logout.blade.php
Normal file
10
resources/views/logout.blade.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
@extends('master')
|
||||||
|
@section('title')Logout @stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h2>Logout</h2>
|
||||||
|
<form action="logout" method="post">
|
||||||
|
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||||
|
<input type="submit" name="submit" value="Logout">
|
||||||
|
</form>
|
||||||
|
@stop
|
|
@ -14,17 +14,21 @@
|
||||||
Route::group(['domain' => config('url.longurl')], function () {
|
Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::get('/', 'NotesController@index');
|
Route::get('/', 'NotesController@index');
|
||||||
|
|
||||||
//Static project page
|
// Static project page
|
||||||
Route::view('projects', 'projects');
|
Route::view('projects', 'projects');
|
||||||
|
|
||||||
//Static colophon page
|
// Static colophon page
|
||||||
Route::view('colophon', 'colophon');
|
Route::view('colophon', 'colophon');
|
||||||
|
|
||||||
//The login routes to get authe'd for admin
|
// The login routes to get auth'd for admin
|
||||||
Route::get('login', 'AuthController@showLogin')->name('login');
|
Route::get('login', 'AuthController@showLogin')->name('login');
|
||||||
Route::post('login', 'AuthController@login');
|
Route::post('login', 'AuthController@login');
|
||||||
|
|
||||||
//Admin pages grouped for filter
|
// And the logout routes
|
||||||
|
Route::get('logout', 'AuthController@showLogout')->name('logout');
|
||||||
|
Route::post('logout', 'AuthController@logout');
|
||||||
|
|
||||||
|
// Admin pages grouped for filter
|
||||||
Route::group([
|
Route::group([
|
||||||
'middleware' => 'myauth',
|
'middleware' => 'myauth',
|
||||||
'namespace' => 'Admin',
|
'namespace' => 'Admin',
|
||||||
|
@ -42,7 +46,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::delete('/{id}', 'ArticlesController@destroy');
|
Route::delete('/{id}', 'ArticlesController@destroy');
|
||||||
});
|
});
|
||||||
|
|
||||||
//Notes
|
// Notes
|
||||||
Route::group(['prefix' => 'notes'], function () {
|
Route::group(['prefix' => 'notes'], function () {
|
||||||
Route::get('/', 'NotesController@index');
|
Route::get('/', 'NotesController@index');
|
||||||
Route::get('/create', 'NotesController@create');
|
Route::get('/create', 'NotesController@create');
|
||||||
|
@ -52,7 +56,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::delete('/{id}', 'NotesController@destroy');
|
Route::delete('/{id}', 'NotesController@destroy');
|
||||||
});
|
});
|
||||||
|
|
||||||
//Micropub Clients
|
// Micropub Clients
|
||||||
Route::group(['prefix' => 'clients'], function () {
|
Route::group(['prefix' => 'clients'], function () {
|
||||||
Route::get('/', 'ClientsController@index');
|
Route::get('/', 'ClientsController@index');
|
||||||
Route::get('/create', 'ClientsController@create');
|
Route::get('/create', 'ClientsController@create');
|
||||||
|
@ -62,7 +66,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::delete('/{id}', 'ClientsController@destroy');
|
Route::delete('/{id}', 'ClientsController@destroy');
|
||||||
});
|
});
|
||||||
|
|
||||||
//Contacts
|
// Contacts
|
||||||
Route::group(['prefix' => 'contacts'], function () {
|
Route::group(['prefix' => 'contacts'], function () {
|
||||||
Route::get('/', 'ContactsController@index');
|
Route::get('/', 'ContactsController@index');
|
||||||
Route::get('/create', 'ContactsController@create');
|
Route::get('/create', 'ContactsController@create');
|
||||||
|
@ -73,7 +77,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::get('/{id}/getavatar', 'ContactsController@getAvatar');
|
Route::get('/{id}/getavatar', 'ContactsController@getAvatar');
|
||||||
});
|
});
|
||||||
|
|
||||||
//Places
|
// Places
|
||||||
Route::group(['prefix' => 'places'], function () {
|
Route::group(['prefix' => 'places'], function () {
|
||||||
Route::get('/', 'PlacesController@index');
|
Route::get('/', 'PlacesController@index');
|
||||||
Route::get('/create', 'PlacesController@create');
|
Route::get('/create', 'PlacesController@create');
|
||||||
|
@ -86,7 +90,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::delete('/{id}', 'PlacesController@destroy');
|
Route::delete('/{id}', 'PlacesController@destroy');
|
||||||
});
|
});
|
||||||
|
|
||||||
//Likes
|
// Likes
|
||||||
Route::group(['prefix' => 'likes'], function () {
|
Route::group(['prefix' => 'likes'], function () {
|
||||||
Route::get('/', 'LikesController@index');
|
Route::get('/', 'LikesController@index');
|
||||||
Route::get('/create', 'LikesController@create');
|
Route::get('/create', 'LikesController@create');
|
||||||
|
@ -97,7 +101,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//Blog pages using ArticlesController
|
// Blog pages using ArticlesController
|
||||||
Route::group(['prefix' => 'blog'], function () {
|
Route::group(['prefix' => 'blog'], function () {
|
||||||
Route::get('/feed.rss', 'FeedsController@blogRss');
|
Route::get('/feed.rss', 'FeedsController@blogRss');
|
||||||
Route::get('/feed.atom', 'FeedsController@blogAtom');
|
Route::get('/feed.atom', 'FeedsController@blogAtom');
|
||||||
|
@ -107,7 +111,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::get('/{year}/{month}/{slug}', 'ArticlesController@show');
|
Route::get('/{year}/{month}/{slug}', 'ArticlesController@show');
|
||||||
});
|
});
|
||||||
|
|
||||||
//Notes pages using NotesController
|
// Notes pages using NotesController
|
||||||
Route::group(['prefix' => 'notes'], function () {
|
Route::group(['prefix' => 'notes'], function () {
|
||||||
Route::get('/', 'NotesController@index');
|
Route::get('/', 'NotesController@index');
|
||||||
Route::get('/feed.rss', 'FeedsController@notesRss');
|
Route::get('/feed.rss', 'FeedsController@notesRss');
|
||||||
|
@ -139,15 +143,15 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::post('api/media', 'MicropubController@media')->middleware('micropub.token', 'cors')->name('media-endpoint');
|
Route::post('api/media', 'MicropubController@media')->middleware('micropub.token', 'cors')->name('media-endpoint');
|
||||||
Route::options('/api/media', 'MicropubController@mediaOptionsResponse')->middleware('cors');
|
Route::options('/api/media', 'MicropubController@mediaOptionsResponse')->middleware('cors');
|
||||||
|
|
||||||
//webmention
|
// Webmention
|
||||||
Route::get('webmention', 'WebMentionsController@get');
|
Route::get('webmention', 'WebMentionsController@get');
|
||||||
Route::post('webmention', 'WebMentionsController@receive');
|
Route::post('webmention', 'WebMentionsController@receive');
|
||||||
|
|
||||||
//Contacts
|
// Contacts
|
||||||
Route::get('contacts', 'ContactsController@index');
|
Route::get('contacts', 'ContactsController@index');
|
||||||
Route::get('contacts/{nick}', 'ContactsController@show');
|
Route::get('contacts/{nick}', 'ContactsController@show');
|
||||||
|
|
||||||
//Places
|
// Places
|
||||||
Route::get('places', 'PlacesController@index');
|
Route::get('places', 'PlacesController@index');
|
||||||
Route::get('places/{slug}', 'PlacesController@show');
|
Route::get('places/{slug}', 'PlacesController@show');
|
||||||
|
|
||||||
|
@ -156,7 +160,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::post('update-colour-scheme', 'SessionStoreController@saveColour');
|
Route::post('update-colour-scheme', 'SessionStoreController@saveColour');
|
||||||
});
|
});
|
||||||
|
|
||||||
//Short URL
|
// Short URL
|
||||||
Route::group(['domain' => config('url.shorturl')], function () {
|
Route::group(['domain' => config('url.shorturl')], function () {
|
||||||
Route::get('/', 'ShortURLsController@baseURL');
|
Route::get('/', 'ShortURLsController@baseURL');
|
||||||
Route::get('@', 'ShortURLsController@twitter');
|
Route::get('@', 'ShortURLsController@twitter');
|
||||||
|
|
|
@ -3,13 +3,20 @@
|
||||||
namespace Tests\Feature\Admin;
|
namespace Tests\Feature\Admin;
|
||||||
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
class AdminHomeControllerTest extends TestCase
|
class AdminHomeControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
public function test_admin_homepage()
|
public function test_admin_homepage()
|
||||||
{
|
{
|
||||||
$response = $this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
->get('/admin');
|
->get('/admin');
|
||||||
|
|
||||||
$response->assertViewIs('admin.welcome');
|
$response->assertViewIs('admin.welcome');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Tests\Feature\Admin;
|
namespace Tests\Feature\Admin;
|
||||||
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
@ -12,21 +13,27 @@ class ArticlesTest extends TestCase
|
||||||
|
|
||||||
public function test_index_page()
|
public function test_index_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
->get('/admin/blog');
|
->get('/admin/blog');
|
||||||
$response->assertSeeText('Select article to edit:');
|
$response->assertSeeText('Select article to edit:');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_page()
|
public function test_create_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
->get('/admin/blog/create');
|
->get('/admin/blog/create');
|
||||||
$response->assertSeeText('Title (URL)');
|
$response->assertSeeText('Title (URL)');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_new_article()
|
public function test_create_new_article()
|
||||||
{
|
{
|
||||||
$this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
->post('/admin/blog', [
|
->post('/admin/blog', [
|
||||||
'title' => 'Test Title',
|
'title' => 'Test Title',
|
||||||
'main' => 'Article content'
|
'main' => 'Article content'
|
||||||
|
@ -36,6 +43,7 @@ class ArticlesTest extends TestCase
|
||||||
|
|
||||||
public function test_create_new_article_with_upload()
|
public function test_create_new_article_with_upload()
|
||||||
{
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
$faker = \Faker\Factory::create();
|
$faker = \Faker\Factory::create();
|
||||||
$text = $faker->text;
|
$text = $faker->text;
|
||||||
if ($fh = fopen(sys_get_temp_dir() . '/article.md', 'w')) {
|
if ($fh = fopen(sys_get_temp_dir() . '/article.md', 'w')) {
|
||||||
|
@ -45,7 +53,7 @@ class ArticlesTest extends TestCase
|
||||||
$path = sys_get_temp_dir() . '/article.md';
|
$path = sys_get_temp_dir() . '/article.md';
|
||||||
$file = new UploadedFile($path, 'article.md', 'text/plain', filesize($path), null, true);
|
$file = new UploadedFile($path, 'article.md', 'text/plain', filesize($path), null, true);
|
||||||
|
|
||||||
$this->withSession(['loggedin' => true])
|
$this->actingAs($user)
|
||||||
->post('/admin/blog', [
|
->post('/admin/blog', [
|
||||||
'title' => 'Uploaded Article',
|
'title' => 'Uploaded Article',
|
||||||
'article' => $file,
|
'article' => $file,
|
||||||
|
@ -59,14 +67,18 @@ class ArticlesTest extends TestCase
|
||||||
|
|
||||||
public function test_see_edit_form()
|
public function test_see_edit_form()
|
||||||
{
|
{
|
||||||
$response = $this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
->get('/admin/blog/1/edit');
|
->get('/admin/blog/1/edit');
|
||||||
$response->assertSeeText('This is *my* new blog. It uses `Markdown`.');
|
$response->assertSeeText('This is *my* new blog. It uses `Markdown`.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_edit_article()
|
public function test_edit_article()
|
||||||
{
|
{
|
||||||
$this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
->post('/admin/blog/1', [
|
->post('/admin/blog/1', [
|
||||||
'_method' => 'PUT',
|
'_method' => 'PUT',
|
||||||
'title' => 'My New Blog',
|
'title' => 'My New Blog',
|
||||||
|
@ -80,7 +92,9 @@ class ArticlesTest extends TestCase
|
||||||
|
|
||||||
public function test_delete_article()
|
public function test_delete_article()
|
||||||
{
|
{
|
||||||
$this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
->post('/admin/blog/1', [
|
->post('/admin/blog/1', [
|
||||||
'_method' => 'DELETE',
|
'_method' => 'DELETE',
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Tests\Feature\Admin;
|
namespace Tests\Feature\Admin;
|
||||||
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
class ClientsTest extends TestCase
|
class ClientsTest extends TestCase
|
||||||
|
@ -11,21 +12,27 @@ class ClientsTest extends TestCase
|
||||||
|
|
||||||
public function test_index_page()
|
public function test_index_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
->get('/admin/clients');
|
->get('/admin/clients');
|
||||||
$response->assertSeeText('Clients');
|
$response->assertSeeText('Clients');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_page()
|
public function test_create_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
->get('/admin/clients/create');
|
->get('/admin/clients/create');
|
||||||
$response->assertSeeText('New Client');
|
$response->assertSeeText('New Client');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_new_client()
|
public function test_create_new_client()
|
||||||
{
|
{
|
||||||
$this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
->post('/admin/clients', [
|
->post('/admin/clients', [
|
||||||
'client_name' => 'Micropublish',
|
'client_name' => 'Micropublish',
|
||||||
'client_url' => 'https://micropublish.net'
|
'client_url' => 'https://micropublish.net'
|
||||||
|
@ -38,14 +45,18 @@ class ClientsTest extends TestCase
|
||||||
|
|
||||||
public function test_see_edit_form()
|
public function test_see_edit_form()
|
||||||
{
|
{
|
||||||
$response = $this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
->get('/admin/clients/1/edit');
|
->get('/admin/clients/1/edit');
|
||||||
$response->assertSee('https://jbl5.dev/notes/new');
|
$response->assertSee('https://jbl5.dev/notes/new');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_edit_client()
|
public function test_edit_client()
|
||||||
{
|
{
|
||||||
$this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
->post('/admin/clients/1', [
|
->post('/admin/clients/1', [
|
||||||
'_method' => 'PUT',
|
'_method' => 'PUT',
|
||||||
'client_url' => 'https://jbl5.dev/notes/new',
|
'client_url' => 'https://jbl5.dev/notes/new',
|
||||||
|
@ -59,7 +70,9 @@ class ClientsTest extends TestCase
|
||||||
|
|
||||||
public function test_delete_client()
|
public function test_delete_client()
|
||||||
{
|
{
|
||||||
$this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
->post('/admin/clients/1', [
|
->post('/admin/clients/1', [
|
||||||
'_method' => 'DELETE',
|
'_method' => 'DELETE',
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Tests\Feature\Admin;
|
namespace Tests\Feature\Admin;
|
||||||
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use App\Models\User;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use App\Models\Contact;
|
use App\Models\Contact;
|
||||||
use GuzzleHttp\HandlerStack;
|
use GuzzleHttp\HandlerStack;
|
||||||
|
@ -26,25 +27,25 @@ class ContactsTest extends TestCase
|
||||||
|
|
||||||
public function test_index_page()
|
public function test_index_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true
|
|
||||||
])->get('/admin/contacts');
|
$response = $this->actingAs($user)->get('/admin/contacts');
|
||||||
$response->assertViewIs('admin.contacts.index');
|
$response->assertViewIs('admin.contacts.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_page()
|
public function test_create_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true
|
|
||||||
])->get('/admin/contacts/create');
|
$response = $this->actingAs($user)->get('/admin/contacts/create');
|
||||||
$response->assertViewIs('admin.contacts.create');
|
$response->assertViewIs('admin.contacts.create');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_new_contact()
|
public function test_create_new_contact()
|
||||||
{
|
{
|
||||||
$this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true
|
|
||||||
])->post('/admin/contacts', [
|
$this->actingAs($user)->post('/admin/contacts', [
|
||||||
'name' => 'Fred Bloggs',
|
'name' => 'Fred Bloggs',
|
||||||
'nick' => 'fred',
|
'nick' => 'fred',
|
||||||
'homepage' => 'https://fred.blog/gs',
|
'homepage' => 'https://fred.blog/gs',
|
||||||
|
@ -58,17 +59,17 @@ class ContactsTest extends TestCase
|
||||||
|
|
||||||
public function test_see_edit_form()
|
public function test_see_edit_form()
|
||||||
{
|
{
|
||||||
$response = $this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true
|
|
||||||
])->get('/admin/contacts/1/edit');
|
$response = $this->actingAs($user)->get('/admin/contacts/1/edit');
|
||||||
$response->assertViewIs('admin.contacts.edit');
|
$response->assertViewIs('admin.contacts.edit');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_update_contact_no_uploaded_avatar()
|
public function test_update_contact_no_uploaded_avatar()
|
||||||
{
|
{
|
||||||
$this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true
|
|
||||||
])->post('/admin/contacts/1', [
|
$this->actingAs($user)->post('/admin/contacts/1', [
|
||||||
'_method' => 'PUT',
|
'_method' => 'PUT',
|
||||||
'name' => 'Tantek Celik',
|
'name' => 'Tantek Celik',
|
||||||
'nick' => 'tantek',
|
'nick' => 'tantek',
|
||||||
|
@ -86,9 +87,9 @@ class ContactsTest extends TestCase
|
||||||
copy(__DIR__ . '/../../aaron.png', sys_get_temp_dir() . '/tantek.png');
|
copy(__DIR__ . '/../../aaron.png', sys_get_temp_dir() . '/tantek.png');
|
||||||
$path = sys_get_temp_dir() . '/tantek.png';
|
$path = sys_get_temp_dir() . '/tantek.png';
|
||||||
$file = new UploadedFile($path, 'tantek.png', 'image/png', filesize($path), null, true);
|
$file = new UploadedFile($path, 'tantek.png', 'image/png', filesize($path), null, true);
|
||||||
$this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true
|
|
||||||
])->post('/admin/contacts/1', [
|
$this->actingAs($user)->post('/admin/contacts/1', [
|
||||||
'_method' => 'PUT',
|
'_method' => 'PUT',
|
||||||
'name' => 'Tantek Celik',
|
'name' => 'Tantek Celik',
|
||||||
'nick' => 'tantek',
|
'nick' => 'tantek',
|
||||||
|
@ -104,9 +105,9 @@ class ContactsTest extends TestCase
|
||||||
|
|
||||||
public function test_delete_contact()
|
public function test_delete_contact()
|
||||||
{
|
{
|
||||||
$this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true
|
|
||||||
])->post('/admin/contacts/1', [
|
$this->actingAs($user)->post('/admin/contacts/1', [
|
||||||
'_method' => 'DELETE',
|
'_method' => 'DELETE',
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseMissing('contacts', [
|
$this->assertDatabaseMissing('contacts', [
|
||||||
|
@ -129,10 +130,9 @@ HTML;
|
||||||
$handler = HandlerStack::create($mock);
|
$handler = HandlerStack::create($mock);
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
$response = $this->withSession([
|
$this->actingAs($user)->get('/admin/contacts/1/getavatar');
|
||||||
'loggedin' => true,
|
|
||||||
])->get('/admin/contacts/1/getavatar');
|
|
||||||
|
|
||||||
$this->assertFileEquals(
|
$this->assertFileEquals(
|
||||||
__DIR__ . '/../../aaron.png',
|
__DIR__ . '/../../aaron.png',
|
||||||
|
@ -148,10 +148,9 @@ HTML;
|
||||||
$handler = HandlerStack::create($mock);
|
$handler = HandlerStack::create($mock);
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
$response = $this->withSession([
|
$response = $this->actingAs($user)->get('/admin/contacts/1/getavatar');
|
||||||
'loggedin' => true,
|
|
||||||
])->get('/admin/contacts/1/getavatar');
|
|
||||||
|
|
||||||
$response->assertRedirect('/admin/contacts/1/edit');
|
$response->assertRedirect('/admin/contacts/1/edit');
|
||||||
}
|
}
|
||||||
|
@ -170,10 +169,9 @@ HTML;
|
||||||
$handler = HandlerStack::create($mock);
|
$handler = HandlerStack::create($mock);
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
$response = $this->withSession([
|
$response = $this->actingAs($user)->get('/admin/contacts/1/getavatar');
|
||||||
'loggedin' => true,
|
|
||||||
])->get('/admin/contacts/1/getavatar');
|
|
||||||
|
|
||||||
$response->assertRedirect('/admin/contacts/1/edit');
|
$response->assertRedirect('/admin/contacts/1/edit');
|
||||||
}
|
}
|
||||||
|
@ -184,10 +182,9 @@ HTML;
|
||||||
'nick' => 'fred',
|
'nick' => 'fred',
|
||||||
'name' => 'Fred Bloggs',
|
'name' => 'Fred Bloggs',
|
||||||
]);
|
]);
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
$response = $this->withSession([
|
$response = $this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/getavatar');
|
||||||
'loggedin' => true,
|
|
||||||
])->get('/admin/contacts/' . $contact->id . '/getavatar');
|
|
||||||
|
|
||||||
$response->assertRedirect('/admin/contacts/' . $contact->id . '/edit');
|
$response->assertRedirect('/admin/contacts/' . $contact->id . '/edit');
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Admin;
|
namespace Tests\Feature\Admin;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use App\Models\Like;
|
use App\Models\Like;
|
||||||
use App\Jobs\ProcessLike;
|
use App\Jobs\ProcessLike;
|
||||||
use Illuminate\Support\Facades\Queue;
|
use Illuminate\Support\Facades\Queue;
|
||||||
use Illuminate\Foundation\Testing\WithFaker;
|
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
class LikesTest extends TestCase
|
class LikesTest extends TestCase
|
||||||
|
@ -15,14 +15,18 @@ class LikesTest extends TestCase
|
||||||
|
|
||||||
public function test_index_page()
|
public function test_index_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
->get('/admin/likes');
|
->get('/admin/likes');
|
||||||
$response->assertSeeText('Likes');
|
$response->assertSeeText('Likes');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_page()
|
public function test_create_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
->get('/admin/likes/create');
|
->get('/admin/likes/create');
|
||||||
$response->assertSeeText('New Like');
|
$response->assertSeeText('New Like');
|
||||||
}
|
}
|
||||||
|
@ -30,7 +34,9 @@ class LikesTest extends TestCase
|
||||||
public function test_create_new_like()
|
public function test_create_new_like()
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
$this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
->post('/admin/likes', [
|
->post('/admin/likes', [
|
||||||
'like_url' => 'https://example.com'
|
'like_url' => 'https://example.com'
|
||||||
]);
|
]);
|
||||||
|
@ -42,7 +48,9 @@ class LikesTest extends TestCase
|
||||||
|
|
||||||
public function test_see_edit_form()
|
public function test_see_edit_form()
|
||||||
{
|
{
|
||||||
$response = $this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
->get('/admin/likes/1/edit');
|
->get('/admin/likes/1/edit');
|
||||||
$response->assertSee('Edit Like');
|
$response->assertSee('Edit Like');
|
||||||
}
|
}
|
||||||
|
@ -50,7 +58,9 @@ class LikesTest extends TestCase
|
||||||
public function test_edit_like()
|
public function test_edit_like()
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
$this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
->post('/admin/likes/1', [
|
->post('/admin/likes/1', [
|
||||||
'_method' => 'PUT',
|
'_method' => 'PUT',
|
||||||
'like_url' => 'https://example.com',
|
'like_url' => 'https://example.com',
|
||||||
|
@ -65,7 +75,9 @@ class LikesTest extends TestCase
|
||||||
{
|
{
|
||||||
$like = Like::find(1);
|
$like = Like::find(1);
|
||||||
$url = $like->url;
|
$url = $like->url;
|
||||||
$this->withSession(['loggedin' => true])
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
->post('/admin/likes/1', [
|
->post('/admin/likes/1', [
|
||||||
'_method' => 'DELETE',
|
'_method' => 'DELETE',
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Admin;
|
namespace Tests\Feature\Admin;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use App\Jobs\SendWebMentions;
|
use App\Jobs\SendWebMentions;
|
||||||
use Illuminate\Support\Facades\Queue;
|
use Illuminate\Support\Facades\Queue;
|
||||||
|
@ -13,25 +14,25 @@ class NotesTest extends TestCase
|
||||||
|
|
||||||
public function test_index_page()
|
public function test_index_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true,
|
|
||||||
])->get('/admin/notes');
|
$response = $this->actingAs($user)->get('/admin/notes');
|
||||||
$response->assertViewIs('admin.notes.index');
|
$response->assertViewIs('admin.notes.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_page()
|
public function test_create_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true,
|
|
||||||
])->get('/admin/notes/create');
|
$response = $this->actingAs($user)->get('/admin/notes/create');
|
||||||
$response->assertViewIs('admin.notes.create');
|
$response->assertViewIs('admin.notes.create');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_a_new_note()
|
public function test_create_a_new_note()
|
||||||
{
|
{
|
||||||
$this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true,
|
|
||||||
])->post('/admin/notes', [
|
$this->actingAs($user)->post('/admin/notes', [
|
||||||
'content' => 'A new test note',
|
'content' => 'A new test note',
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('notes', [
|
$this->assertDatabaseHas('notes', [
|
||||||
|
@ -41,19 +42,18 @@ class NotesTest extends TestCase
|
||||||
|
|
||||||
public function test_edit_page()
|
public function test_edit_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true,
|
|
||||||
])->get('/admin/notes/1/edit');
|
$response = $this->actingAs($user)->get('/admin/notes/1/edit');
|
||||||
$response->assertViewIs('admin.notes.edit');
|
$response->assertViewIs('admin.notes.edit');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_edit_a_note()
|
public function test_edit_a_note()
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
$this->withSession([
|
$this->actingAs($user)->post('/admin/notes/1', [
|
||||||
'loggedin' => true,
|
|
||||||
])->post('/admin/notes/1', [
|
|
||||||
'_method' => 'PUT',
|
'_method' => 'PUT',
|
||||||
'content' => 'An edited note',
|
'content' => 'An edited note',
|
||||||
'webmentions' => true,
|
'webmentions' => true,
|
||||||
|
@ -67,9 +67,9 @@ class NotesTest extends TestCase
|
||||||
|
|
||||||
public function test_delete_note()
|
public function test_delete_note()
|
||||||
{
|
{
|
||||||
$this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true,
|
|
||||||
])->post('/admin/notes/1', [
|
$this->actingAs($user)->post('/admin/notes/1', [
|
||||||
'_method' => 'DELETE',
|
'_method' => 'DELETE',
|
||||||
]);
|
]);
|
||||||
$this->assertSoftDeleted('notes', [
|
$this->assertSoftDeleted('notes', [
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Admin;
|
namespace Tests\Feature\Admin;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
@ -11,25 +12,25 @@ class PlacesTest extends TestCase
|
||||||
|
|
||||||
public function test_index_page()
|
public function test_index_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true,
|
|
||||||
])->get('/admin/places');
|
$response = $this->actingAs($user)->get('/admin/places');
|
||||||
$response->assertViewIs('admin.places.index');
|
$response->assertViewIs('admin.places.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_page()
|
public function test_create_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true,
|
|
||||||
])->get('/admin/places/create');
|
$response = $this->actingAs($user)->get('/admin/places/create');
|
||||||
$response->assertViewIs('admin.places.create');
|
$response->assertViewIs('admin.places.create');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_new_place()
|
public function test_create_new_place()
|
||||||
{
|
{
|
||||||
$this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true,
|
|
||||||
])->post('/admin/places', [
|
$this->actingAs($user)->post('/admin/places', [
|
||||||
'name' => 'Test Place',
|
'name' => 'Test Place',
|
||||||
'description' => 'A dummy place for feature tests',
|
'description' => 'A dummy place for feature tests',
|
||||||
'latitude' => '1.23',
|
'latitude' => '1.23',
|
||||||
|
@ -43,17 +44,17 @@ class PlacesTest extends TestCase
|
||||||
|
|
||||||
public function test_edit_page()
|
public function test_edit_page()
|
||||||
{
|
{
|
||||||
$response = $this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true,
|
|
||||||
])->get('/admin/places/1/edit');
|
$response = $this->actingAs($user)->get('/admin/places/1/edit');
|
||||||
$response->assertViewIs('admin.places.edit');
|
$response->assertViewIs('admin.places.edit');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_updating_a_place()
|
public function test_updating_a_place()
|
||||||
{
|
{
|
||||||
$this->withSession([
|
$user = factory(User::class)->create();
|
||||||
'loggedin' => true,
|
|
||||||
])->post('/admin/places/1', [
|
$this->actingAs($user)->post('/admin/places/1', [
|
||||||
'_method' => 'PUT',
|
'_method' => 'PUT',
|
||||||
'name' => 'The Bridgewater',
|
'name' => 'The Bridgewater',
|
||||||
'description' => 'Who uses “Pub” anyway',
|
'description' => 'Who uses “Pub” anyway',
|
||||||
|
|
Loading…
Add table
Reference in a new issue