Finish re-working tests to run on test database

This commit is contained in:
Jonny Barnes 2021-08-31 12:28:00 +01:00
parent 09fc211623
commit 1abca77bdc
50 changed files with 535 additions and 265 deletions

View file

@ -4,15 +4,16 @@ declare(strict_types=1);
namespace Tests\Feature\Admin;
use App\Models\Article;
use App\Models\User;
use Faker\Factory;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class ArticlesTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
/** @test */
public function adminArticlesPageLoads(): void
@ -76,9 +77,12 @@ class ArticlesTest extends TestCase
public function articleCanLoadFormToEditArticle(): void
{
$user = User::factory()->make();
$article = Article::factory()->create([
'main' => 'This is *my* new blog. It uses `Markdown`.',
]);
$response = $this->actingAs($user)
->get('/admin/blog/1/edit');
->get('/admin/blog/' . $article->id . '/edit');
$response->assertSeeText('This is *my* new blog. It uses `Markdown`.');
}
@ -86,9 +90,10 @@ class ArticlesTest extends TestCase
public function adminCanEditArticle(): void
{
$user = User::factory()->make();
$article = Article::factory()->create();
$this->actingAs($user)
->post('/admin/blog/1', [
->post('/admin/blog/' . $article->id, [
'_method' => 'PUT',
'title' => 'My New Blog',
'main' => 'This article has been edited',
@ -103,13 +108,14 @@ class ArticlesTest extends TestCase
public function adminCanDeleteArticle(): void
{
$user = User::factory()->make();
$article = Article::factory()->create();
$this->actingAs($user)
->post('/admin/blog/1', [
->post('/admin/blog/' . $article->id, [
'_method' => 'DELETE',
]);
$this->assertSoftDeleted('articles', [
'title' => 'My New Blog',
'title' => $article->title,
]);
}
}

View file

@ -4,13 +4,14 @@ declare(strict_types=1);
namespace Tests\Feature\Admin;
use App\Models\MicropubClient;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ClientsTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
/** @test */
public function clientsPageLoads(): void
@ -52,9 +53,12 @@ class ClientsTest extends TestCase
public function adminCanLoadEditFormForClient(): void
{
$user = User::factory()->make();
$client = MicropubClient::factory()->create([
'client_url' => 'https://jbl5.dev/notes/new',
]);
$response = $this->actingAs($user)
->get('/admin/clients/1/edit');
->get('/admin/clients/' . $client->id . '/edit');
$response->assertSee('https://jbl5.dev/notes/new');
}
@ -62,9 +66,10 @@ class ClientsTest extends TestCase
public function adminCanEditClient(): void
{
$user = User::factory()->make();
$client = MicropubClient::factory()->create();
$this->actingAs($user)
->post('/admin/clients/1', [
->post('/admin/clients/' . $client->id, [
'_method' => 'PUT',
'client_url' => 'https://jbl5.dev/notes/new',
'client_name' => 'JBL5dev',
@ -79,9 +84,12 @@ class ClientsTest extends TestCase
public function adminCanDeleteClient(): void
{
$user = User::factory()->make();
$client = MicropubClient::factory()->create([
'client_url' => 'https://jbl5.dev/notes/new',
]);
$this->actingAs($user)
->post('/admin/clients/1', [
->post('/admin/clients/' . $client->id, [
'_method' => 'DELETE',
]);
$this->assertDatabaseMissing('clients', [

View file

@ -10,13 +10,13 @@ use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Tests\TestCase;
class ContactsTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
protected function tearDown(): void
{
@ -66,8 +66,9 @@ class ContactsTest extends TestCase
public function adminCanSeeFormToEditContact(): void
{
$user = User::factory()->make();
$contact = Contact::factory()->create();
$response = $this->actingAs($user)->get('/admin/contacts/1/edit');
$response = $this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/edit');
$response->assertViewIs('admin.contacts.edit');
}
@ -75,8 +76,9 @@ class ContactsTest extends TestCase
public function adminCanUpdateContact(): void
{
$user = User::factory()->make();
$contact = Contact::factory()->create();
$this->actingAs($user)->post('/admin/contacts/1', [
$this->actingAs($user)->post('/admin/contacts/' . $contact->id, [
'_method' => 'PUT',
'name' => 'Tantek Celik',
'nick' => 'tantek',
@ -96,8 +98,9 @@ class ContactsTest extends TestCase
$path = sys_get_temp_dir() . '/tantek.png';
$file = new UploadedFile($path, 'tantek.png', 'image/png', null, true);
$user = User::factory()->make();
$contact = Contact::factory()->create();
$this->actingAs($user)->post('/admin/contacts/1', [
$this->actingAs($user)->post('/admin/contacts/' . $contact->id, [
'_method' => 'PUT',
'name' => 'Tantek Celik',
'nick' => 'tantek',
@ -115,8 +118,13 @@ class ContactsTest extends TestCase
public function adminCanDeleteContact(): void
{
$user = User::factory()->make();
$contact = Contact::factory()->create(['nick' => 'tantek']);
$this->actingAs($user)->post('/admin/contacts/1', [
$this->assertDatabaseHas('contacts', [
'nick' => 'tantek',
]);
$this->actingAs($user)->post('/admin/contacts/' . $contact->id, [
'_method' => 'DELETE',
]);
$this->assertDatabaseMissing('contacts', [
@ -132,7 +140,7 @@ class ContactsTest extends TestCase
<img class="u-photo" alt="" src="http://tantek.com/tantek.png">
</div>
HTML;
$file = fopen(__DIR__ . '/../../aaron.png', 'r');
$file = fopen(__DIR__ . '/../../aaron.png', 'rb');
$mock = new MockHandler([
new Response(200, ['Content-Type' => 'text/html'], $html),
new Response(200, ['Content-Type' => 'iamge/png'], $file),
@ -141,8 +149,11 @@ class ContactsTest extends TestCase
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$user = User::factory()->make();
$contact = Contact::factory()->create([
'homepage' => 'https://tantek.com',
]);
$this->actingAs($user)->get('/admin/contacts/1/getavatar');
$this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/getavatar');
$this->assertFileEquals(
__DIR__ . '/../../aaron.png',
@ -160,10 +171,11 @@ class ContactsTest extends TestCase
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$user = User::factory()->make();
$contact = Contact::factory()->create();
$response = $this->actingAs($user)->get('/admin/contacts/1/getavatar');
$response = $this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/getavatar');
$response->assertRedirect('/admin/contacts/1/edit');
$response->assertRedirect('/admin/contacts/' . $contact->id . '/edit');
}
/** @test */
@ -182,10 +194,11 @@ class ContactsTest extends TestCase
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$user = User::factory()->make();
$contact = Contact::factory()->create();
$response = $this->actingAs($user)->get('/admin/contacts/1/getavatar');
$response = $this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/getavatar');
$response->assertRedirect('/admin/contacts/1/edit');
$response->assertRedirect('/admin/contacts/' . $contact->id . '/edit');
}
/** @test */

View file

@ -7,13 +7,13 @@ namespace Tests\Feature\Admin;
use App\Jobs\ProcessLike;
use App\Models\Like;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class LikesTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
/** @test */
public function likesPageLoads(): void
@ -55,9 +55,10 @@ class LikesTest extends TestCase
public function likeEditFormLoads(): void
{
$user = User::factory()->make();
$like = Like::factory()->create();
$response = $this->actingAs($user)
->get('/admin/likes/1/edit');
->get('/admin/likes/' . $like->id . '/edit');
$response->assertSee('Edit Like');
}
@ -66,9 +67,10 @@ class LikesTest extends TestCase
{
Queue::fake();
$user = User::factory()->make();
$like = Like::factory()->create();
$this->actingAs($user)
->post('/admin/likes/1', [
->post('/admin/likes/' . $like->id, [
'_method' => 'PUT',
'like_url' => 'https://example.com',
]);
@ -81,12 +83,12 @@ class LikesTest extends TestCase
/** @test */
public function adminCanDeleteLike(): void
{
$like = Like::find(1);
$like = Like::factory()->create();
$url = $like->url;
$user = User::factory()->make();
$this->actingAs($user)
->post('/admin/likes/1', [
->post('/admin/likes/' . $like->id, [
'_method' => 'DELETE',
]);
$this->assertDatabaseMissing('likes', [

View file

@ -5,14 +5,15 @@ declare(strict_types=1);
namespace Tests\Feature\Admin;
use App\Jobs\SendWebMentions;
use App\Models\Note;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class NotesTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
/** @test */
public function notesPageLoads(): void
@ -49,8 +50,9 @@ class NotesTest extends TestCase
public function noteEditFormLoads(): void
{
$user = User::factory()->make();
$note = Note::factory()->create();
$response = $this->actingAs($user)->get('/admin/notes/1/edit');
$response = $this->actingAs($user)->get('/admin/notes/' . $note->id . '/edit');
$response->assertViewIs('admin.notes.edit');
}
@ -59,8 +61,9 @@ class NotesTest extends TestCase
{
Queue::fake();
$user = User::factory()->make();
$note = Note::factory()->create();
$this->actingAs($user)->post('/admin/notes/1', [
$this->actingAs($user)->post('/admin/notes/' . $note->id, [
'_method' => 'PUT',
'content' => 'An edited note',
'webmentions' => true,
@ -76,12 +79,13 @@ class NotesTest extends TestCase
public function adminCanDeleteNote(): void
{
$user = User::factory()->make();
$note = Note::factory()->create();
$this->actingAs($user)->post('/admin/notes/1', [
$this->actingAs($user)->post('/admin/notes/' . $note->id, [
'_method' => 'DELETE',
]);
$this->assertSoftDeleted('notes', [
'id' => '1',
'id' => $note->id,
]);
}
}

View file

@ -4,13 +4,14 @@ declare(strict_types=1);
namespace Tests\Feature\Admin;
use App\Models\Place;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PlacesTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
/** @test */
public function placesPageLoads(): void
@ -51,8 +52,9 @@ class PlacesTest extends TestCase
public function editPlacePageLoads(): void
{
$user = User::factory()->make();
$place = Place::factory()->create();
$response = $this->actingAs($user)->get('/admin/places/1/edit');
$response = $this->actingAs($user)->get('/admin/places/' . $place->id . '/edit');
$response->assertViewIs('admin.places.edit');
}
@ -60,8 +62,11 @@ class PlacesTest extends TestCase
public function adminCanUpdatePlace(): void
{
$user = User::factory()->make();
$place = Place::factory()->create([
'name' => 'The Bridgewater Pub',
]);
$this->actingAs($user)->post('/admin/places/1', [
$this->actingAs($user)->post('/admin/places/' . $place->id, [
'_method' => 'PUT',
'name' => 'The Bridgewater',
'description' => 'Who uses “Pub” anyway',