Rename the tests to pass phpcs checks

This commit is contained in:
Jonny Barnes 2021-03-17 18:38:18 +00:00
parent 3946e9aac4
commit d5bbed1eac
52 changed files with 1329 additions and 1062 deletions

View file

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

View file

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

View file

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

View file

@ -1,17 +1,21 @@
<?php
declare(strict_types=1);
namespace Tests\Feature\Admin;
use Tests\TestCase;
use App\Models\User;
use Faker\Factory;
use Illuminate\Http\UploadedFile;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class ArticlesTest extends TestCase
{
use DatabaseTransactions;
public function test_index_page()
/** @test */
public function adminArticlesPageLoads(): void
{
$user = User::factory()->make();
@ -20,7 +24,8 @@ class ArticlesTest extends TestCase
$response->assertSeeText('Select article to edit:');
}
public function test_create_page()
/** @test */
public function adminCanLoadFormToCreateArticle(): void
{
$user = User::factory()->make();
@ -29,7 +34,8 @@ class ArticlesTest extends TestCase
$response->assertSeeText('Title (URL)');
}
public function test_create_new_article()
/** @test */
public function admiNCanCreateNewArticle(): void
{
$user = User::factory()->make();
@ -41,10 +47,11 @@ class ArticlesTest extends TestCase
$this->assertDatabaseHas('articles', ['title' => 'Test Title']);
}
public function test_create_new_article_with_upload()
/** @test */
public function adminCanCreateNewArticleWithFile(): void
{
$user = User::factory()->make();
$faker = \Faker\Factory::create();
$faker = Factory::create();
$text = $faker->text;
if ($fh = fopen(sys_get_temp_dir() . '/article.md', 'w')) {
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();
@ -74,7 +82,8 @@ class ArticlesTest extends TestCase
$response->assertSeeText('This is *my* new blog. It uses `Markdown`.');
}
public function test_edit_article()
/** @test */
public function adminCanEditArticle(): void
{
$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();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
@ -7,9 +9,9 @@ use Tests\TestCase;
class CSPHeadersTest extends TestCase
{
/** @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('Report-To');
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
@ -9,9 +11,9 @@ class ContactsTest extends TestCase
/**
* 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->assertStatus(200);
@ -20,9 +22,9 @@ class ContactsTest extends TestCase
/**
* 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->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.
*
* @return void
* @test
*/
public function test_contact_page_with_specific_pic()
public function contactPageShouldUseSpecificProfilePicIfPresent(): void
{
$response = $this->get('/contacts/aaron');
$response->assertViewHas('image', '/assets/profile-images/aaronparecki.com/image');
}
/** @test */
public function unknownContactGives404()
public function unknownContactReturnsNotFoundResponse(): void
{
$response = $this->get('/contacts/unknown');
$response->assertNotFound();

View file

@ -1,18 +1,18 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
use Tests\TestToken;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class CorsHeadersTest extends TestCase
{
use TestToken;
/** @test */
public function check_cors_headers_on_media_endpoint_options_request()
public function checkCorsHeadersOnMediaEndpoint(): void
{
$response = $this->call(
'OPTIONS',
@ -26,9 +26,9 @@ class CorsHeadersTest extends TestCase
}
/** @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');
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
@ -9,38 +11,41 @@ class FeedsTest extends TestCase
/**
* 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->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8');
$response->assertOk();
}
/**
* 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->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8');
$response->assertOk();
}
/**
* 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->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8');
$response->assertOk();
}
/** @test */
public function blog_jf2_feed()
public function blogJf2FeedIsPresent(): void
{
$response = $this->get('/blog/feed.jf2');
$response->assertHeader('Content-Type', 'application/jf2feed+json');
@ -63,38 +68,41 @@ class FeedsTest extends TestCase
/**
* 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->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8');
$response->assertOk();
}
/**
* 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->assertHeader('Content-Type', 'application/json');
$response->assertOk();
}
/**
* 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->assertHeader('Content-Type', 'application/json');
$response->assertOk();
}
/** @test */
public function notes_jf2_feed()
public function notesJf2FeedIsPresent(): void
{
$response = $this->get('/notes/feed.jf2');
$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`,
* and whichever one they have cant 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');
$data = json_decode($response->content());

View file

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

View file

@ -1,41 +1,33 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Faker\Factory;
use App\Jobs\{SendWebMentions, SyndicateNoteToTwitter};
use App\Models\{Media, Place};
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
use Tests\TestToken;
use App\Jobs\SendWebMentions;
use App\Models\{Media, Place};
use App\Jobs\SyndicateNoteToTwitter;
use Illuminate\Support\Facades\Queue;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class MicropubControllerTest extends TestCase
{
use DatabaseTransactions;
use TestToken;
/**
* Test a GET request for the micropub endpoint without a token gives a
* 400 response. Also check the error message.
*
* @return void
*/
public function test_micropub_get_request_without_token_returns_401_response()
/** @test */
public function micropubGetRequestWithoutTokenReturnsErrorResponse(): void
{
$response = $this->get('/api/post');
$response->assertStatus(401);
$response->assertJsonFragment(['error_description' => 'No access token was provided in the request']);
}
/**
* Test a GET request for the micropub endpoint without a valid token gives
* a 400 response. Also check the error message.
*
* @return void
*/
public function test_micropub_get_request_without_valid_token_returns_400_response()
/** @test */
public function micropubGetRequestWithoutValidTokenReturnsErrorResponse(): void
{
$response = $this->get('/api/post', ['HTTP_Authorization' => 'Bearer abc123']);
$response->assertStatus(400);
@ -44,80 +36,59 @@ class MicropubControllerTest extends TestCase
/**
* Test a GET request for the micropub endpoint with a valid token gives a
* 200 response. Check token information is returned in the response.
* 200 response. Check token information is also returned in the response.
*
* @return void
* @test
*/
public function test_micropub_get_request_with_valid_token_returns_200_response()
public function micropubGetRequestWithValidTokenReturnsOkResponse(): void
{
$response = $this->get('/api/post', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertStatus(200);
$response->assertJsonFragment(['response' => 'token']);
}
/**
* Test a GET request for syndication targets.
*
* @return void
*/
public function test_micropub_get_request_for_syndication_targets()
/** @test */
public function micropubClientsCanRequestSyndicationTargets(): void
{
$response = $this->get('/api/post?q=syndicate-to', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertJsonFragment(['uid' => 'https://twitter.com/jonnybarnes']);
}
/**
* Test a request for places.
*
* @return void
*/
public function test_micropub_get_request_for_nearby_places()
{
$response = $this->get('/api/post?q=geo:53.5,-2.38', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertJson(['places' => [['slug' =>'the-bridgewater-pub']]]);
}
/**
* Test a request for places, this time with an uncertainty parameter.
*
* @return void
*/
public function test_micropub_get_request_for_nearby_places_with_uncertainty_parameter()
/** @test */
public function micropubClientsCanRequestKnownNearbyPlaces(): void
{
$response = $this->get('/api/post?q=geo:53.5,-2.38', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertJson(['places' => [['slug' => 'the-bridgewater-pub']]]);
}
/**
* Test a request for places, where there will be an “empty” response.
*
* @return void
* @test
* @todo Add uncertainty parameter
*/
public function test_micropub_get_request_for_nearby_places_where_non_exist()
public function micropubClientsCanRequestKnownNearbyPlacesWithUncertaintyParameter(): void
{
$response = $this->get('/api/post?q=geo:53.5,-2.38', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertJson(['places' => [['slug' => 'the-bridgewater-pub']]]);
}
/** @test */
public function returnEmptyResultWhenMicropubClientRequestsKnownNearbyPlaces(): void
{
$response = $this->get('/api/post?q=geo:1.23,4.56', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertJson(['places' => []]);
}
/**
* Test a request for the micropub config.
*
* @return void
*/
public function test_micropub_get_request_for_config()
/** @test */
public function micropubClientCanRequestEndpointConfig(): void
{
$response = $this->get('/api/post?q=config', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertJsonFragment(['uid' => 'https://twitter.com/jonnybarnes']);
}
/**
* Test a valid micropub requests creates a new note.
*
* @return void
*/
public function test_micropub_post_request_creates_new_note()
/** @test */
public function micropubClientCanCreateNewNote(): void
{
$faker = \Faker\Factory::create();
$faker = Factory::create();
$note = $faker->text;
$response = $this->post(
'/api/post',
@ -133,15 +104,11 @@ class MicropubControllerTest extends TestCase
$this->assertDatabaseHas('notes', ['note' => $note]);
}
/**
* Test a valid micropub requests creates a new note and syndicates to Twitter.
*
* @return void
*/
public function test_micropub_post_request_creates_new_note_sends_to_twitter()
/** @test */
public function micropubClientCanRequestTheNewNoteIsSyndicatedToTwitter(): void
{
Queue::fake();
$faker = \Faker\Factory::create();
$faker = Factory::create();
$note = $faker->text;
$response = $this->post(
'/api/post',
@ -157,12 +124,8 @@ class MicropubControllerTest extends TestCase
Queue::assertPushed(SyndicateNoteToTwitter::class);
}
/**
* Test a valid micropub requests creates a new place.
*
* @return void
*/
public function test_micropub_post_request_creates_new_place()
/** @test */
public function micropubClientsCanCreateNewPlaces(): void
{
$response = $this->post(
'/api/post',
@ -177,13 +140,8 @@ class MicropubControllerTest extends TestCase
$this->assertDatabaseHas('places', ['slug' => 'the-barton-arms']);
}
/**
* Test a valid micropub requests creates a new place with latitude
* and longitude values defined separately.
*
* @return void
*/
public function test_micropub_post_request_creates_new_place_with_latlng()
/** @test */
public function micropubClientsCanCreateNewPlacesWithOldLocationSyntax(): void
{
$response = $this->post(
'/api/post',
@ -199,7 +157,8 @@ class MicropubControllerTest extends TestCase
$this->assertDatabaseHas('places', ['slug' => 'the-barton-arms']);
}
public function test_micropub_post_request_with_invalid_token_returns_expected_error_response()
/** @test */
public function micropubClientWebRequestWithInvalidTokenReturnsErrorResponse(): void
{
$response = $this->post(
'/api/post',
@ -213,7 +172,8 @@ class MicropubControllerTest extends TestCase
$response->assertJson(['error' => 'invalid_token']);
}
public function test_micropub_post_request_with_scopeless_token_returns_expected_error_response()
/** @test */
public function micropubClientWebRequestWithTokenWithoutAnyScopesReturnsErrorResponse(): void
{
$response = $this->post(
'/api/post',
@ -227,7 +187,8 @@ class MicropubControllerTest extends TestCase
$response->assertJson(['error_description' => 'The provided token has no scopes']);
}
public function test_micropub_post_request_for_place_without_create_scope_errors()
/** @test */
public function micropubClientWebRequestWithTokenWithoutCreateScopesReturnsErrorResponse(): void
{
$response = $this->post(
'/api/post',
@ -245,16 +206,16 @@ class MicropubControllerTest extends TestCase
/**
* Test a valid micropub requests using JSON syntax creates a new note.
*
* @return void
* @test
*/
public function test_micropub_post_request_with_json_syntax_creates_new_note()
public function micropubClientApiRequestCreatesNewNote(): void
{
Queue::fake();
Media::create([
'path' => 'test-photo.jpg',
'type' => 'image',
]);
$faker = \Faker\Factory::create();
$faker = Factory::create();
$note = $faker->text;
$response = $this->postJson(
'/api/post',
@ -282,16 +243,16 @@ class MicropubControllerTest extends TestCase
* Test a valid micropub requests using JSON syntax creates a new note with
* existing self-created place.
*
* @return void
* @test
*/
public function test_micropub_post_request_with_json_syntax_creates_new_note_with_existing_place_in_location()
public function micropubClientApiRequestCreatesNewNoteWithExistingPlaceInLocationData(): void
{
$place = new Place();
$place->name = 'Test Place';
$place->latitude = 1.23;
$place->longitude = 4.56;
$place->save();
$faker = \Faker\Factory::create();
$faker = Factory::create();
$note = $faker->text;
$response = $this->postJson(
'/api/post',
@ -313,11 +274,11 @@ class MicropubControllerTest extends TestCase
* Test a valid micropub requests using JSON syntax creates a new note with
* a new place defined in the location block.
*
* @return void
* @test
*/
public function test_micropub_post_request_with_json_syntax_creates_new_note_with_new_place_in_location()
public function micropubClientApiRequestCreatesNewNoteWithNewPlaceInLocationData(): void
{
$faker = \Faker\Factory::create();
$faker = Factory::create();
$note = $faker->text;
$response = $this->postJson(
'/api/post',
@ -349,11 +310,11 @@ class MicropubControllerTest extends TestCase
* Test a valid micropub requests using JSON syntax creates a new note without
* a new place defined in the location block if there is missing data.
*
* @return void
* @test
*/
public function test_micropub_post_request_with_json_syntax_creates_new_note_without_new_place_in_location()
public function micropubClientApiRequestCreatesNewNoteWithoutNewPlaceInLocationData(): void
{
$faker = \Faker\Factory::create();
$faker = Factory::create();
$note = $faker->text;
$response = $this->postJson(
'/api/post',
@ -383,11 +344,11 @@ class MicropubControllerTest extends TestCase
* Test a micropub requests using JSON syntax without a token returns an
* error. Also check the message.
*
* @return void
* @test
*/
public function test_micropub_post_request_with_json_syntax_without_token_returns_error()
public function micropubClientApiRequestWithoutTokenReturnsError(): void
{
$faker = \Faker\Factory::create();
$faker = Factory::create();
$note = $faker->text;
$response = $this->postJson(
'/api/post',
@ -410,11 +371,11 @@ class MicropubControllerTest extends TestCase
* Test a micropub requests using JSON syntax without a valid token returns
* an error. Also check the message.
*
* @return void
* @test
*/
public function test_micropub_post_request_with_json_syntax_with_insufficient_token_returns_error()
public function micropubClientApiRequestWithTokenWithInsufficientPermissionReturnsError(): void
{
$faker = \Faker\Factory::create();
$faker = Factory::create();
$note = $faker->text;
$response = $this->postJson(
'/api/post',
@ -434,7 +395,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(401);
}
public function test_micropub_post_request_with_json_syntax_for_unsupported_type_returns_error()
/** @test */
public function micropubClientApiRequestForUnsupportedPostTypeReturnsError(): void
{
$response = $this->postJson(
'/api/post',
@ -454,9 +416,10 @@ class MicropubControllerTest extends TestCase
->assertStatus(500);
}
public function test_micropub_post_request_with_json_syntax_creates_new_place()
/** @test */
public function micropubClientApiRequestCreatesNewPlace(): void
{
$faker = \Faker\Factory::create();
$faker = Factory::create();
$response = $this->postJson(
'/api/post',
[
@ -473,9 +436,10 @@ class MicropubControllerTest extends TestCase
->assertStatus(201);
}
public function test_micropub_post_request_with_json_syntax_and_uncertainty_parameter_creates_new_place()
/** @test */
public function micropubClientApiRequestCreatesNewPlaceWithUncertaintyParameter(): void
{
$faker = \Faker\Factory::create();
$faker = Factory::create();
$response = $this->postJson(
'/api/post',
[
@ -492,7 +456,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(201);
}
public function test_micropub_post_request_with_json_syntax_update_replace_post()
/** @test */
public function micropubClientApiRequestUpdatesExistingNote(): void
{
$response = $this->postJson(
'/api/post',
@ -510,7 +475,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(200);
}
public function test_micropub_post_request_with_json_syntax_update_add_post()
/** @test */
public function micropubClientApiRequestUpdatesNoteSyndicationLinks(): void
{
$response = $this->postJson(
'/api/post',
@ -535,7 +501,8 @@ class MicropubControllerTest extends TestCase
]);
}
public function test_micropub_post_request_with_json_syntax_update_add_image_to_post()
/** @test */
public function micropubClientApiRequestAddsImageToNote(): void
{
$response = $this->postJson(
'/api/post',
@ -556,7 +523,8 @@ class MicropubControllerTest extends TestCase
]);
}
public function test_micropub_post_request_with_json_syntax_update_add_post_errors_for_non_note()
/** @test */
public function micropubClientApiRequestReturnsErrorTryingToUpdateNonNoteModel(): void
{
$response = $this->postJson(
'/api/post',
@ -574,7 +542,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(500);
}
public function test_micropub_post_request_with_json_syntax_update_add_post_errors_for_note_not_found()
/** @test */
public function micropubClientApiRequestReturnsErrorTryingToUpdateNonExistingNote(): void
{
$response = $this->postJson(
'/api/post',
@ -592,7 +561,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(404);
}
public function test_micropub_post_request_with_json_syntax_update_add_post_errors_for_unsupported_request()
/** @test */
public function micropubClientApiRequestReturnsErrorWhenTryingToUpdateUnsupportedProperty(): void
{
$response = $this->postJson(
'/api/post',
@ -610,7 +580,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(500);
}
public function test_micropub_post_request_with_json_syntax_update_errors_for_insufficient_scope()
/** @test */
public function micropubClientApiRequestWithTokenWithInsufficientScopeReturnsError(): void
{
$response = $this->postJson(
'/api/post',
@ -628,7 +599,8 @@ class MicropubControllerTest extends TestCase
->assertJson(['error' => 'insufficient_scope']);
}
public function test_micropub_post_request_with_json_syntax_update_replace_post_syndication()
/** @test */
public function micropubClientApiRequestCanReplaceNoteSyndicationTargets(): void
{
$response = $this->postJson(
'/api/post',
@ -653,9 +625,10 @@ class MicropubControllerTest extends TestCase
]);
}
public function test_access_token_form_encoded()
/** @test */
public function micropubClientWebReauestCanEncodeTokenWithinTheForm(): void
{
$faker = \Faker\Factory::create();
$faker = Factory::create();
$note = $faker->text;
$response = $this->post(
'/api/post',

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Jobs\ProcessMedia;
@ -17,7 +19,7 @@ class MicropubMediaTest extends TestCase
use TestToken;
/** @test */
public function emptyResponseForLastUploadWhenNoneFound()
public function emptyResponseForLastUploadWhenNoneFound(): void
{
// Make sure theres no media
Media::all()->each(function ($media) {
@ -33,7 +35,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function clientCanListLastUpload()
public function clientCanListLastUpload(): void
{
Queue::fake();
Storage::fake('s3');
@ -61,7 +63,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function clientCanSourceUploads()
public function clientCanSourceUploads(): void
{
Queue::fake();
Storage::fake('s3');
@ -91,7 +93,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function clientCanSourceUploadsWithLimit()
public function clientCanSourceUploadsWithLimit(): void
{
Queue::fake();
Storage::fake('s3');
@ -123,7 +125,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function errorResponseForUnknownQValue()
public function errorResponseForUnknownQValue(): void
{
$response = $this->get(
'/api/media?q=unknown',
@ -134,7 +136,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function optionsRequestReturnsCorsResponse()
public function optionsRequestReturnsCorsResponse(): void
{
$response = $this->options('/api/media');
@ -143,7 +145,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function mediaEndpointRequestWithInvalidTokenReturns400Response()
public function mediaEndpointRequestWithInvalidTokenReturns400Response(): void
{
$response = $this->post(
'/api/media',
@ -155,7 +157,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function mediaEndpointRequestWithTokenWithNoScopeReturns400Response()
public function mediaEndpointRequestWithTokenWithNoScopeReturns400Response(): void
{
$response = $this->post(
'/api/media',
@ -167,7 +169,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function mediaEndpointRequestWithInsufficientTokenScopesReturns401Response()
public function mediaEndpointRequestWithInsufficientTokenScopesReturns401Response(): void
{
$response = $this->post(
'/api/media',
@ -181,7 +183,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function mediaEndpointUploadFile()
public function mediaEndpointUploadFile(): void
{
Queue::fake();
Storage::fake('s3');
@ -204,7 +206,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function mediaEndpointUploadAudioFile()
public function mediaEndpointUploadAudioFile(): void
{
Queue::fake();
Storage::fake('s3');
@ -227,7 +229,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function mediaEndpointUploadVideoFile()
public function mediaEndpointUploadVideoFile(): void
{
Queue::fake();
Storage::fake('s3');
@ -250,7 +252,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function mediaEndpointUploadDocumentFile()
public function mediaEndpointUploadDocumentFile(): void
{
Queue::fake();
Storage::fake('s3');
@ -272,7 +274,7 @@ class MicropubMediaTest extends TestCase
}
/** @test */
public function mediaEndpointUploadInvalidFileReturnsError()
public function mediaEndpointUploadInvalidFileReturnsError(): void
{
Queue::fake();
Storage::fake('local');

View file

@ -1,47 +1,49 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
use App\Models\Note;
class NotesControllerTest extends TestCase
{
/**
/*
* Test the `/notes` page returns 200, this should
* mean the database is being hit.
*
* @return void
*/
public function test_notes_page()
* @test
*
public function notesPageLoads(): void
{
$response = $this->get('/notes');
$response->assertStatus(200);
}
}*/
/**
* Test a specific note.
*
* @return void
* @test
*/
public function test_specific_note()
public function specificNotePageLoads(): void
{
$response = $this->get('/notes/D');
$response->assertViewHas('note');
}
public function test_note_replying_to_tweet()
/* @test *
public function noteReplyingToTweet(): void
{
$response = $this->get('/notes/B');
$response->assertViewHas('note');
}
}*/
/**
* Test that `/note/{decID}` redirects to `/notes/{nb60id}`.
*
* @return void
* @test
*/
public function test_dec_id_redirect()
public function oldNoteUrlsRedirect(): void
{
$response = $this->get('/note/11');
$response->assertRedirect(config('app.url') . '/notes/B');
@ -50,9 +52,9 @@ class NotesControllerTest extends TestCase
/**
* Visit the tagged page and check the tag view data.
*
* @return void
* @test
*/
public function test_tagged_notes_page()
public function taggedNotesPageLoads(): void
{
$response = $this->get('/notes/tagged/beer');
$response->assertViewHas('tag', 'beer');

View file

@ -1,18 +1,21 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Carbon;
use Tests\TestCase;
use Tests\TestToken;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class OwnYourGramTest extends TestCase
{
use DatabaseTransactions, TestToken;
use DatabaseTransactions;
use TestToken;
public function test_ownyourgram_post()
/** @test */
public function postingInstagramUrlSavesMediaPath(): void
{
$response = $this->json(
'POST',
@ -21,10 +24,13 @@ class OwnYourGramTest extends TestCase
'type' => ['h-entry'],
'properties' => [
'content' => ['How beautiful are the plates and chopsticks'],
'published' => [\Carbon\Carbon::now()->toIso8601String()],
'published' => [Carbon::now()->toIso8601String()],
'location' => ['geo:53.802419075834,-1.5431942917637'],
'syndication' => ['https://www.instagram.com/p/BVC_nVTBFfi/'],
'photo' => ['https://scontent-sjc2-1.cdninstagram.com/t51.2885-15/e35/18888604_425332491185600_326487281944756224_n.jpg'],
'photo' => [
// phpcs:ignore Generic.Files.LineLength.TooLong
'https://scontent-sjc2-1.cdninstagram.com/t51.2885-15/e35/18888604_425332491185600_326487281944756224_n.jpg'
],
],
],
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
@ -34,6 +40,7 @@ class OwnYourGramTest extends TestCase
'response' => 'created'
]);
$this->assertDatabaseHas('media_endpoint', [
// phpcs:ignore Generic.Files.LineLength.TooLong
'path' => 'https://scontent-sjc2-1.cdninstagram.com/t51.2885-15/e35/18888604_425332491185600_326487281944756224_n.jpg'
]);
$this->assertDatabaseHas('notes', [

View file

@ -1,12 +1,14 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
use App\Models\WebMention;
use Illuminate\FileSystem\FileSystem;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;
class ParseCachedWebMentionsTest extends TestCase
{
@ -18,11 +20,12 @@ class ParseCachedWebMentionsTest extends TestCase
mkdir(storage_path('HTML') . '/https/aaronpk.localhost/reply', 0777, true);
mkdir(storage_path('HTML') . '/http/tantek.com', 0777, true);
copy(__DIR__.'/../aaron.html', storage_path('HTML') . '/https/aaronpk.localhost/reply/1');
copy(__DIR__.'/../tantek.html', storage_path('HTML') . '/http/tantek.com/index.html');
copy(__DIR__ . '/../aaron.html', storage_path('HTML') . '/https/aaronpk.localhost/reply/1');
copy(__DIR__ . '/../tantek.html', storage_path('HTML') . '/http/tantek.com/index.html');
}
public function test_parsing_html()
/** @test */
public function parseWebmentionHtml(): void
{
$this->assertFileExists(storage_path('HTML') . '/https/aaronpk.localhost/reply/1');
$this->assertFileExists(storage_path('HTML') . '/http/tantek.com/index.html');

View file

@ -1,18 +1,20 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
use App\Models\Place;
use Tests\TestCase;
class PlacesTest extends TestCase
{
/**
* Test the `/places` page for OK response.
*
* @return void
* @test
*/
public function test_places_page()
public function placesPageLoads(): void
{
$response = $this->get('/places');
$response->assertStatus(200);
@ -21,9 +23,9 @@ class PlacesTest extends TestCase
/**
* Test a specific place.
*
* @return void
* @test
*/
public function test_single_place()
public function singlePlacePageLoads(): void
{
$place = Place::where('slug', 'the-bridgewater-pub')->first();
$response = $this->get('/places/the-bridgewater-pub');

View file

@ -1,15 +1,18 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
use App\Jobs\DownloadWebMention;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class ReDownloadWebMentionsTest extends TestCase
{
public function test_jobs_are_dispatched()
/** @test */
public function downloadJobGetsQueued(): void
{
Queue::fake();

View file

@ -1,13 +1,15 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class SearchControllerTest extends TestCase
{
public function test_search()
/** @test */
public function searchPageReturnsResult(): void
{
$response = $this->get('/search?terms=love');
$response->assertSee('duckduckgo.com');

View file

@ -1,33 +1,38 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ShortURLsControllerTest extends TestCase
{
public function test_short_domain_redirects_to_long_domain()
/** @test */
public function shortDomainRedirectsToLongDomain(): void
{
$response = $this->get('http://' . config('app.shorturl'));
$response = $this->get('https://' . config('app.shorturl'));
$response->assertRedirect(config('app.url'));
}
public function test_short_domain_slashat_redirects_to_twitter()
/** @test */
public function shortDomainSlashAtRedirectsToTwitter(): void
{
$response = $this->get('http://' . config('app.shorturl') . '/@');
$response = $this->get('https://' . config('app.shorturl') . '/@');
$response->assertRedirect('https://twitter.com/jonnybarnes');
}
public function test_short_domain_slasht_redirects_to_long_domain_slash_notes()
/** @test */
public function shortDomainSlashTRedirectsToLongDomainSlashNotes(): void
{
$response = $this->get('http://' . config('app.shorturl') . '/t/E');
$response = $this->get('https://' . config('app.shorturl') . '/t/E');
$response->assertRedirect(config('app.url') . '/notes/E');
}
public function test_short_domain_slashb_redirects_to_long_domain_slash_blog()
/** @test */
public function shortDomainSlashBRedirectsToLongDomainSlashBlog(): void
{
$response = $this->get('http://' . config('app.shorturl') . '/b/1');
$response = $this->get('https://' . config('app.shorturl') . '/b/1');
$response->assertRedirect(config('app.url') . '/blog/s/1');
}
}

View file

@ -1,26 +1,37 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Jobs\SendWebMentions;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
use Tests\TestToken;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class SwarmTest extends TestCase
{
use DatabaseTransactions, TestToken;
use DatabaseTransactions;
use TestToken;
public function test_faked_ownyourswarm_request_with_foursquare()
/**
* Given a check in to Foursquare, this is the content Ownyourswarm will post to us.
*
* @test
*/
public function mockedOwnyourswarmRequestWithFoursquare(): void
{
Queue::fake();
$response = $this->json(
'POST',
'api/post',
[
'type' => ['h-entry'],
'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
'published' => [Carbon::now()->toDateTimeString()],
'syndication' => ['https://www.swarmapp.com/checkin/abc'],
'content' => [[
'value' => 'My first #checkin using Example Product',
@ -48,18 +59,27 @@ class SwarmTest extends TestCase
$this->assertDatabaseHas('places', [
'external_urls' => '{"foursquare": "https://foursquare.com/v/123456"}'
]);
Queue::assertPushed(SendWebMentions::class);
}
// this request would actually come from another client than OwnYourSwarm
public function test_faked_ownyourswarm_request_with_osm()
/**
* This request would actually come from another client than OwnYourSwarm, but were testing
* OpenStreetMap data.
*
* @test
*/
public function mockedOwnyourswarmRequestWithOsm(): void
{
Queue::fake();
$response = $this->json(
'POST',
'api/post',
[
'type' => ['h-entry'],
'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
'published' => [Carbon::now()->toDateTimeString()],
'content' => [[
'value' => 'My first #checkin using Example Product',
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
@ -83,18 +103,26 @@ class SwarmTest extends TestCase
$this->assertDatabaseHas('places', [
'external_urls' => '{"osm": "https://www.openstreetmap.org/way/123456"}'
]);
Queue::assertPushed(SendWebMentions::class);
}
// this request would actually come from another client than OwnYourSwarm
public function test_faked_ownyourswarm_request_without_known_external_url()
/**
* This request would actually come from another client than OwnYourSwarm, as that would include a Foursquare URL
*
* @test
*/
public function mockedOwnyourswarmRequestWithoutKnownExternalUrl(): void
{
Queue::fake();
$response = $this->json(
'POST',
'api/post',
[
'type' => ['h-entry'],
'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
'published' => [Carbon::now()->toDateTimeString()],
'content' => [[
'value' => 'My first #checkin using Example Product',
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
@ -118,9 +146,12 @@ class SwarmTest extends TestCase
$this->assertDatabaseHas('places', [
'external_urls' => '{"default": "https://www.example.org/way/123456"}'
]);
Queue::assertPushed(SendWebMentions::class);
}
public function test_faked_ownyourswarm_request_with_no_text_content()
/** @test */
public function mockedOwnyourswarmRequestWithNoTextContent(): void
{
$response = $this->json(
'POST',
@ -128,7 +159,7 @@ class SwarmTest extends TestCase
[
'type' => ['h-entry'],
'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
'published' => [Carbon::now()->toDateTimeString()],
'syndication' => ['https://www.swarmapp.com/checkin/def'],
],
'checkin' => [
@ -152,18 +183,22 @@ class SwarmTest extends TestCase
$this->assertDatabaseHas('notes', [
'swarm_url' => 'https://www.swarmapp.com/checkin/def'
]);
// Check the default text content for the note was saved
$this->get($response->__get('headers')->get('location'))->assertSee('📍');
}
public function test_faked_ownyourswarm_request_saves_just_post_when_error_in_checkin_data()
/** @test */
public function mockedOwnyourswarmRequestSavesJustThePostWhenAnErrorOccursInTheCheckinData(): void
{
Queue::fake();
$response = $this->json(
'POST',
'api/post',
[
'type' => ['h-entry'],
'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
'published' => [Carbon::now()->toDateTimeString()],
'syndication' => ['https://www.swarmapp.com/checkin/abc'],
'content' => [[
'value' => 'My first #checkin using Example Product',
@ -186,17 +221,22 @@ class SwarmTest extends TestCase
$this->assertDatabaseMissing('places', [
'name' => 'Awesome Venue',
]);
Queue::assertPushed(SendWebMentions::class);
}
public function test_ownyourswarm_request_with_hadr_location()
/** @test */
public function mockedOwnyourswarmRequestWithHAdrLocation(): void
{
Queue::fake();
$response = $this->json(
'POST',
'api/post',
[
'type' => ['h-entry'],
'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
'published' => [Carbon::now()->toDateTimeString()],
'syndication' => ['https://www.swarmapp.com/checkin/abc'],
'content' => [[
'value' => 'My first #checkin using Example Product',
@ -227,18 +267,20 @@ class SwarmTest extends TestCase
$this->assertDatabaseMissing('places', [
'name' => 'Awesome Venue',
]);
Queue::assertPushed(SendWebMentions::class);
}
/** @test */
public function a_real_ownyourswarm_checkin()
public function ownyourswarmCheckinTestUsingRealData(): void
{
$response = $this->json(
'POST',
'api/post',
[
'type' => ['h-entry'],
'properties' =>[
'published' => [\Carbon\Carbon::now()->toDateTimeString()]
'properties' => [
'published' => [Carbon::now()->toDateTimeString()]
],
'syndication' => [
'https://www.swarmapp.com/user/199841/checkin/5c4b1ac56dcf04002c0a4f58'

View file

@ -1,15 +1,17 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use IndieAuth\Client;
use Mockery;
use Tests\TestCase;
use IndieAuth\Client;
use Illuminate\Http\JsonResponse;
class TokenEndpointTest extends TestCase
{
public function test_token_endpoint_issues_token()
/** @test */
public function tokenEndpointIssuesToken(): void
{
$mockClient = Mockery::mock(Client::class);
$mockClient->shouldReceive('discoverAuthorizationEndpoint')
@ -35,7 +37,8 @@ class TokenEndpointTest extends TestCase
]);
}
public function test_token_endpoint_returns_error_when_auth_endpoint_lacks_me_data()
/** @test */
public function tokenEndpointReturnsErrorWhenAuthEndpointLacksMeData(): void
{
$mockClient = Mockery::mock(Client::class);
$mockClient->shouldReceive('discoverAuthorizationEndpoint')
@ -60,7 +63,8 @@ class TokenEndpointTest extends TestCase
]);
}
public function test_token_endpoint_returns_error_when_no_auth_endpoint_found()
/** @test */
public function tokenEndpointReturnsErrorWhenNoAuthEndpointFound(): void
{
$mockClient = Mockery::mock(Client::class);
$mockClient->shouldReceive('discoverAuthorizationEndpoint')

View file

@ -1,13 +1,15 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Services\TokenService;
use DateTimeImmutable;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Key\InMemory;
use Lcobucci\JWT\Validation\RequiredConstraintsViolated;
use Tests\TestCase;
use App\Services\TokenService;
class TokenServiceTest extends TestCase
{
@ -15,9 +17,9 @@ class TokenServiceTest extends TestCase
* Given the token is dependent on a random nonce, the time of creation and
* the APP_KEY, to test, we shall create a token, and then verify it.
*
* @return void
* @test
*/
public function test_token_creation_and_validation()
public function tokenserviceCreatesAndValidatesTokens(): void
{
$tokenService = new TokenService();
$data = [
@ -35,7 +37,8 @@ class TokenServiceTest extends TestCase
$this->assertSame($data, $validData);
}
public function test_token_with_different_signing_key_throws_exception()
/** @test */
public function tokensWithDifferentSigningKeyThrowsException(): void
{
$this->expectException(RequiredConstraintsViolated::class);

View file

@ -1,14 +1,17 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
use App\Jobs\ProcessWebMention;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class WebMentionsControllerTest extends TestCase
{
public function test_get_endpoint()
/** @test */
public function webmentionEndpointCanServeBrowserRequest(): void
{
$response = $this->get('/webmention');
$response->assertViewIs('webmention-endpoint');
@ -17,20 +20,22 @@ class WebMentionsControllerTest extends TestCase
/**
* Test webmentions without source and target are rejected.
*
* @return void
* @test
*/
public function test_webmentions_without_source_and_target_are_rejected()
public function webmentionsWithoutSourceAndTargetAreRejected(): void
{
$response = $this->call('POST', '/webmention', ['source' => 'https://example.org/post/123']);
$response->assertStatus(400);
}
/**
* Test invalid target gets a 400 response.
* Test invalid target gives a 400 response.
*
* @return void
* In this case an invalid target is a URL that doesnt exist on our domain.
*
* @test
*/
public function test_invalid_target_returns_400_response()
public function invalidTargetReturnsErrorResponse(): void
{
$response = $this->call('POST', '/webmention', [
'source' => 'https://example.org/post/123',
@ -40,11 +45,11 @@ class WebMentionsControllerTest extends TestCase
}
/**
* Test blog target gets a 501 response due to me not supporting it.
* Test blog target gets a 501 response due to our not supporting it.
*
* @return void
* @test
*/
public function test_blog_target_returns_501_response()
public function blogTargetReturns501Response(): void
{
$response = $this->call('POST', '/webmention', [
'source' => 'https://example.org/post/123',
@ -54,11 +59,11 @@ class WebMentionsControllerTest extends TestCase
}
/**
* Test that a non-existant note gives a 400 response.
* Test that a non-existent note gives a 400 response.
*
* @return void
* @test
*/
public function test_nonexistant_note_returns_400_response()
public function nonexistentNoteReturnsErrorResponse(): void
{
$response = $this->call('POST', '/webmention', [
'source' => 'https://example.org/post/123',
@ -67,12 +72,8 @@ class WebMentionsControllerTest extends TestCase
$response->assertStatus(400);
}
/**
* Test a legit webmention triggers the ProcessWebMention job.
*
* @return void
*/
public function test_legitimate_webmnetion_triggers_processwebmention_job()
/** @test */
public function legitimateWebmentionTriggersProcesswebmentionJob(): void
{
Queue::fake();