Move some tests into their own subfodlers
This commit is contained in:
parent
0dd6adfa0e
commit
e1aa814d8c
18 changed files with 29 additions and 31 deletions
15
tests/Feature/Admin/AdminHomeControllerTest.php
Normal file
15
tests/Feature/Admin/AdminHomeControllerTest.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminHomeControllerTest extends TestCase
|
||||
{
|
||||
public function test_admin_homepage()
|
||||
{
|
||||
$response = $this->withSession(['loggedin' => true])
|
||||
->get('/admin');
|
||||
$response->assertViewIs('admin.welcome');
|
||||
}
|
||||
}
|
38
tests/Feature/Admin/AdminTest.php
Normal file
38
tests/Feature/Admin/AdminTest.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminTest extends TestCase
|
||||
{
|
||||
public function test_admin_page_redirects_to_login()
|
||||
{
|
||||
$response = $this->get('/admin');
|
||||
$response->assertRedirect('/login');
|
||||
}
|
||||
|
||||
public function test_login_page()
|
||||
{
|
||||
$response = $this->get('/login');
|
||||
$response->assertViewIs('login');
|
||||
}
|
||||
|
||||
public function test_attempt_login_with_good_credentials()
|
||||
{
|
||||
$response = $this->post('/login', [
|
||||
'username' => config('admin.user'),
|
||||
'password' => config('admin.pass'),
|
||||
]);
|
||||
$response->assertRedirect('/admin');
|
||||
}
|
||||
|
||||
public function test_attempt_login_with_bad_credentials()
|
||||
{
|
||||
$response = $this->post('/login', [
|
||||
'username' => 'bad',
|
||||
'password' => 'credentials',
|
||||
]);
|
||||
$response->assertRedirect('/login');
|
||||
}
|
||||
}
|
91
tests/Feature/Admin/ArticlesTest.php
Normal file
91
tests/Feature/Admin/ArticlesTest.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ArticlesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_index_page()
|
||||
{
|
||||
$response = $this->withSession(['loggedin' => true])
|
||||
->get('/admin/blog');
|
||||
$response->assertSeeText('Select article to edit:');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
{
|
||||
$response = $this->withSession(['loggedin' => true])
|
||||
->get('/admin/blog/create');
|
||||
$response->assertSeeText('Title (URL)');
|
||||
}
|
||||
|
||||
public function test_create_new_article()
|
||||
{
|
||||
$this->withSession(['loggedin' => true])
|
||||
->post('/admin/blog', [
|
||||
'title' => 'Test Title',
|
||||
'main' => 'Article content'
|
||||
]);
|
||||
$this->assertDatabaseHas('articles', ['title' => 'Test Title']);
|
||||
}
|
||||
|
||||
public function test_create_new_article_with_upload()
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$text = $faker->text;
|
||||
if ($fh = fopen(sys_get_temp_dir() . '/article.md', 'w')) {
|
||||
fwrite($fh, $text);
|
||||
fclose($fh);
|
||||
}
|
||||
$path = sys_get_temp_dir() . '/article.md';
|
||||
$file = new UploadedFile($path, 'article.md', 'text/plain', filesize($path), null, true);
|
||||
|
||||
$this->withSession(['loggedin' => true])
|
||||
->post('/admin/blog', [
|
||||
'title' => 'Uploaded Article',
|
||||
'article' => $file,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('articles', [
|
||||
'title' => 'Uploaded Article',
|
||||
'main' => $text,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_edit_form()
|
||||
{
|
||||
$response = $this->withSession(['loggedin' => true])
|
||||
->get('/admin/blog/1/edit');
|
||||
$response->assertSeeText('This is *my* new blog. It uses `Markdown`.');
|
||||
}
|
||||
|
||||
public function test_edit_article()
|
||||
{
|
||||
$this->withSession(['loggedin' => true])
|
||||
->post('/admin/blog/1', [
|
||||
'_method' => 'PUT',
|
||||
'title' => 'My New Blog',
|
||||
'main' => 'This article has been edited',
|
||||
]);
|
||||
$this->assertDatabaseHas('articles', [
|
||||
'title' => 'My New Blog',
|
||||
'main' => 'This article has been edited',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_article()
|
||||
{
|
||||
$this->withSession(['loggedin' => true])
|
||||
->post('/admin/blog/1', [
|
||||
'_method' => 'DELETE',
|
||||
]);
|
||||
$this->assertSoftDeleted('articles', [
|
||||
'title' => 'My New Blog',
|
||||
]);
|
||||
}
|
||||
}
|
70
tests/Feature/Admin/ClientsTest.php
Normal file
70
tests/Feature/Admin/ClientsTest.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ClientsTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_index_page()
|
||||
{
|
||||
$response = $this->withSession(['loggedin' => true])
|
||||
->get('/admin/clients');
|
||||
$response->assertSeeText('Clients');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
{
|
||||
$response = $this->withSession(['loggedin' => true])
|
||||
->get('/admin/clients/create');
|
||||
$response->assertSeeText('New Client');
|
||||
}
|
||||
|
||||
public function test_create_new_client()
|
||||
{
|
||||
$this->withSession(['loggedin' => true])
|
||||
->post('/admin/clients', [
|
||||
'client_name' => 'Micropublish',
|
||||
'client_url' => 'https://micropublish.net'
|
||||
]);
|
||||
$this->assertDatabaseHas('clients', [
|
||||
'client_name' => 'Micropublish',
|
||||
'client_url' => 'https://micropublish.net'
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_edit_form()
|
||||
{
|
||||
$response = $this->withSession(['loggedin' => true])
|
||||
->get('/admin/clients/1/edit');
|
||||
$response->assertSee('https://jbl5.dev/notes/new');
|
||||
}
|
||||
|
||||
public function test_edit_client()
|
||||
{
|
||||
$this->withSession(['loggedin' => true])
|
||||
->post('/admin/clients/1', [
|
||||
'_method' => 'PUT',
|
||||
'client_url' => 'https://jbl5.dev/notes/new',
|
||||
'client_name' => 'JBL5dev',
|
||||
]);
|
||||
$this->assertDatabaseHas('clients', [
|
||||
'client_url' => 'https://jbl5.dev/notes/new',
|
||||
'client_name' => 'JBL5dev',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_client()
|
||||
{
|
||||
$this->withSession(['loggedin' => true])
|
||||
->post('/admin/clients/1', [
|
||||
'_method' => 'DELETE',
|
||||
]);
|
||||
$this->assertDatabaseMissing('clients', [
|
||||
'client_url' => 'https://jbl5.dev/notes/new',
|
||||
]);
|
||||
}
|
||||
}
|
194
tests/Feature/Admin/ContactsTest.php
Normal file
194
tests/Feature/Admin/ContactsTest.php
Normal file
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use App\Contact;
|
||||
use Tests\TestCase;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ContactsTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if (file_exists(public_path() . '/assets/profile-images/tantek.com/image')) {
|
||||
unlink(public_path() . '/assets/profile-images/tantek.com/image');
|
||||
rmdir(public_path() . '/assets/profile-images/tantek.com');
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_index_page()
|
||||
{
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true
|
||||
])->get('/admin/contacts');
|
||||
$response->assertViewIs('admin.contacts.index');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
{
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true
|
||||
])->get('/admin/contacts/create');
|
||||
$response->assertViewIs('admin.contacts.create');
|
||||
}
|
||||
|
||||
public function test_create_new_contact()
|
||||
{
|
||||
$this->withSession([
|
||||
'loggedin' => true
|
||||
])->post('/admin/contacts', [
|
||||
'name' => 'Fred Bloggs',
|
||||
'nick' => 'fred',
|
||||
'homepage' => 'https://fred.blog/gs',
|
||||
]);
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'name' => 'Fred Bloggs',
|
||||
'nick' => 'fred',
|
||||
'homepage' => 'https://fred.blog/gs'
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_edit_form()
|
||||
{
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true
|
||||
])->get('/admin/contacts/1/edit');
|
||||
$response->assertViewIs('admin.contacts.edit');
|
||||
}
|
||||
|
||||
public function test_update_contact_no_uploaded_avatar()
|
||||
{
|
||||
$this->withSession([
|
||||
'loggedin' => true
|
||||
])->post('/admin/contacts/1', [
|
||||
'_method' => 'PUT',
|
||||
'name' => 'Tantek Celik',
|
||||
'nick' => 'tantek',
|
||||
'homepage' => 'https://tantek.com',
|
||||
'twitter' => 't',
|
||||
]);
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'name' => 'Tantek Celik',
|
||||
'homepage' => 'https://tantek.com',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_edit_contact_with_uploaded_avatar()
|
||||
{
|
||||
copy(__DIR__ . '/../../aaron.png', 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);
|
||||
$this->withSession([
|
||||
'loggedin' => true
|
||||
])->post('/admin/contacts/1', [
|
||||
'_method' => 'PUT',
|
||||
'name' => 'Tantek Celik',
|
||||
'nick' => 'tantek',
|
||||
'homepage' => 'https://tantek.com',
|
||||
'twitter' => 't',
|
||||
'avatar' => $file,
|
||||
]);
|
||||
$this->assertFileEquals(
|
||||
__DIR__ . '/../../aaron.png',
|
||||
public_path() . '/assets/profile-images/tantek.com/image'
|
||||
);
|
||||
}
|
||||
|
||||
public function test_delete_contact()
|
||||
{
|
||||
$this->withSession([
|
||||
'loggedin' => true
|
||||
])->post('/admin/contacts/1', [
|
||||
'_method' => 'DELETE',
|
||||
]);
|
||||
$this->assertDatabaseMissing('contacts', [
|
||||
'nick' => 'tantek',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_get_avatar_method()
|
||||
{
|
||||
$html = <<<HTML
|
||||
<div class="h-card">
|
||||
<img class="u-photo" src="http://tantek.com/tantek.png">
|
||||
</div>
|
||||
HTML;
|
||||
$file = fopen(__DIR__ . '/../../aaron.png', 'r');
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['Content-Type' => 'text/html'], $html),
|
||||
new Response(200, ['Content-Type' => 'iamge/png'], $file),
|
||||
]);
|
||||
$handler = HandlerStack::create($mock);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
$this->app->instance(Client::class, $client);
|
||||
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true,
|
||||
])->get('/admin/contacts/1/getavatar');
|
||||
|
||||
$this->assertFileEquals(
|
||||
__DIR__ . '/../../aaron.png',
|
||||
public_path() . '/assets/profile-images/tantek.com/image'
|
||||
);
|
||||
}
|
||||
|
||||
public function test_get_avatar_method_redirects_with_failed_homepage()
|
||||
{
|
||||
$mock = new MockHandler([
|
||||
new Response(404),
|
||||
]);
|
||||
$handler = HandlerStack::create($mock);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
$this->app->instance(Client::class, $client);
|
||||
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true,
|
||||
])->get('/admin/contacts/1/getavatar');
|
||||
|
||||
$response->assertRedirect('/admin/contacts/1/edit');
|
||||
}
|
||||
|
||||
public function test_get_avatar_method_redirects_with_failed_avatar_download()
|
||||
{
|
||||
$html = <<<HTML
|
||||
<div class="h-card">
|
||||
<img class="u-photo" src="http://tantek.com/tantek.png">
|
||||
</div>
|
||||
HTML;
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['Content-Type' => 'text/html'], $html),
|
||||
new Response(404),
|
||||
]);
|
||||
$handler = HandlerStack::create($mock);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
$this->app->instance(Client::class, $client);
|
||||
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true,
|
||||
])->get('/admin/contacts/1/getavatar');
|
||||
|
||||
$response->assertRedirect('/admin/contacts/1/edit');
|
||||
}
|
||||
|
||||
public function test_get_avatar_for_contact_with_no_homepage()
|
||||
{
|
||||
$contact = Contact::create([
|
||||
'nick' => 'fred',
|
||||
'name' => 'Fred Bloggs',
|
||||
]);
|
||||
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true,
|
||||
])->get('/admin/contacts/' . $contact->id . '/getavatar');
|
||||
|
||||
$response->assertRedirect('/admin/contacts/' . $contact->id . '/edit');
|
||||
}
|
||||
}
|
79
tests/Feature/Admin/NotesTest.php
Normal file
79
tests/Feature/Admin/NotesTest.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\SendWebMentions;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class NotesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_index_page()
|
||||
{
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true,
|
||||
])->get('/admin/notes');
|
||||
$response->assertViewIs('admin.notes.index');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
{
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true,
|
||||
])->get('/admin/notes/create');
|
||||
$response->assertViewIs('admin.notes.create');
|
||||
}
|
||||
|
||||
public function test_create_a_new_note()
|
||||
{
|
||||
$this->withSession([
|
||||
'loggedin' => true,
|
||||
])->post('/admin/notes', [
|
||||
'content' => 'A new test note',
|
||||
]);
|
||||
$this->assertDatabaseHas('notes', [
|
||||
'note' => 'A new test note',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_edit_page()
|
||||
{
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true,
|
||||
])->get('/admin/notes/1/edit');
|
||||
$response->assertViewIs('admin.notes.edit');
|
||||
}
|
||||
|
||||
public function test_edit_a_note()
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$this->withSession([
|
||||
'loggedin' => true,
|
||||
])->post('/admin/notes/1', [
|
||||
'_method' => 'PUT',
|
||||
'content' => 'An edited note',
|
||||
'webmentions' => true,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('notes', [
|
||||
'note' => 'An edited note',
|
||||
]);
|
||||
Queue::assertPushed(SendWebMentions::class);
|
||||
}
|
||||
|
||||
public function test_delete_note()
|
||||
{
|
||||
$this->withSession([
|
||||
'loggedin' => true,
|
||||
])->post('/admin/notes/1', [
|
||||
'_method' => 'DELETE',
|
||||
]);
|
||||
$this->assertSoftDeleted('notes', [
|
||||
'id' => '1',
|
||||
]);
|
||||
}
|
||||
}
|
67
tests/Feature/Admin/PlacesTest.php
Normal file
67
tests/Feature/Admin/PlacesTest.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class PlacesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_index_page()
|
||||
{
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true,
|
||||
])->get('/admin/places');
|
||||
$response->assertViewIs('admin.places.index');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
{
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true,
|
||||
])->get('/admin/places/create');
|
||||
$response->assertViewIs('admin.places.create');
|
||||
}
|
||||
|
||||
public function test_create_new_place()
|
||||
{
|
||||
$this->withSession([
|
||||
'loggedin' => true,
|
||||
])->post('/admin/places', [
|
||||
'name' => 'Test Place',
|
||||
'description' => 'A dummy place for feature tests',
|
||||
'latitude' => '1.23',
|
||||
'longitude' => '4.56',
|
||||
]);
|
||||
$this->assertDatabaseHas('places', [
|
||||
'name' => 'Test Place',
|
||||
'description' => 'A dummy place for feature tests',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_edit_page()
|
||||
{
|
||||
$response = $this->withSession([
|
||||
'loggedin' => true,
|
||||
])->get('/admin/places/1/edit');
|
||||
$response->assertViewIs('admin.places.edit');
|
||||
}
|
||||
|
||||
public function test_updating_a_place()
|
||||
{
|
||||
$this->withSession([
|
||||
'loggedin' => true,
|
||||
])->post('/admin/places/1', [
|
||||
'_method' => 'PUT',
|
||||
'name' => 'The Bridgewater',
|
||||
'description' => 'Who uses “Pub” anyway',
|
||||
'latitude' => '53.4983',
|
||||
'longitude' => '-2.3805',
|
||||
]);
|
||||
$this->assertDatabaseHas('places', [
|
||||
'name' => 'The Bridgewater',
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue