Rename the tests to pass phpcs checks

This commit is contained in:
Jonny Barnes 2021-03-17 18:38:18 +00:00
commit d5bbed1eac
52 changed files with 1316 additions and 1049 deletions

View file

@ -41,11 +41,13 @@ class SaveProfileImage implements ShouldQueue
{ {
try { try {
$author = $authorship->findAuthor($this->microformats); $author = $authorship->findAuthor($this->microformats);
} catch (AuthorshipParserException $e) { } catch (AuthorshipParserException) {
return; return null;
} }
$photo = Arr::get($author, 'properties.photo.0'); $photo = Arr::get($author, 'properties.photo.0');
$home = Arr::get($author, 'properties.url.0'); $home = Arr::get($author, 'properties.url.0');
//dont save pbs.twimg.com links //dont save pbs.twimg.com links
if ( if (
$photo $photo
@ -53,16 +55,18 @@ class SaveProfileImage implements ShouldQueue
&& parse_url($photo, PHP_URL_HOST) != 'twitter.com' && parse_url($photo, PHP_URL_HOST) != 'twitter.com'
) { ) {
$client = resolve(Client::class); $client = resolve(Client::class);
try { try {
$response = $client->get($photo); $response = $client->get($photo);
$image = $response->getBody(); $image = $response->getBody();
} catch (RequestException $e) { } catch (RequestException) {
// we are opening and reading the default image so that // we are opening and reading the default image so that
$default = public_path() . '/assets/profile-images/default-image'; $default = public_path() . '/assets/profile-images/default-image';
$handle = fopen($default, 'rb'); $handle = fopen($default, 'rb');
$image = fread($handle, filesize($default)); $image = fread($handle, filesize($default));
fclose($handle); fclose($handle);
} }
$path = public_path() . '/assets/profile-images/' . parse_url($home, PHP_URL_HOST) . '/image'; $path = public_path() . '/assets/profile-images/' . parse_url($home, PHP_URL_HOST) . '/image';
$parts = explode('/', $path); $parts = explode('/', $path);
$name = array_pop($parts); $name = array_pop($parts);

659
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,13 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false" <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupStaticAttributes="false" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php" bootstrap="vendor/autoload.php"
colors="true" colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer"
processIsolation="false"
stopOnFailure="true" stopOnFailure="true"
> >
<testsuites> <testsuites>

View file

@ -1,18 +1,16 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use App\Models\Note;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ActivityStreamTest extends TestCase class ActivityStreamTest extends TestCase
{ {
/** /** @test */
* Test request to homepage returns data for site owner. public function homepageRequestReturnsDataForSiteOwner(): void
*
* @return void
*/
public function test_homepage_returns_data_for_site_owner()
{ {
$response = $this->get('/', ['Accept' => 'application/activity+json']); $response = $this->get('/', ['Accept' => 'application/activity+json']);
$response->assertHeader('Content-Type', 'application/activity+json'); $response->assertHeader('Content-Type', 'application/activity+json');
@ -24,14 +22,10 @@ class ActivityStreamTest extends TestCase
]); ]);
} }
/** /** @test */
* Test request to a single note returns AS2.0 data. public function requestForNoteIncludesActivityStreamData(): void
*
* @return void
*/
public function test_single_note_returns_as_data()
{ {
$note = \App\Models\Note::find(11); $note = Note::find(11);
$response = $this->get('/notes/B', ['Accept' => 'application/activity+json']); $response = $this->get('/notes/B', ['Accept' => 'application/activity+json']);
$response->assertHeader('Content-Type', 'application/activity+json'); $response->assertHeader('Content-Type', 'application/activity+json');
$response->assertJson([ $response->assertJson([

View file

@ -1,16 +1,19 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature\Admin; namespace Tests\Feature\Admin;
use Tests\TestCase;
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class AdminHomeControllerTest extends TestCase class AdminHomeControllerTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_admin_homepage() /** @test */
public function adminHomepageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();

View file

@ -1,24 +1,29 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature\Admin; namespace Tests\Feature\Admin;
use Tests\TestCase; use Tests\TestCase;
class AdminTest extends TestCase class AdminTest extends TestCase
{ {
public function test_admin_page_redirects_to_login() /** @test */
public function adminPageRedirectsUnauthedUsersToLoginPage(): void
{ {
$response = $this->get('/admin'); $response = $this->get('/admin');
$response->assertRedirect('/login'); $response->assertRedirect('/login');
} }
public function test_login_page() /** @test */
public function loginPageLoads(): void
{ {
$response = $this->get('/login'); $response = $this->get('/login');
$response->assertViewIs('login'); $response->assertViewIs('login');
} }
public function test_attempt_login_with_bad_credentials() /** @test */
public function loginAttemptWithBadCredentialsFails(): void
{ {
$response = $this->post('/login', [ $response = $this->post('/login', [
'username' => 'bad', 'username' => 'bad',

View file

@ -1,17 +1,21 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature\Admin; namespace Tests\Feature\Admin;
use Tests\TestCase;
use App\Models\User; use App\Models\User;
use Faker\Factory;
use Illuminate\Http\UploadedFile; use Illuminate\Http\UploadedFile;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class ArticlesTest extends TestCase class ArticlesTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_index_page() /** @test */
public function adminArticlesPageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -20,7 +24,8 @@ class ArticlesTest extends TestCase
$response->assertSeeText('Select article to edit:'); $response->assertSeeText('Select article to edit:');
} }
public function test_create_page() /** @test */
public function adminCanLoadFormToCreateArticle(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -29,7 +34,8 @@ class ArticlesTest extends TestCase
$response->assertSeeText('Title (URL)'); $response->assertSeeText('Title (URL)');
} }
public function test_create_new_article() /** @test */
public function admiNCanCreateNewArticle(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -41,10 +47,11 @@ class ArticlesTest extends TestCase
$this->assertDatabaseHas('articles', ['title' => 'Test Title']); $this->assertDatabaseHas('articles', ['title' => 'Test Title']);
} }
public function test_create_new_article_with_upload() /** @test */
public function adminCanCreateNewArticleWithFile(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
$faker = \Faker\Factory::create(); $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')) {
fwrite($fh, $text); fwrite($fh, $text);
@ -65,7 +72,8 @@ class ArticlesTest extends TestCase
]); ]);
} }
public function test_see_edit_form() /** @test */
public function articleCanLoadFormToEditArticle(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -74,7 +82,8 @@ class ArticlesTest extends TestCase
$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() /** @test */
public function adminCanEditArticle(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -90,7 +99,8 @@ class ArticlesTest extends TestCase
]); ]);
} }
public function test_delete_article() /** @test */
public function adminCanDeleteArticle(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();

View file

@ -1,16 +1,19 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature\Admin; namespace Tests\Feature\Admin;
use Tests\TestCase;
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class ClientsTest extends TestCase class ClientsTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_index_page() /** @test */
public function clientsPageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -19,7 +22,8 @@ class ClientsTest extends TestCase
$response->assertSeeText('Clients'); $response->assertSeeText('Clients');
} }
public function test_create_page() /** @test */
public function adminCanLoadFormToCreateClient(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -28,7 +32,8 @@ class ClientsTest extends TestCase
$response->assertSeeText('New Client'); $response->assertSeeText('New Client');
} }
public function test_create_new_client() /** @test */
public function adminCanCreateNewClient(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -43,7 +48,8 @@ class ClientsTest extends TestCase
]); ]);
} }
public function test_see_edit_form() /** @test */
public function adminCanLoadEditFormForClient(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -52,7 +58,8 @@ class ClientsTest extends TestCase
$response->assertSee('https://jbl5.dev/notes/new'); $response->assertSee('https://jbl5.dev/notes/new');
} }
public function test_edit_client() /** @test */
public function adminCanEditClient(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -68,7 +75,8 @@ class ClientsTest extends TestCase
]); ]);
} }
public function test_delete_client() /** @test */
public function adminCanDeleteClient(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();

View file

@ -1,16 +1,18 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature\Admin; namespace Tests\Feature\Admin;
use Tests\TestCase;
use App\Models\User; use App\Models\User;
use GuzzleHttp\Client;
use App\Models\Contact; use App\Models\Contact;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use Illuminate\Http\UploadedFile;
use GuzzleHttp\Handler\MockHandler;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Http\UploadedFile;
use Tests\TestCase;
class ContactsTest extends TestCase class ContactsTest extends TestCase
{ {
@ -25,7 +27,8 @@ class ContactsTest extends TestCase
parent::tearDown(); parent::tearDown();
} }
public function test_index_page() /** @test */
public function contactIndexPageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -33,7 +36,8 @@ class ContactsTest extends TestCase
$response->assertViewIs('admin.contacts.index'); $response->assertViewIs('admin.contacts.index');
} }
public function test_create_page() /** @test */
public function contactCreatePageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -41,7 +45,8 @@ class ContactsTest extends TestCase
$response->assertViewIs('admin.contacts.create'); $response->assertViewIs('admin.contacts.create');
} }
public function test_create_new_contact() /** @test */
public function adminCanCreateNewContact(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -57,7 +62,8 @@ class ContactsTest extends TestCase
]); ]);
} }
public function test_see_edit_form() /** @test */
public function adminCanSeeFormToEditContact(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -65,7 +71,8 @@ class ContactsTest extends TestCase
$response->assertViewIs('admin.contacts.edit'); $response->assertViewIs('admin.contacts.edit');
} }
public function test_update_contact_no_uploaded_avatar() /** @test */
public function adminCanUpdateContact(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -82,7 +89,8 @@ class ContactsTest extends TestCase
]); ]);
} }
public function test_edit_contact_with_uploaded_avatar() /** @test */
public function adminCanEditContactAndUploadAvatar(): void
{ {
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';
@ -103,7 +111,8 @@ class ContactsTest extends TestCase
); );
} }
public function test_delete_contact() /** @test */
public function adminCanDeleteContact(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -115,13 +124,14 @@ class ContactsTest extends TestCase
]); ]);
} }
public function test_get_avatar_method() /** @test */
public function adminCanTriggerRetrievalOfRemoteAvatar(): void
{ {
$html = <<<HTML $html = <<<HTML
<div class="h-card"> <div class="h-card">
<img class="u-photo" src="http://tantek.com/tantek.png"> <img class="u-photo" alt="" src="http://tantek.com/tantek.png">
</div> </div>
HTML; HTML;
$file = fopen(__DIR__ . '/../../aaron.png', 'r'); $file = fopen(__DIR__ . '/../../aaron.png', 'r');
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['Content-Type' => 'text/html'], $html), new Response(200, ['Content-Type' => 'text/html'], $html),
@ -140,7 +150,8 @@ HTML;
); );
} }
public function test_get_avatar_method_redirects_with_failed_homepage() /** @test */
public function gettingRemoteAvatarFailsGracefullyWithRemoteNotFound(): void
{ {
$mock = new MockHandler([ $mock = new MockHandler([
new Response(404), new Response(404),
@ -155,13 +166,14 @@ HTML;
$response->assertRedirect('/admin/contacts/1/edit'); $response->assertRedirect('/admin/contacts/1/edit');
} }
public function test_get_avatar_method_redirects_with_failed_avatar_download() /** @test */
public function gettingRemoteAvatarFailsGracefullyWithRemoteError(): void
{ {
$html = <<<HTML $html = <<<HTML
<div class="h-card"> <div class="h-card">
<img class="u-photo" src="http://tantek.com/tantek.png"> <img class="u-photo" src="http://tantek.com/tantek.png">
</div> </div>
HTML; HTML;
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['Content-Type' => 'text/html'], $html), new Response(200, ['Content-Type' => 'text/html'], $html),
new Response(404), new Response(404),
@ -176,7 +188,8 @@ HTML;
$response->assertRedirect('/admin/contacts/1/edit'); $response->assertRedirect('/admin/contacts/1/edit');
} }
public function test_get_avatar_for_contact_with_no_homepage() /** @test */
public function gettingRemoteAvatarFailsGracefullyForContactWithNoHompage(): void
{ {
$contact = Contact::create([ $contact = Contact::create([
'nick' => 'fred', 'nick' => 'fred',

View file

@ -1,19 +1,22 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature\Admin; namespace Tests\Feature\Admin;
use App\Models\User;
use Tests\TestCase;
use App\Models\Like;
use App\Jobs\ProcessLike; use App\Jobs\ProcessLike;
use App\Models\Like;
use App\Models\User;
use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Queue;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class LikesTest extends TestCase class LikesTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_index_page() /** @test */
public function likesPageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -22,7 +25,8 @@ class LikesTest extends TestCase
$response->assertSeeText('Likes'); $response->assertSeeText('Likes');
} }
public function test_create_page() /** @test */
public function likeCreateFormLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -31,7 +35,8 @@ class LikesTest extends TestCase
$response->assertSeeText('New Like'); $response->assertSeeText('New Like');
} }
public function test_create_new_like() /** @test */
public function adminCanCreateLike(): void
{ {
Queue::fake(); Queue::fake();
$user = User::factory()->make(); $user = User::factory()->make();
@ -46,7 +51,8 @@ class LikesTest extends TestCase
Queue::assertPushed(ProcessLike::class); Queue::assertPushed(ProcessLike::class);
} }
public function test_see_edit_form() /** @test */
public function likeEditFormLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -55,7 +61,8 @@ class LikesTest extends TestCase
$response->assertSee('Edit Like'); $response->assertSee('Edit Like');
} }
public function test_edit_like() /** @test */
public function adminCanEditLike(): void
{ {
Queue::fake(); Queue::fake();
$user = User::factory()->make(); $user = User::factory()->make();
@ -71,7 +78,8 @@ class LikesTest extends TestCase
Queue::assertPushed(ProcessLike::class); Queue::assertPushed(ProcessLike::class);
} }
public function test_delete_like() /** @test */
public function adminCanDeleteLike(): void
{ {
$like = Like::find(1); $like = Like::find(1);
$url = $like->url; $url = $like->url;

View file

@ -1,18 +1,21 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature\Admin; namespace Tests\Feature\Admin;
use App\Models\User;
use Tests\TestCase;
use App\Jobs\SendWebMentions; use App\Jobs\SendWebMentions;
use Illuminate\Support\Facades\Queue; use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class NotesTest extends TestCase class NotesTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_index_page() /** @test */
public function notesPageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -20,7 +23,8 @@ class NotesTest extends TestCase
$response->assertViewIs('admin.notes.index'); $response->assertViewIs('admin.notes.index');
} }
public function test_create_page() /** @test */
public function noteCreatePageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -28,7 +32,8 @@ class NotesTest extends TestCase
$response->assertViewIs('admin.notes.create'); $response->assertViewIs('admin.notes.create');
} }
public function test_create_a_new_note() /** @test */
public function adminCanCreateNewNote(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -40,7 +45,8 @@ class NotesTest extends TestCase
]); ]);
} }
public function test_edit_page() /** @test */
public function noteEditFormLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -48,7 +54,8 @@ class NotesTest extends TestCase
$response->assertViewIs('admin.notes.edit'); $response->assertViewIs('admin.notes.edit');
} }
public function test_edit_a_note() /** @test */
public function adminCanEditNote(): void
{ {
Queue::fake(); Queue::fake();
$user = User::factory()->make(); $user = User::factory()->make();
@ -65,7 +72,8 @@ class NotesTest extends TestCase
Queue::assertPushed(SendWebMentions::class); Queue::assertPushed(SendWebMentions::class);
} }
public function test_delete_note() /** @test */
public function adminCanDeleteNote(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();

View file

@ -1,16 +1,19 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature\Admin; namespace Tests\Feature\Admin;
use App\Models\User; use App\Models\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class PlacesTest extends TestCase class PlacesTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_index_page() /** @test */
public function placesPageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -18,7 +21,8 @@ class PlacesTest extends TestCase
$response->assertViewIs('admin.places.index'); $response->assertViewIs('admin.places.index');
} }
public function test_create_page() /** @test */
public function createPlacePageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -26,7 +30,8 @@ class PlacesTest extends TestCase
$response->assertViewIs('admin.places.create'); $response->assertViewIs('admin.places.create');
} }
public function test_create_new_place() /** @test */
public function adminCanCreateNewPlace(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -42,7 +47,8 @@ class PlacesTest extends TestCase
]); ]);
} }
public function test_edit_page() /** @test */
public function editPlacePageLoads(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();
@ -50,7 +56,8 @@ class PlacesTest extends TestCase
$response->assertViewIs('admin.places.edit'); $response->assertViewIs('admin.places.edit');
} }
public function test_updating_a_place() /** @test */
public function adminCanUpdatePlace(): void
{ {
$user = User::factory()->make(); $user = User::factory()->make();

View file

@ -1,45 +1,50 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ArticlesTest extends TestCase class ArticlesTest extends TestCase
{ {
public function test_articles_page() /** @test */
public function articlesPageLoads(): void
{ {
$response = $this->get('/blog'); $response = $this->get('/blog');
$response->assertViewIs('articles.index'); $response->assertViewIs('articles.index');
} }
public function test_single_article() /** @test */
public function singleArticlePageLoads()
{ {
$response = $this->get('/blog/' . date('Y') . '/' . date('m') . '/some-code-i-did'); $response = $this->get('/blog/' . date('Y') . '/' . date('m') . '/some-code-i-did');
$response->assertViewIs('articles.show'); $response->assertViewIs('articles.show');
} }
public function test_wrong_date_redirects() /** @test */
public function wrongDateInUrlRedirectsToCorrectDate()
{ {
$response = $this->get('/blog/1900/01/some-code-i-did'); $response = $this->get('/blog/1900/01/some-code-i-did');
$response->assertRedirect('/blog/' . date('Y') . '/' . date('m') . '/some-code-i-did'); $response->assertRedirect('/blog/' . date('Y') . '/' . date('m') . '/some-code-i-did');
} }
public function test_redirect_for_id() /** @test */
public function oldUrlsWithIdAreRedirected()
{ {
$response = $this->get('/blog/s/2'); $response = $this->get('/blog/s/2');
$response->assertRedirect('/blog/' . date('Y') . '/' . date('m') . '/some-code-i-did'); $response->assertRedirect('/blog/' . date('Y') . '/' . date('m') . '/some-code-i-did');
} }
/** @test */ /** @test */
public function unknownSlugGives404() public function unknownSlugGetsNotFoundResponse()
{ {
$response = $this->get('/blog/' . date('Y') . '/' . date('m') . '/unknown-slug'); $response = $this->get('/blog/' . date('Y') . '/' . date('m') . '/unknown-slug');
$response->assertNotFound(); $response->assertNotFound();
} }
/** @test */ /** @test */
public function unknownArticleIdGives404() public function unknownArticleIdGetsNotFoundResponse()
{ {
$response = $this->get('/blog/s/22'); $response = $this->get('/blog/s/22');
$response->assertNotFound(); $response->assertNotFound();

View file

@ -1,31 +1,36 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase;
use Tests\TestToken;
use App\Jobs\ProcessBookmark; use App\Jobs\ProcessBookmark;
use Illuminate\Support\Facades\Queue;
use App\Jobs\SyndicateBookmarkToTwitter; use App\Jobs\SyndicateBookmarkToTwitter;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
use Tests\TestToken;
class BookmarksTest extends TestCase class BookmarksTest extends TestCase
{ {
use DatabaseTransactions, TestToken; use DatabaseTransactions, TestToken;
public function test_bookmarks_page() /** @test */
public function bookmarksPageLoadsWithoutError(): void
{ {
$response = $this->get('/bookmarks'); $response = $this->get('/bookmarks');
$response->assertViewIs('bookmarks.index'); $response->assertViewIs('bookmarks.index');
} }
public function test_single_bookmark_page() /** @test */
public function singleBookmarkPageLoadsWithoutError(): void
{ {
$response = $this->get('/bookmarks/1'); $response = $this->get('/bookmarks/1');
$response->assertViewIs('bookmarks.show'); $response->assertViewIs('bookmarks.show');
} }
public function test_browsershot_job_dispatches_when_bookmark_added_http_post_syntax() /** @test */
public function whenBookmarkIsAddedUsingHttpSyntaxCheckJobToTakeScreenshotIsInvoked(): void
{ {
Queue::fake(); Queue::fake();
@ -46,7 +51,8 @@ class BookmarksTest extends TestCase
$this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']); $this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']);
} }
public function test_browsershot_job_dispatches_when_bookmark_added_json_syntax() /** @test */
public function whenBookmarkIsAddedUsingJsonSyntaxCheckJobToTakeScreenshotIsInvoked(): void
{ {
Queue::fake(); Queue::fake();
@ -69,7 +75,8 @@ class BookmarksTest extends TestCase
$this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']); $this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']);
} }
public function test_single_twitter_syndication_target_causes_job_dispatch_http_post_syntax() /** @test */
public function whenTheBookmarkIsMarkedForPostingToTwitterCheckWeInvokeTheCorrectJob(): void
{ {
Queue::fake(); Queue::fake();
@ -88,7 +95,8 @@ class BookmarksTest extends TestCase
$this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']); $this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']);
} }
public function test_tags_created_with_new_bookmark() /** @test */
public function whenTheBookmarkIsCreatedCheckNecessaryTagsAreAlsoCreated(): void
{ {
Queue::fake(); Queue::fake();

View file

@ -1,12 +1,15 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase; use Tests\TestCase;
class BridgyPosseTest extends TestCase class BridgyPosseTest extends TestCase
{ {
public function test_bridgy_twitter_content() /** @test */
public function notesWeWantCopiedToTwitterShouldHaveNecessaryMarkup(): void
{ {
$response = $this->get('/notes/4'); $response = $this->get('/notes/4');

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase; use Tests\TestCase;
@ -7,9 +9,9 @@ use Tests\TestCase;
class CSPHeadersTest extends TestCase class CSPHeadersTest extends TestCase
{ {
/** @test */ /** @test */
public function check_csp_headers_test() public function checkCspHeadersArePresent(): void
{ {
$response = $this->get('/'); $response = $this->get('/blog');
$response->assertHeader('Content-Security-Policy'); $response->assertHeader('Content-Security-Policy');
$response->assertHeader('Report-To'); $response->assertHeader('Report-To');
} }

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase; use Tests\TestCase;
@ -9,9 +11,9 @@ class ContactsTest extends TestCase
/** /**
* Check the `/contacts` page gives a good response. * Check the `/contacts` page gives a good response.
* *
* @return void * @test
*/ */
public function test_contacts_page() public function contactsPageLoadsWithoutError(): void
{ {
$response = $this->get('/contacts'); $response = $this->get('/contacts');
$response->assertStatus(200); $response->assertStatus(200);
@ -20,9 +22,9 @@ class ContactsTest extends TestCase
/** /**
* Test an individual contact page with default profile image. * Test an individual contact page with default profile image.
* *
* @return void * @test
*/ */
public function test_contact_page_with_default_pic() public function contactPageShouldFallbackToDefaultProfilePic(): void
{ {
$response = $this->get('/contacts/tantek'); $response = $this->get('/contacts/tantek');
$response->assertViewHas('image', '/assets/profile-images/default-image'); $response->assertViewHas('image', '/assets/profile-images/default-image');
@ -31,16 +33,16 @@ class ContactsTest extends TestCase
/** /**
* Test an individual contact page with a specific profile image. * Test an individual contact page with a specific profile image.
* *
* @return void * @test
*/ */
public function test_contact_page_with_specific_pic() public function contactPageShouldUseSpecificProfilePicIfPresent(): void
{ {
$response = $this->get('/contacts/aaron'); $response = $this->get('/contacts/aaron');
$response->assertViewHas('image', '/assets/profile-images/aaronparecki.com/image'); $response->assertViewHas('image', '/assets/profile-images/aaronparecki.com/image');
} }
/** @test */ /** @test */
public function unknownContactGives404() public function unknownContactReturnsNotFoundResponse(): void
{ {
$response = $this->get('/contacts/unknown'); $response = $this->get('/contacts/unknown');
$response->assertNotFound(); $response->assertNotFound();

View file

@ -1,18 +1,18 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase; use Tests\TestCase;
use Tests\TestToken; use Tests\TestToken;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class CorsHeadersTest extends TestCase class CorsHeadersTest extends TestCase
{ {
use TestToken; use TestToken;
/** @test */ /** @test */
public function check_cors_headers_on_media_endpoint_options_request() public function checkCorsHeadersOnMediaEndpoint(): void
{ {
$response = $this->call( $response = $this->call(
'OPTIONS', 'OPTIONS',
@ -26,9 +26,9 @@ class CorsHeadersTest extends TestCase
} }
/** @test */ /** @test */
public function check_missing_on_other_route() public function checkForNoCorsHeaderOnNonMediaEndpointLinks(): void
{ {
$response = $this->get('/'); $response = $this->get('/blog');
$response->assertHeaderMissing('Access-Control-Allow-Origin'); $response->assertHeaderMissing('Access-Control-Allow-Origin');
} }
} }

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase; use Tests\TestCase;
@ -9,38 +11,41 @@ class FeedsTest extends TestCase
/** /**
* Test the blog RSS feed. * Test the blog RSS feed.
* *
* @return void * @test
*/ */
public function test_blog_rss_feed() public function blogRssFeedIsPresent(): void
{ {
$response = $this->get('/blog/feed.rss'); $response = $this->get('/blog/feed.rss');
$response->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8'); $response->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8');
$response->assertOk();
} }
/** /**
* Test the notes RSS feed. * Test the notes RSS feed.
* *
* @return void * @test
*/ */
public function test_notes_rss_feed() public function notesRssFeedIsPresent(): void
{ {
$response = $this->get('/notes/feed.rss'); $response = $this->get('/notes/feed.rss');
$response->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8'); $response->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8');
$response->assertOk();
} }
/** /**
* Test the blog RSS feed. * Test the blog RSS feed.
* *
* @return void * @test
*/ */
public function test_blog_atom_feed() public function blogAtomFeedIsPresent(): void
{ {
$response = $this->get('/blog/feed.atom'); $response = $this->get('/blog/feed.atom');
$response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8'); $response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8');
$response->assertOk();
} }
/** @test */ /** @test */
public function blog_jf2_feed() public function blogJf2FeedIsPresent(): void
{ {
$response = $this->get('/blog/feed.jf2'); $response = $this->get('/blog/feed.jf2');
$response->assertHeader('Content-Type', 'application/jf2feed+json'); $response->assertHeader('Content-Type', 'application/jf2feed+json');
@ -63,38 +68,41 @@ class FeedsTest extends TestCase
/** /**
* Test the notes RSS feed. * Test the notes RSS feed.
* *
* @return void * @test
*/ */
public function test_notes_atom_feed() public function notesAtomFeedIsPresent(): void
{ {
$response = $this->get('/notes/feed.atom'); $response = $this->get('/notes/feed.atom');
$response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8'); $response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8');
$response->assertOk();
} }
/** /**
* Test the blog JSON feed. * Test the blog JSON feed.
* *
* @return void * @test
*/ */
public function test_blog_json_feed() public function blogJsonFeedIsPresent(): void
{ {
$response = $this->get('/blog/feed.json'); $response = $this->get('/blog/feed.json');
$response->assertHeader('Content-Type', 'application/json'); $response->assertHeader('Content-Type', 'application/json');
$response->assertOk();
} }
/** /**
* Test the notes JSON feed. * Test the notes JSON feed.
* *
* @return void * @test
*/ */
public function test_notes_json_feed() public function notesJsonFeedIsPresent(): void
{ {
$response = $this->get('/notes/feed.json'); $response = $this->get('/notes/feed.json');
$response->assertHeader('Content-Type', 'application/json'); $response->assertHeader('Content-Type', 'application/json');
$response->assertOk();
} }
/** @test */ /** @test */
public function notes_jf2_feed() public function notesJf2FeedIsPresent(): void
{ {
$response = $this->get('/notes/feed.jf2'); $response = $this->get('/notes/feed.jf2');
$response->assertHeader('Content-Type', 'application/jf2feed+json'); $response->assertHeader('Content-Type', 'application/jf2feed+json');
@ -118,9 +126,9 @@ class FeedsTest extends TestCase
* Each JSON feed item must have one of `content_text` or `content_html`, * Each JSON feed item must have one of `content_text` or `content_html`,
* and whichever one they have can’t be `null`. * and whichever one they have can’t be `null`.
* *
* @return void * @test
*/ */
public function test_json_feed_has_one_content_attribute_and_it_isnt_null() public function jsonFeedsHaveRequiredAttributes(): void
{ {
$response = $this->get('/notes/feed.json'); $response = $this->get('/notes/feed.json');
$data = json_decode($response->content()); $data = json_decode($response->content());

View file

@ -1,40 +1,43 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Codebird\Codebird;
use Queue;
use stdClass;
use Tests\TestCase;
use App\Models\Like;
use Tests\TestToken;
use GuzzleHttp\Client;
use App\Jobs\ProcessLike; use App\Jobs\ProcessLike;
use Lcobucci\JWT\Builder; use App\Models\Like;
use Codebird\Codebird;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Jonnybarnes\WebmentionsParser\Authorship;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Queue;
use Jonnybarnes\WebmentionsParser\Authorship;
use Tests\TestCase;
use Tests\TestToken;
class LikesTest extends TestCase class LikesTest extends TestCase
{ {
use DatabaseTransactions, TestToken; use DatabaseTransactions;
use TestToken;
public function test_likes_page() /** @test */
public function likesPageHasCorrectView(): void
{ {
$response = $this->get('/likes'); $response = $this->get('/likes');
$response->assertViewIs('likes.index'); $response->assertViewIs('likes.index');
} }
public function test_single_like_page() /** @test */
public function singleLikePageHasCorrectView(): void
{ {
$response = $this->get('/likes/1'); $response = $this->get('/likes/1');
$response->assertViewIs('likes.show'); $response->assertViewIs('likes.show');
} }
public function test_like_micropub_json_request() /** @test */
public function checkLikeCreatedFromMicropubApiRequests(): void
{ {
Queue::fake(); Queue::fake();
@ -53,7 +56,8 @@ class LikesTest extends TestCase
$this->assertDatabaseHas('likes', ['url' => 'https://example.org/blog-post']); $this->assertDatabaseHas('likes', ['url' => 'https://example.org/blog-post']);
} }
public function test_like_micropub_form_request() /** @test */
public function checkLikeCreatedFromMicropubWebRequests(): void
{ {
Queue::fake(); Queue::fake();
@ -70,7 +74,8 @@ class LikesTest extends TestCase
$this->assertDatabaseHas('likes', ['url' => 'https://example.org/blog-post']); $this->assertDatabaseHas('likes', ['url' => 'https://example.org/blog-post']);
} }
public function test_process_like_job_with_simple_author() /** @test */
public function likeWithSimpleAuthor(): void
{ {
$like = new Like(); $like = new Like();
$like->url = 'http://example.org/note/id'; $like->url = 'http://example.org/note/id';
@ -80,17 +85,18 @@ class LikesTest extends TestCase
$job = new ProcessLike($like); $job = new ProcessLike($like);
$content = <<<END $content = <<<END
<html> <html>
<body> <body>
<div class="h-entry"> <div class="h-entry">
<div class="e-content"> <div class="e-content">
A post that I like. A post that I like.
</div> </div>
by <span class="p-author">Fred Bloggs</span> by <span class="p-author">Fred Bloggs</span>
</div> </div>
</body> </body>
</html> </html>
END; END;
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, [], $content), new Response(200, [], $content),
new Response(200, [], $content), new Response(200, [], $content),
@ -107,7 +113,8 @@ END;
$this->assertEquals('Fred Bloggs', Like::find($id)->author_name); $this->assertEquals('Fred Bloggs', Like::find($id)->author_name);
} }
public function test_process_like_job_with_h_card() /** @test */
public function likeWithHCard(): void
{ {
$like = new Like(); $like = new Like();
$like->url = 'http://example.org/note/id'; $like->url = 'http://example.org/note/id';
@ -117,21 +124,22 @@ END;
$job = new ProcessLike($like); $job = new ProcessLike($like);
$content = <<<END $content = <<<END
<html> <html>
<body> <body>
<div class="h-entry"> <div class="h-entry">
<div class="e-content"> <div class="e-content">
A post that I like. A post that I like.
</div> </div>
by by
<div class="p-author h-card"> <div class="p-author h-card">
<span class="p-name">Fred Bloggs</span> <span class="p-name">Fred Bloggs</span>
<a class="u-url" href="https://fredd.blog/gs"></a> <a class="u-url" href="https://fredd.blog/gs"></a>
</div> </div>
</div> </div>
</body> </body>
</html> </html>
END; END;
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, [], $content), new Response(200, [], $content),
new Response(200, [], $content), new Response(200, [], $content),
@ -148,7 +156,8 @@ END;
$this->assertEquals('Fred Bloggs', Like::find($id)->author_name); $this->assertEquals('Fred Bloggs', Like::find($id)->author_name);
} }
public function test_process_like_job_without_mf2() /** @test */
public function likeWithoutMicroformats(): void
{ {
$like = new Like(); $like = new Like();
$like->url = 'http://example.org/note/id'; $like->url = 'http://example.org/note/id';
@ -158,14 +167,15 @@ END;
$job = new ProcessLike($like); $job = new ProcessLike($like);
$content = <<<END $content = <<<END
<html> <html>
<body> <body>
<div> <div>
I liked a post I liked a post
</div> </div>
</body> </body>
</html> </html>
END; END;
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, [], $content), new Response(200, [], $content),
new Response(200, [], $content), new Response(200, [], $content),
@ -182,7 +192,8 @@ END;
$this->assertNull(Like::find($id)->author_name); $this->assertNull(Like::find($id)->author_name);
} }
public function test_process_like_that_is_tweet() /** @test */
public function likeThatIsATweet(): void
{ {
$like = new Like(); $like = new Like();
$like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200'; $like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200';
@ -202,10 +213,11 @@ END;
return $client; return $client;
}); });
$info = new stdClass(); $info = (object) [
$info->author_name = 'Jonny Barnes'; 'author_name' => 'Jonny Barnes',
$info->author_url = 'https://twitter.com/jonnybarnes'; 'author_url' => 'https://twitter.com/jonnybarnes',
$info->html = '<div>HTML of the tweet embed</div>'; 'html' => '<div>HTML of the tweet embed</div>',
];
$codebirdMock = $this->getMockBuilder(Codebird::class) $codebirdMock = $this->getMockBuilder(Codebird::class)
->addMethods(['statuses_oembed']) ->addMethods(['statuses_oembed'])
->getMock(); ->getMock();
@ -221,7 +233,7 @@ END;
} }
/** @test */ /** @test */
public function unknownLikeGives404() public function unknownLikeGivesNotFoundResponse(): void
{ {
$response = $this->get('/likes/202'); $response = $this->get('/likes/202');
$response->assertNotFound(); $response->assertNotFound();

Some files were not shown because too many files have changed in this diff Show more