Merge pull request #225 from jonnybarnes/rename_tests

Rename tests
This commit is contained in:
Jonny Barnes 2021-03-17 18:52:02 +00:00 committed by GitHub
commit da2c49a72c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 1329 additions and 1253 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 cant be `null`. * 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'); $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();

View file

@ -1,41 +1,33 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Faker\Factory;
use App\Jobs\{SendWebMentions, SyndicateNoteToTwitter};
use App\Models\{Media, Place};
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase; use Tests\TestCase;
use Tests\TestToken; 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 class MicropubControllerTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
use TestToken; use TestToken;
/** /** @test */
* Test a GET request for the micropub endpoint without a token gives a public function micropubGetRequestWithoutTokenReturnsErrorResponse(): void
* 400 response. Also check the error message.
*
* @return void
*/
public function test_micropub_get_request_without_token_returns_401_response()
{ {
$response = $this->get('/api/post'); $response = $this->get('/api/post');
$response->assertStatus(401); $response->assertStatus(401);
$response->assertJsonFragment(['error_description' => 'No access token was provided in the request']); $response->assertJsonFragment(['error_description' => 'No access token was provided in the request']);
} }
/** /** @test */
* Test a GET request for the micropub endpoint without a valid token gives public function micropubGetRequestWithoutValidTokenReturnsErrorResponse(): void
* a 400 response. Also check the error message.
*
* @return void
*/
public function test_micropub_get_request_without_valid_token_returns_400_response()
{ {
$response = $this->get('/api/post', ['HTTP_Authorization' => 'Bearer abc123']); $response = $this->get('/api/post', ['HTTP_Authorization' => 'Bearer abc123']);
$response->assertStatus(400); $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 * 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 = $this->get('/api/post', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertStatus(200); $response->assertStatus(200);
$response->assertJsonFragment(['response' => 'token']); $response->assertJsonFragment(['response' => 'token']);
} }
/** /** @test */
* Test a GET request for syndication targets. public function micropubClientsCanRequestSyndicationTargets(): void
*
* @return void
*/
public function test_micropub_get_request_for_syndication_targets()
{ {
$response = $this->get('/api/post?q=syndicate-to', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]); $response = $this->get('/api/post?q=syndicate-to', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertJsonFragment(['uid' => 'https://twitter.com/jonnybarnes']); $response->assertJsonFragment(['uid' => 'https://twitter.com/jonnybarnes']);
} }
/** /** @test */
* Test a request for places. public function micropubClientsCanRequestKnownNearbyPlaces(): void
*
* @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()
{ {
$response = $this->get('/api/post?q=geo:53.5,-2.38', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]); $response = $this->get('/api/post?q=geo:53.5,-2.38', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertJson(['places' => [['slug' => 'the-bridgewater-pub']]]); $response->assertJson(['places' => [['slug' => 'the-bridgewater-pub']]]);
} }
/** /**
* Test a request for places, where there will be an “empty” response. * @test
* * @todo Add uncertainty parameter
* @return void
*/ */
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 = $this->get('/api/post?q=geo:1.23,4.56', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertJson(['places' => []]); $response->assertJson(['places' => []]);
} }
/** /** @test */
* Test a request for the micropub config. public function micropubClientCanRequestEndpointConfig(): void
*
* @return void
*/
public function test_micropub_get_request_for_config()
{ {
$response = $this->get('/api/post?q=config', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]); $response = $this->get('/api/post?q=config', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$response->assertJsonFragment(['uid' => 'https://twitter.com/jonnybarnes']); $response->assertJsonFragment(['uid' => 'https://twitter.com/jonnybarnes']);
} }
/** /** @test */
* Test a valid micropub requests creates a new note. public function micropubClientCanCreateNewNote(): void
*
* @return void
*/
public function test_micropub_post_request_creates_new_note()
{ {
$faker = \Faker\Factory::create(); $faker = Factory::create();
$note = $faker->text; $note = $faker->text;
$response = $this->post( $response = $this->post(
'/api/post', '/api/post',
@ -133,15 +104,11 @@ class MicropubControllerTest extends TestCase
$this->assertDatabaseHas('notes', ['note' => $note]); $this->assertDatabaseHas('notes', ['note' => $note]);
} }
/** /** @test */
* Test a valid micropub requests creates a new note and syndicates to Twitter. public function micropubClientCanRequestTheNewNoteIsSyndicatedToTwitter(): void
*
* @return void
*/
public function test_micropub_post_request_creates_new_note_sends_to_twitter()
{ {
Queue::fake(); Queue::fake();
$faker = \Faker\Factory::create(); $faker = Factory::create();
$note = $faker->text; $note = $faker->text;
$response = $this->post( $response = $this->post(
'/api/post', '/api/post',
@ -157,12 +124,8 @@ class MicropubControllerTest extends TestCase
Queue::assertPushed(SyndicateNoteToTwitter::class); Queue::assertPushed(SyndicateNoteToTwitter::class);
} }
/** /** @test */
* Test a valid micropub requests creates a new place. public function micropubClientsCanCreateNewPlaces(): void
*
* @return void
*/
public function test_micropub_post_request_creates_new_place()
{ {
$response = $this->post( $response = $this->post(
'/api/post', '/api/post',
@ -177,13 +140,8 @@ class MicropubControllerTest extends TestCase
$this->assertDatabaseHas('places', ['slug' => 'the-barton-arms']); $this->assertDatabaseHas('places', ['slug' => 'the-barton-arms']);
} }
/** /** @test */
* Test a valid micropub requests creates a new place with latitude public function micropubClientsCanCreateNewPlacesWithOldLocationSyntax(): void
* and longitude values defined separately.
*
* @return void
*/
public function test_micropub_post_request_creates_new_place_with_latlng()
{ {
$response = $this->post( $response = $this->post(
'/api/post', '/api/post',
@ -199,7 +157,8 @@ class MicropubControllerTest extends TestCase
$this->assertDatabaseHas('places', ['slug' => 'the-barton-arms']); $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( $response = $this->post(
'/api/post', '/api/post',
@ -213,7 +172,8 @@ class MicropubControllerTest extends TestCase
$response->assertJson(['error' => 'invalid_token']); $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( $response = $this->post(
'/api/post', '/api/post',
@ -227,7 +187,8 @@ class MicropubControllerTest extends TestCase
$response->assertJson(['error_description' => 'The provided token has no scopes']); $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( $response = $this->post(
'/api/post', '/api/post',
@ -245,16 +206,16 @@ class MicropubControllerTest extends TestCase
/** /**
* Test a valid micropub requests using JSON syntax creates a new note. * 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(); Queue::fake();
Media::create([ Media::create([
'path' => 'test-photo.jpg', 'path' => 'test-photo.jpg',
'type' => 'image', 'type' => 'image',
]); ]);
$faker = \Faker\Factory::create(); $faker = Factory::create();
$note = $faker->text; $note = $faker->text;
$response = $this->postJson( $response = $this->postJson(
'/api/post', '/api/post',
@ -282,16 +243,16 @@ class MicropubControllerTest extends TestCase
* Test a valid micropub requests using JSON syntax creates a new note with * Test a valid micropub requests using JSON syntax creates a new note with
* existing self-created place. * 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 = new Place();
$place->name = 'Test Place'; $place->name = 'Test Place';
$place->latitude = 1.23; $place->latitude = 1.23;
$place->longitude = 4.56; $place->longitude = 4.56;
$place->save(); $place->save();
$faker = \Faker\Factory::create(); $faker = Factory::create();
$note = $faker->text; $note = $faker->text;
$response = $this->postJson( $response = $this->postJson(
'/api/post', '/api/post',
@ -313,11 +274,11 @@ class MicropubControllerTest extends TestCase
* Test a valid micropub requests using JSON syntax creates a new note with * Test a valid micropub requests using JSON syntax creates a new note with
* a new place defined in the location block. * 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; $note = $faker->text;
$response = $this->postJson( $response = $this->postJson(
'/api/post', '/api/post',
@ -349,11 +310,11 @@ class MicropubControllerTest extends TestCase
* Test a valid micropub requests using JSON syntax creates a new note without * 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. * 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; $note = $faker->text;
$response = $this->postJson( $response = $this->postJson(
'/api/post', '/api/post',
@ -383,11 +344,11 @@ class MicropubControllerTest extends TestCase
* Test a micropub requests using JSON syntax without a token returns an * Test a micropub requests using JSON syntax without a token returns an
* error. Also check the message. * 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; $note = $faker->text;
$response = $this->postJson( $response = $this->postJson(
'/api/post', '/api/post',
@ -410,11 +371,11 @@ class MicropubControllerTest extends TestCase
* Test a micropub requests using JSON syntax without a valid token returns * Test a micropub requests using JSON syntax without a valid token returns
* an error. Also check the message. * 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; $note = $faker->text;
$response = $this->postJson( $response = $this->postJson(
'/api/post', '/api/post',
@ -434,7 +395,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(401); ->assertStatus(401);
} }
public function test_micropub_post_request_with_json_syntax_for_unsupported_type_returns_error() /** @test */
public function micropubClientApiRequestForUnsupportedPostTypeReturnsError(): void
{ {
$response = $this->postJson( $response = $this->postJson(
'/api/post', '/api/post',
@ -454,9 +416,10 @@ class MicropubControllerTest extends TestCase
->assertStatus(500); ->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( $response = $this->postJson(
'/api/post', '/api/post',
[ [
@ -473,9 +436,10 @@ class MicropubControllerTest extends TestCase
->assertStatus(201); ->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( $response = $this->postJson(
'/api/post', '/api/post',
[ [
@ -492,7 +456,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(201); ->assertStatus(201);
} }
public function test_micropub_post_request_with_json_syntax_update_replace_post() /** @test */
public function micropubClientApiRequestUpdatesExistingNote(): void
{ {
$response = $this->postJson( $response = $this->postJson(
'/api/post', '/api/post',
@ -510,7 +475,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(200); ->assertStatus(200);
} }
public function test_micropub_post_request_with_json_syntax_update_add_post() /** @test */
public function micropubClientApiRequestUpdatesNoteSyndicationLinks(): void
{ {
$response = $this->postJson( $response = $this->postJson(
'/api/post', '/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( $response = $this->postJson(
'/api/post', '/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( $response = $this->postJson(
'/api/post', '/api/post',
@ -574,7 +542,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(500); ->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( $response = $this->postJson(
'/api/post', '/api/post',
@ -592,7 +561,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(404); ->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( $response = $this->postJson(
'/api/post', '/api/post',
@ -610,7 +580,8 @@ class MicropubControllerTest extends TestCase
->assertStatus(500); ->assertStatus(500);
} }
public function test_micropub_post_request_with_json_syntax_update_errors_for_insufficient_scope() /** @test */
public function micropubClientApiRequestWithTokenWithInsufficientScopeReturnsError(): void
{ {
$response = $this->postJson( $response = $this->postJson(
'/api/post', '/api/post',
@ -628,7 +599,8 @@ class MicropubControllerTest extends TestCase
->assertJson(['error' => 'insufficient_scope']); ->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( $response = $this->postJson(
'/api/post', '/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; $note = $faker->text;
$response = $this->post( $response = $this->post(
'/api/post', '/api/post',

View file

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

View file

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

View file

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

View file

@ -1,12 +1,14 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase;
use App\Models\WebMention; use App\Models\WebMention;
use Illuminate\FileSystem\FileSystem; use Illuminate\FileSystem\FileSystem;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;
class ParseCachedWebMentionsTest extends 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') . '/https/aaronpk.localhost/reply', 0777, true);
mkdir(storage_path('HTML') . '/http/tantek.com', 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__ . '/../aaron.html', storage_path('HTML') . '/https/aaronpk.localhost/reply/1');
copy(__DIR__.'/../tantek.html', storage_path('HTML') . '/http/tantek.com/index.html'); 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') . '/https/aaronpk.localhost/reply/1');
$this->assertFileExists(storage_path('HTML') . '/http/tantek.com/index.html'); $this->assertFileExists(storage_path('HTML') . '/http/tantek.com/index.html');

View file

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

View file

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

View file

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

View file

@ -1,33 +1,38 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ShortURLsControllerTest extends TestCase 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')); $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'); $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'); $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'); $response->assertRedirect(config('app.url') . '/blog/s/1');
} }
} }

View file

@ -1,26 +1,37 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; 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\TestCase;
use Tests\TestToken; use Tests\TestToken;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class SwarmTest extends TestCase 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( $response = $this->json(
'POST', 'POST',
'api/post', 'api/post',
[ [
'type' => ['h-entry'], 'type' => ['h-entry'],
'properties' => [ 'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()], 'published' => [Carbon::now()->toDateTimeString()],
'syndication' => ['https://www.swarmapp.com/checkin/abc'], 'syndication' => ['https://www.swarmapp.com/checkin/abc'],
'content' => [[ 'content' => [[
'value' => 'My first #checkin using Example Product', 'value' => 'My first #checkin using Example Product',
@ -48,18 +59,27 @@ class SwarmTest extends TestCase
$this->assertDatabaseHas('places', [ $this->assertDatabaseHas('places', [
'external_urls' => '{"foursquare": "https://foursquare.com/v/123456"}' '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( $response = $this->json(
'POST', 'POST',
'api/post', 'api/post',
[ [
'type' => ['h-entry'], 'type' => ['h-entry'],
'properties' => [ 'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()], 'published' => [Carbon::now()->toDateTimeString()],
'content' => [[ 'content' => [[
'value' => 'My first #checkin using Example Product', 'value' => 'My first #checkin using Example Product',
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>', 'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
@ -83,18 +103,26 @@ class SwarmTest extends TestCase
$this->assertDatabaseHas('places', [ $this->assertDatabaseHas('places', [
'external_urls' => '{"osm": "https://www.openstreetmap.org/way/123456"}' '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( $response = $this->json(
'POST', 'POST',
'api/post', 'api/post',
[ [
'type' => ['h-entry'], 'type' => ['h-entry'],
'properties' => [ 'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()], 'published' => [Carbon::now()->toDateTimeString()],
'content' => [[ 'content' => [[
'value' => 'My first #checkin using Example Product', 'value' => 'My first #checkin using Example Product',
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>', 'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
@ -118,9 +146,12 @@ class SwarmTest extends TestCase
$this->assertDatabaseHas('places', [ $this->assertDatabaseHas('places', [
'external_urls' => '{"default": "https://www.example.org/way/123456"}' '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( $response = $this->json(
'POST', 'POST',
@ -128,7 +159,7 @@ class SwarmTest extends TestCase
[ [
'type' => ['h-entry'], 'type' => ['h-entry'],
'properties' => [ 'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()], 'published' => [Carbon::now()->toDateTimeString()],
'syndication' => ['https://www.swarmapp.com/checkin/def'], 'syndication' => ['https://www.swarmapp.com/checkin/def'],
], ],
'checkin' => [ 'checkin' => [
@ -152,18 +183,22 @@ class SwarmTest extends TestCase
$this->assertDatabaseHas('notes', [ $this->assertDatabaseHas('notes', [
'swarm_url' => 'https://www.swarmapp.com/checkin/def' '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('📍'); $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( $response = $this->json(
'POST', 'POST',
'api/post', 'api/post',
[ [
'type' => ['h-entry'], 'type' => ['h-entry'],
'properties' => [ 'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()], 'published' => [Carbon::now()->toDateTimeString()],
'syndication' => ['https://www.swarmapp.com/checkin/abc'], 'syndication' => ['https://www.swarmapp.com/checkin/abc'],
'content' => [[ 'content' => [[
'value' => 'My first #checkin using Example Product', 'value' => 'My first #checkin using Example Product',
@ -186,17 +221,22 @@ class SwarmTest extends TestCase
$this->assertDatabaseMissing('places', [ $this->assertDatabaseMissing('places', [
'name' => 'Awesome Venue', '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( $response = $this->json(
'POST', 'POST',
'api/post', 'api/post',
[ [
'type' => ['h-entry'], 'type' => ['h-entry'],
'properties' => [ 'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()], 'published' => [Carbon::now()->toDateTimeString()],
'syndication' => ['https://www.swarmapp.com/checkin/abc'], 'syndication' => ['https://www.swarmapp.com/checkin/abc'],
'content' => [[ 'content' => [[
'value' => 'My first #checkin using Example Product', 'value' => 'My first #checkin using Example Product',
@ -227,18 +267,20 @@ class SwarmTest extends TestCase
$this->assertDatabaseMissing('places', [ $this->assertDatabaseMissing('places', [
'name' => 'Awesome Venue', 'name' => 'Awesome Venue',
]); ]);
Queue::assertPushed(SendWebMentions::class);
} }
/** @test */ /** @test */
public function a_real_ownyourswarm_checkin() public function ownyourswarmCheckinTestUsingRealData(): void
{ {
$response = $this->json( $response = $this->json(
'POST', 'POST',
'api/post', 'api/post',
[ [
'type' => ['h-entry'], 'type' => ['h-entry'],
'properties' =>[ 'properties' => [
'published' => [\Carbon\Carbon::now()->toDateTimeString()] 'published' => [Carbon::now()->toDateTimeString()]
], ],
'syndication' => [ 'syndication' => [
'https://www.swarmapp.com/user/199841/checkin/5c4b1ac56dcf04002c0a4f58' 'https://www.swarmapp.com/user/199841/checkin/5c4b1ac56dcf04002c0a4f58'

View file

@ -1,15 +1,17 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use IndieAuth\Client;
use Mockery; use Mockery;
use Tests\TestCase; use Tests\TestCase;
use IndieAuth\Client;
use Illuminate\Http\JsonResponse;
class TokenEndpointTest extends TestCase class TokenEndpointTest extends TestCase
{ {
public function test_token_endpoint_issues_token() /** @test */
public function tokenEndpointIssuesToken(): void
{ {
$mockClient = Mockery::mock(Client::class); $mockClient = Mockery::mock(Client::class);
$mockClient->shouldReceive('discoverAuthorizationEndpoint') $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 = Mockery::mock(Client::class);
$mockClient->shouldReceive('discoverAuthorizationEndpoint') $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 = Mockery::mock(Client::class);
$mockClient->shouldReceive('discoverAuthorizationEndpoint') $mockClient->shouldReceive('discoverAuthorizationEndpoint')

View file

@ -1,13 +1,15 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use App\Services\TokenService;
use DateTimeImmutable; use DateTimeImmutable;
use Lcobucci\JWT\Configuration; use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Key\InMemory; use Lcobucci\JWT\Signer\Key\InMemory;
use Lcobucci\JWT\Validation\RequiredConstraintsViolated; use Lcobucci\JWT\Validation\RequiredConstraintsViolated;
use Tests\TestCase; use Tests\TestCase;
use App\Services\TokenService;
class TokenServiceTest extends TestCase 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 * 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. * 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(); $tokenService = new TokenService();
$data = [ $data = [
@ -35,7 +37,8 @@ class TokenServiceTest extends TestCase
$this->assertSame($data, $validData); $this->assertSame($data, $validData);
} }
public function test_token_with_different_signing_key_throws_exception() /** @test */
public function tokensWithDifferentSigningKeyThrowsException(): void
{ {
$this->expectException(RequiredConstraintsViolated::class); $this->expectException(RequiredConstraintsViolated::class);

View file

@ -1,14 +1,17 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase;
use App\Jobs\ProcessWebMention; use App\Jobs\ProcessWebMention;
use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class WebMentionsControllerTest extends TestCase class WebMentionsControllerTest extends TestCase
{ {
public function test_get_endpoint() /** @test */
public function webmentionEndpointCanServeBrowserRequest(): void
{ {
$response = $this->get('/webmention'); $response = $this->get('/webmention');
$response->assertViewIs('webmention-endpoint'); $response->assertViewIs('webmention-endpoint');
@ -17,20 +20,22 @@ class WebMentionsControllerTest extends TestCase
/** /**
* Test webmentions without source and target are rejected. * 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 = $this->call('POST', '/webmention', ['source' => 'https://example.org/post/123']);
$response->assertStatus(400); $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', [ $response = $this->call('POST', '/webmention', [
'source' => 'https://example.org/post/123', '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', [ $response = $this->call('POST', '/webmention', [
'source' => 'https://example.org/post/123', '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', [ $response = $this->call('POST', '/webmention', [
'source' => 'https://example.org/post/123', 'source' => 'https://example.org/post/123',
@ -67,12 +72,8 @@ class WebMentionsControllerTest extends TestCase
$response->assertStatus(400); $response->assertStatus(400);
} }
/** /** @test */
* Test a legit webmention triggers the ProcessWebMention job. public function legitimateWebmentionTriggersProcesswebmentionJob(): void
*
* @return void
*/
public function test_legitimate_webmnetion_triggers_processwebmention_job()
{ {
Queue::fake(); Queue::fake();

View file

@ -1,16 +1,19 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit; namespace Tests\Unit;
use Tests\TestCase;
use App\Models\Article; use App\Models\Article;
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_sluggable_method() /** @test */
public function titleSlugIsGeneratedAutomatically(): void
{ {
$article = new Article(); $article = new Article();
$article->title = 'My Title'; $article->title = 'My Title';
@ -20,15 +23,17 @@ class ArticlesTest extends TestCase
$this->assertEquals('my-title', $article->titleurl); $this->assertEquals('my-title', $article->titleurl);
} }
public function test_markdown_conversion() /** @test */
public function markdownContentIsConverted(): void
{ {
$article = new Article(); $article = new Article();
$article->main = 'Some *markdown*'; $article->main = 'Some *markdown*';
$this->assertEquals('<p>Some <em>markdown</em></p>'.PHP_EOL, $article->html); $this->assertEquals('<p>Some <em>markdown</em></p>' . PHP_EOL, $article->html);
} }
public function test_time_attributes() /** @test */
public function weGenerateTheDifferentTimeAttributes(): void
{ {
$article = Article::create([ $article = Article::create([
'title' => 'Test', 'title' => 'Test',
@ -41,7 +46,8 @@ class ArticlesTest extends TestCase
$this->assertEquals($article->pubdate, $article->updated_at->toRSSString()); $this->assertEquals($article->pubdate, $article->updated_at->toRSSString());
} }
public function test_link_accessor() /** @test */
public function weGenerateTheArticleLinkFromTheSlug(): void
{ {
$article = Article::create([ $article = Article::create([
'title' => 'Test', 'title' => 'Test',
@ -55,7 +61,8 @@ class ArticlesTest extends TestCase
); );
} }
public function test_date_scope() /** @test */
public function dateScopeReturnsExpectedArticles(): void
{ {
$yearAndMonth = Article::date(date('Y'), date('m'))->get(); $yearAndMonth = Article::date(date('Y'), date('m'))->get();
$this->assertTrue(count($yearAndMonth) === 1); $this->assertTrue(count($yearAndMonth) === 1);

View file

@ -1,27 +1,31 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit; namespace Tests\Unit;
use Tests\TestCase; use App\Exceptions\InternetArchiveException;
use App\Services\BookmarkService;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use App\Services\BookmarkService; use Tests\TestCase;
use GuzzleHttp\Handler\MockHandler;
use App\Exceptions\InternetArchiveException;
class BookmarksTest extends TestCase class BookmarksTest extends TestCase
{ {
/** /**
* @test
* @group puppeteer * @group puppeteer
*/ *
public function test_screenshot_of_google() public function takeScreenshotOfDuckDuckGo()
{ {
$uuid = (new BookmarkService())->saveScreenshot('https://www.google.co.uk'); $uuid = (new BookmarkService())->saveScreenshot('https://duckduckgo.com');
$this->assertTrue(file_exists(public_path() . '/assets/img/bookmarks/' . $uuid . '.png')); $this->assertTrue(file_exists(public_path() . '/assets/img/bookmarks/' . $uuid . '.png'));
} }*/
public function test_archive_link_method() /** @test */
public function archiveLinkMethodCallsArchiveService(): void
{ {
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['Content-Location' => '/web/1234/example.org']), new Response(200, ['Content-Location' => '/web/1234/example.org']),
@ -33,7 +37,8 @@ class BookmarksTest extends TestCase
$this->assertEquals('/web/1234/example.org', $url); $this->assertEquals('/web/1234/example.org', $url);
} }
public function test_archive_link_method_archive_site_error_exception() /** @test */
public function archiveLinkMethodThrowsAnExceptionOnError(): void
{ {
$this->expectException(InternetArchiveException::class); $this->expectException(InternetArchiveException::class);
@ -43,10 +48,11 @@ class BookmarksTest extends TestCase
$handler = HandlerStack::create($mock); $handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]); $client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client); $this->app->instance(Client::class, $client);
$url = (new BookmarkService())->getArchiveLink('https://example.org'); (new BookmarkService())->getArchiveLink('https://example.org');
} }
public function test_archive_link_method_archive_site_no_location_exception() /** @test */
public function archiveLinkMethodThrowsAnExceptionIfNoLocationReturned(): void
{ {
$this->expectException(InternetArchiveException::class); $this->expectException(InternetArchiveException::class);
@ -56,6 +62,6 @@ class BookmarksTest extends TestCase
$handler = HandlerStack::create($mock); $handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]); $client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client); $this->app->instance(Client::class, $client);
$url = (new BookmarkService())->getArchiveLink('https://example.org'); (new BookmarkService())->getArchiveLink('https://example.org');
} }
} }

View file

@ -1,18 +1,72 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit; namespace Tests\Unit;
use Tests\TestCase; use Tests\TestCase;
class HelpersTest extends TestCase class HelpersTest extends TestCase
{ {
public function test_normalize_url_is_idempotent() /** @test */
public function normalizeUrlIsIdempotent(): void
{ {
$input = 'http://example.org:80/index.php?foo=bar&baz=1'; $input = 'http://example.org:80/index.php?foo=bar&baz=1';
$this->assertEquals(normalize_url(normalize_url($input)), normalize_url($input)); $this->assertEquals(normalize_url(normalize_url($input)), normalize_url($input));
} }
public function urlProvider() /**
* @test
* @dataProvider urlProvider
* @param string $input
* @param string $output
*/
public function normalizeUrlOnDataProvider(string $input, string $output): void
{
$this->assertEquals($output, normalize_url($input));
}
/** @test */
public function prettyPrintJson(): void
{
// phpcs:disable Generic.Files.LineLength.TooLong
$json = <<<JSON
{"glossary": {"title": "example glossary", "GlossDiv": {"title": "S", "GlossList": {"GlossEntry": {"ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": {"para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML", "XML"]}, "GlossSee": "markup"}}}}}
JSON;
// phpcs:enable Generic.Files.LineLength.TooLong
$expected = <<<EXPECTED
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": [
"GML",
"XML"
]
},
"GlossSee": "markup"
}
}
}
}
}
EXPECTED;
$this->assertEquals($expected, prettyPrintJson($json));
}
public function urlProvider(): array
{ {
return [ return [
['https://example.org/', 'https://example.org'], ['https://example.org/', 'https://example.org'],
@ -25,48 +79,4 @@ class HelpersTest extends TestCase
], ],
]; ];
} }
/**
* @dataProvider urlProvider
* @group temp
*/
public function test_normalize_url($input, $output)
{
$this->assertEquals($output, normalize_url($input));
}
public function test_pretty_print_json()
{
$json = <<<JSON
{"glossary": {"title": "example glossary", "GlossDiv": {"title": "S", "GlossList": {"GlossEntry": {"ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": {"para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML", "XML"]}, "GlossSee": "markup"}}}}}
JSON;
$expected = <<<EXPECTED
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": [
"GML",
"XML"
]
},
"GlossSee": "markup"
}
}
}
}
}
EXPECTED;
$this->assertEquals($expected, prettyPrintJson($json));
}
} }

View file

@ -1,16 +1,19 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit\Jobs; namespace Tests\Unit\Jobs;
use Tests\TestCase;
use App\Jobs\AddClientToDatabase; use App\Jobs\AddClientToDatabase;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class AddClientToDatabaseJobTest extends TestCase class AddClientToDatabaseJobTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_job_adds_client() /** @test */
public function clientIsAddedToDatabaseByJob(): void
{ {
$job = new AddClientToDatabase('https://example.org/client'); $job = new AddClientToDatabase('https://example.org/client');
$job->handle(); $job->handle();

View file

@ -1,14 +1,16 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit\Jobs; namespace Tests\Unit\Jobs;
use Tests\TestCase; use App\Jobs\DownloadWebMention;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use App\Jobs\DownloadWebMention;
use GuzzleHttp\Handler\MockHandler;
use Illuminate\FileSystem\FileSystem; use Illuminate\FileSystem\FileSystem;
use Tests\TestCase;
class DownloadWebMentionJobTest extends TestCase class DownloadWebMentionJobTest extends TestCase
{ {
@ -21,15 +23,16 @@ class DownloadWebMentionJobTest extends TestCase
parent::tearDown(); parent::tearDown();
} }
public function test_the_job_saves_html() /** @test */
public function htmlIsSavedByJob(): void
{ {
$this->assertFileDoesNotExist(storage_path('HTML/https')); $this->assertFileDoesNotExist(storage_path('HTML/https'));
$source = 'https://example.org/reply/1'; $source = 'https://example.org/reply/1';
$html = <<<HTML $html = <<<HTML
<div class="h-entry"> <div class="h-entry">
<a class="u-like-of" href=""></a> <a class="u-like-of" href=""></a>
</div> </div>
HTML; HTML;
$html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html); $html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html);
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['X-Foo' => 'Bar'], $html), new Response(200, ['X-Foo' => 'Bar'], $html),
@ -48,21 +51,22 @@ HTML;
$this->assertFileDoesNotExist(storage_path('HTML/https/example.org/reply') . '/1.' . date('Y-m-d') . '.backup'); $this->assertFileDoesNotExist(storage_path('HTML/https/example.org/reply') . '/1.' . date('Y-m-d') . '.backup');
} }
public function test_the_job_saves_html_and_backup() /** @test */
public function htmlAndBackupSavedByJob(): void
{ {
$this->assertFileDoesNotExist(storage_path('HTML/https')); $this->assertFileDoesNotExist(storage_path('HTML/https'));
$source = 'https://example.org/reply/1'; $source = 'https://example.org/reply/1';
$html = <<<HTML $html = <<<HTML
<div class="h-entry"> <div class="h-entry">
<a class="u-like-of" href=""></a> <a class="u-like-of" href=""></a>
</div> </div>
HTML; HTML;
$html2 = <<<HTML $html2 = <<<HTML
<div class="h-entry"> <div class="h-entry">
<a class="u-like-of" href=""></a> <a class="u-like-of" href=""></a>
<a class="u-repost-of" href=""></a> <a class="u-repost-of" href=""></a>
</div> </div>
HTML; HTML;
$html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html); $html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html);
$html2 = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html2); $html2 = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html2);
$mock = new MockHandler([ $mock = new MockHandler([
@ -82,15 +86,16 @@ HTML;
$this->assertFileExists(storage_path('HTML/https/example.org/reply') . '/1.' . date('Y-m-d') . '.backup'); $this->assertFileExists(storage_path('HTML/https/example.org/reply') . '/1.' . date('Y-m-d') . '.backup');
} }
public function test_an_index_html_file() /** @test */
public function indexHtmlFileIsSavedByJobForUrlsEndingWithSlash(): void
{ {
$this->assertFileDoesNotExist(storage_path('HTML/https')); $this->assertFileDoesNotExist(storage_path('HTML/https'));
$source = 'https://example.org/reply-one/'; $source = 'https://example.org/reply-one/';
$html = <<<HTML $html = <<<HTML
<div class="h-entry"> <div class="h-entry">
<a class="u-like-of" href=""></a> <a class="u-like-of" href=""></a>
</div> </div>
HTML; HTML;
$html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html); $html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html);
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['X-Foo' => 'Bar'], $html), new Response(200, ['X-Foo' => 'Bar'], $html),

View file

@ -1,24 +1,23 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit\Jobs; namespace Tests\Unit\Jobs;
use Tests\TestCase;
use Ramsey\Uuid\Uuid;
use GuzzleHttp\Client;
use App\Models\Bookmark;
use GuzzleHttp\HandlerStack;
use App\Jobs\ProcessBookmark;
use GuzzleHttp\Psr7\Response;
use App\Services\BookmarkService;
use GuzzleHttp\Handler\MockHandler;
use App\Exceptions\InternetArchiveException; use App\Exceptions\InternetArchiveException;
use App\Jobs\ProcessBookmark;
use App\Models\Bookmark;
use App\Services\BookmarkService;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Ramsey\Uuid\Uuid;
use Tests\TestCase;
class ProcessBookmarkJobTest extends TestCase class ProcessBookmarkJobTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_screenshot_and_archive_link_are_saved() /** @test */
public function screenshotAndArchiveLinkAreSavedByJob(): void
{ {
$bookmark = Bookmark::find(1); $bookmark = Bookmark::find(1);
$uuid = Uuid::uuid4(); $uuid = Uuid::uuid4();
@ -38,7 +37,8 @@ class ProcessBookmarkJobTest extends TestCase
]); ]);
} }
public function test_exception_casesu_null_value_for_archive_link() /** @test */
public function archiveLinkSavedAsNullWhenExceptionThrown(): void
{ {
$bookmark = Bookmark::find(1); $bookmark = Bookmark::find(1);
$uuid = Uuid::uuid4(); $uuid = Uuid::uuid4();
@ -46,7 +46,7 @@ class ProcessBookmarkJobTest extends TestCase
$service->method('saveScreenshot') $service->method('saveScreenshot')
->willReturn($uuid->toString()); ->willReturn($uuid->toString());
$service->method('getArchiveLink') $service->method('getArchiveLink')
->will($this->throwException(new InternetArchiveException)); ->will($this->throwException(new InternetArchiveException()));
$this->app->instance(BookmarkService::class, $service); $this->app->instance(BookmarkService::class, $service);
$job = new ProcessBookmark($bookmark); $job = new ProcessBookmark($bookmark);

View file

@ -1,15 +1,18 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit\Jobs; namespace Tests\Unit\Jobs;
use Storage;
use Tests\TestCase;
use App\Jobs\ProcessMedia; use App\Jobs\ProcessMedia;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\ImageManager; use Intervention\Image\ImageManager;
use Tests\TestCase;
class ProcessMediaJobTest extends TestCase class ProcessMediaJobTest extends TestCase
{ {
public function test_job_does_nothing_to_non_image() /** @test */
public function nonMediaFilesAreNotSaved(): void
{ {
Storage::fake('s3'); Storage::fake('s3');
$manager = app()->make(ImageManager::class); $manager = app()->make(ImageManager::class);
@ -20,18 +23,20 @@ class ProcessMediaJobTest extends TestCase
$this->assertFalse(file_exists(storage_path('app') . '/file.txt')); $this->assertFalse(file_exists(storage_path('app') . '/file.txt'));
} }
public function test_job_does_nothing_to_small_images() /** @test */
public function smallImagesAreNotResized(): void
{ {
Storage::fake('s3'); Storage::fake('s3');
$manager = app()->make(ImageManager::class); $manager = app()->make(ImageManager::class);
Storage::disk('local')->put('aaron.png', file_get_contents(__DIR__.'/../../aaron.png')); Storage::disk('local')->put('aaron.png', file_get_contents(__DIR__ . '/../../aaron.png'));
$job = new ProcessMedia('aaron.png'); $job = new ProcessMedia('aaron.png');
$job->handle($manager); $job->handle($manager);
$this->assertFalse(file_exists(storage_path('app') . '/aaron.png')); $this->assertFalse(file_exists(storage_path('app') . '/aaron.png'));
} }
public function test_large_images_have_smaller_files_created() /** @test */
public function largeImagesHaveSmallerImagesCreated(): void
{ {
$manager = app()->make(ImageManager::class); $manager = app()->make(ImageManager::class);
Storage::disk('local')->put('test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg')); Storage::disk('local')->put('test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));

View file

@ -1,21 +1,23 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit\Jobs; namespace Tests\Unit\Jobs;
use Tests\TestCase; use App\Exceptions\RemoteContentNotFoundException;
use App\Jobs\ProcessWebMention;
use App\Jobs\SaveProfileImage;
use App\Models\Note; use App\Models\Note;
use GuzzleHttp\Client;
use App\Models\WebMention; use App\Models\WebMention;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use App\Jobs\SaveProfileImage;
use App\Jobs\ProcessWebMention;
use GuzzleHttp\Handler\MockHandler;
use Illuminate\FileSystem\FileSystem; use Illuminate\FileSystem\FileSystem;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Queue;
use Jonnybarnes\WebmentionsParser\Parser; use Jonnybarnes\WebmentionsParser\Parser;
use App\Exceptions\RemoteContentNotFoundException; use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ProcessWebMentionJobTest extends TestCase class ProcessWebMentionJobTest extends TestCase
{ {
@ -30,7 +32,8 @@ class ProcessWebMentionJobTest extends TestCase
parent::tearDown(); parent::tearDown();
} }
public function test_for_exception_from_failure_to_get_webmention() /** @test */
public function failureGettingWebmentionThrowsAnException(): void
{ {
$this->expectException(RemoteContentNotFoundException::class); $this->expectException(RemoteContentNotFoundException::class);
@ -48,17 +51,18 @@ class ProcessWebMentionJobTest extends TestCase
$job->handle($parser, $client); $job->handle($parser, $client);
} }
public function test_a_new_webmention_gets_saved() /** @test */
public function newWebmentionGetsSavedByJob(): void
{ {
Queue::fake(); Queue::fake();
$parser = new Parser(); $parser = new Parser();
$html = <<<HTML $html = <<<HTML
<div class="h-entry"> <div class="h-entry">
I liked <a class="u-like-of" href="/notes/1">a note</a>. I liked <a class="u-like-of" href="/notes/1">a note</a>.
</div> </div>
HTML; HTML;
$html = str_replace('href="', 'href="' . config('app.url'), $html); $html = str_replace('href="', 'href="' . config('app.url'), $html);
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, [], $html), new Response(200, [], $html),
@ -79,18 +83,19 @@ HTML;
]); ]);
} }
public function test_existing_webmention_gets_updated() /** @test */
public function existingWebmentionGetsUpdatedByJob(): void
{ {
Queue::fake(); Queue::fake();
$parser = new Parser(); $parser = new Parser();
$html = <<<HTML $html = <<<HTML
<div class="h-entry"> <div class="h-entry">
<p>In reply to <a class="u-in-reply-to" href="/notes/E">a note</a></p> <p>In reply to <a class="u-in-reply-to" href="/notes/E">a note</a></p>
<div class="e-content">Updated reply</div> <div class="e-content">Updated reply</div>
</div> </div>
HTML; HTML;
$html = str_replace('href="', 'href="' . config('app.url'), $html); $html = str_replace('href="', 'href="' . config('app.url'), $html);
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, [], $html), new Response(200, [], $html),
@ -108,20 +113,22 @@ HTML;
$this->assertDatabaseHas('webmentions', [ $this->assertDatabaseHas('webmentions', [
'source' => $source, 'source' => $source,
'type' => 'in-reply-to', 'type' => 'in-reply-to',
// phpcs:ignore Generic.Files.LineLength.TooLong
'mf2' => '{"rels": [], "items": [{"type": ["h-entry"], "properties": {"content": [{"html": "Updated reply", "value": "Updated reply"}], "in-reply-to": ["' . config('app.url') . '/notes/E"]}}], "rel-urls": []}', 'mf2' => '{"rels": [], "items": [{"type": ["h-entry"], "properties": {"content": [{"html": "Updated reply", "value": "Updated reply"}], "in-reply-to": ["' . config('app.url') . '/notes/E"]}}], "rel-urls": []}',
]); ]);
} }
public function test_webmention_reply_gets_deleted() /** @test */
public function webmentionReplyGetsDeletedWhenReplyToValueChanges(): void
{ {
$parser = new Parser(); $parser = new Parser();
$html = <<<HTML $html = <<<HTML
<div class="h-entry"> <div class="h-entry">
<p>In reply to <a class="u-in-reply-to" href="https://other.com/notes/E">a note</a></p> <p>In reply to <a class="u-in-reply-to" href="https://other.com/notes/E">a note</a></p>
<div class="e-content">Replying to someone else</div> <div class="e-content">Replying to someone else</div>
</div> </div>
HTML; HTML;
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, [], $html), new Response(200, [], $html),
]); ]);
@ -148,16 +155,17 @@ HTML;
]); ]);
} }
public function test_webmention_like_gets_deleted() /** @test */
public function webmentionLikeGetsDeletedWhenLikeOfValueChanges(): void
{ {
$parser = new Parser(); $parser = new Parser();
$html = <<<HTML $html = <<<HTML
<div class="h-entry"> <div class="h-entry">
<p>In reply to <a class="u-like-of" href="https://other.com/notes/E">a note</a></p> <p>In reply to <a class="u-like-of" href="https://other.com/notes/E">a note</a></p>
<div class="e-content">I like someone else now</div> <div class="e-content">I like someone else now</div>
</div> </div>
HTML; HTML;
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, [], $html), new Response(200, [], $html),
]); ]);
@ -184,16 +192,17 @@ HTML;
]); ]);
} }
public function test_webmention_repost_gets_deleted() /** @test */
public function webmentionRepostGetsDeletedWhenRepostOfValueChanges(): void
{ {
$parser = new Parser(); $parser = new Parser();
$html = <<<HTML $html = <<<HTML
<div class="h-entry"> <div class="h-entry">
<p>In reply to <a class="u-repost-of" href="https://other.com/notes/E">a note</a></p> <p>In reply to <a class="u-repost-of" href="https://other.com/notes/E">a note</a></p>
<div class="e-content">Reposting someone else</div> <div class="e-content">Reposting someone else</div>
</div> </div>
HTML; HTML;
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, [], $html), new Response(200, [], $html),
]); ]);

View file

@ -1,16 +1,17 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit\Jobs; namespace Tests\Unit\Jobs;
use Tests\TestCase; use App\Jobs\SaveProfileImage;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use App\Jobs\SaveProfileImage;
use GuzzleHttp\Handler\MockHandler;
use Jonnybarnes\WebmentionsParser\Authorship; use Jonnybarnes\WebmentionsParser\Authorship;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException; use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException;
use Tests\TestCase;
class SaveProfileImageJobTest extends TestCase class SaveProfileImageJobTest extends TestCase
{ {
@ -22,18 +23,21 @@ class SaveProfileImageJobTest extends TestCase
} }
parent::tearDown(); parent::tearDown();
} }
public function test_authorship_algo_exception_return_null()
/** @test */
public function authorshipAlgorithmReturnsNullOnException(): void
{ {
$mf = ['items' => []]; $mf = ['items' => []];
$authorship = $this->createMock(Authorship::class); $authorship = $this->createMock(Authorship::class);
$authorship->method('findAuthor') $authorship->method('findAuthor')
->will($this->throwException(new AuthorshipParserException)); ->will($this->throwException(new AuthorshipParserException()));
$job = new SaveProfileImage($mf); $job = new SaveProfileImage($mf);
$this->assertNull($job->handle($authorship)); $this->assertNull($job->handle($authorship));
} }
public function test_we_dont_process_twitter_images() /** @test */
public function weDoNotProcessTwitterImages(): void
{ {
$mf = ['items' => []]; $mf = ['items' => []];
$author = [ $author = [
@ -50,7 +54,8 @@ class SaveProfileImageJobTest extends TestCase
$this->assertNull($job->handle($authorship)); $this->assertNull($job->handle($authorship));
} }
public function test_saving_of_remote_image() /** @test */
public function remoteAuthorImagesAreSavedLocally(): void
{ {
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['Content-Type' => 'image/jpeg'], 'fake jpeg image'), new Response(200, ['Content-Type' => 'image/jpeg'], 'fake jpeg image'),
@ -74,7 +79,8 @@ class SaveProfileImageJobTest extends TestCase
$this->assertFileExists(public_path() . '/assets/profile-images/example.org/image'); $this->assertFileExists(public_path() . '/assets/profile-images/example.org/image');
} }
public function test_copying_of_local_image() /** @test */
public function localDefaultAuthorImageIsUsedAsFallback(): void
{ {
$mock = new MockHandler([ $mock = new MockHandler([
new Response(404), new Response(404),

View file

@ -1,19 +1,21 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit\Jobs; namespace Tests\Unit\Jobs;
use Tests\TestCase; use App\Jobs\SendWebMentions;
use App\Models\Note; use App\Models\Note;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use App\Jobs\SendWebMentions;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\Handler\MockHandler;
use Illuminate\Foundation\Testing\RefreshDatabase; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Tests\TestCase;
class SendWebMentionJobTest extends TestCase class SendWebMentionJobTest extends TestCase
{ {
public function test_dicover_endoint_method_on_self() /** @test */
public function discoverWebmentionEndpointOnOwnDomain(): void
{ {
$note = new Note(); $note = new Note();
$job = new SendWebMentions($note); $job = new SendWebMentions($note);
@ -21,7 +23,8 @@ class SendWebMentionJobTest extends TestCase
$this->assertNull($job->discoverWebmentionEndpoint('/notes/tagged/test')); $this->assertNull($job->discoverWebmentionEndpoint('/notes/tagged/test'));
} }
public function test_discover_endpoint_gets_link_from_headers() /** @test */
public function discoverWebmentionEndpointFromHeaderLinks(): void
{ {
$url = 'https://example.org/webmention'; $url = 'https://example.org/webmention';
$mock = new MockHandler([ $mock = new MockHandler([
@ -35,7 +38,8 @@ class SendWebMentionJobTest extends TestCase
$this->assertEquals($url, $job->discoverWebmentionEndpoint('https://example.org')); $this->assertEquals($url, $job->discoverWebmentionEndpoint('https://example.org'));
} }
public function test_discover_endpoint_correctly_parses_html() /** @test */
public function discoverWebmentionEndpointFromHtmlLinkTags(): void
{ {
$html = '<link rel="webmention" href="https://example.org/webmention">'; $html = '<link rel="webmention" href="https://example.org/webmention">';
$mock = new MockHandler([ $mock = new MockHandler([
@ -52,7 +56,8 @@ class SendWebMentionJobTest extends TestCase
); );
} }
public function test_discover_endpoint_correctly_parses_html_legacy() /** @test */
public function discoverWebmentionEndpointFromLegacyHtmlMarkup(): void
{ {
$html = '<link rel="http://webmention.org/" href="https://example.org/webmention">'; $html = '<link rel="http://webmention.org/" href="https://example.org/webmention">';
$mock = new MockHandler([ $mock = new MockHandler([
@ -69,13 +74,15 @@ class SendWebMentionJobTest extends TestCase
); );
} }
public function test_empty_note_does_nothing() /** @test */
public function ensureEmptyNoteDoesNotTriggerAnyActions(): void
{ {
$job = new SendWebMentions(new Note()); $job = new SendWebMentions(new Note());
$this->assertNull($job->handle()); $this->assertNull($job->handle());
} }
public function test_resolve_uri() /** @test */
public function weResolveRelativeUris(): void
{ {
$uri = '/blog/post'; $uri = '/blog/post';
$base = 'https://example.org/'; $base = 'https://example.org/';
@ -83,7 +90,8 @@ class SendWebMentionJobTest extends TestCase
$this->assertEquals('https://example.org/blog/post', $job->resolveUri($uri, $base)); $this->assertEquals('https://example.org/blog/post', $job->resolveUri($uri, $base));
} }
public function test_the_job() /** @test */
public function weSendAWebmentionForANote(): void
{ {
$html = '<link rel="http://webmention.org/" href="https://example.org/webmention">'; $html = '<link rel="http://webmention.org/" href="https://example.org/webmention">';
$mock = new MockHandler([ $mock = new MockHandler([
@ -98,6 +106,7 @@ class SendWebMentionJobTest extends TestCase
$note->note = 'Hi [Aaron](https://aaronparecki.com)'; $note->note = 'Hi [Aaron](https://aaronparecki.com)';
$note->save(); $note->save();
$job = new SendWebMentions($note); $job = new SendWebMentions($note);
$this->assertNull($job->handle()); $job->handle();
$this->assertTrue(true);
} }
} }

View file

@ -1,21 +1,24 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit\Jobs; namespace Tests\Unit\Jobs;
use Tests\TestCase; use App\Jobs\SyndicateBookmarkToTwitter;
use GuzzleHttp\Client;
use App\Models\Bookmark; use App\Models\Bookmark;
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 App\Jobs\SyndicateBookmarkToTwitter;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class SyndicateBookmarkToTwitterJobTest extends TestCase class SyndicateBookmarkToTwitterJobTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_the_job() /** @test */
public function weSendBookmarksToTwitter(): void
{ {
$json = json_encode([ $json = json_encode([
'url' => 'https://twitter.com/123' 'url' => 'https://twitter.com/123'

View file

@ -2,20 +2,21 @@
namespace Tests\Unit\Jobs; namespace Tests\Unit\Jobs;
use Tests\TestCase; use App\Jobs\SyndicateNoteToTwitter;
use App\Models\Note; use App\Models\Note;
use GuzzleHttp\Client; 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 App\Jobs\SyndicateNoteToTwitter;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class SyndicateNoteToTwitterJobTest extends TestCase class SyndicateNoteToTwitterJobTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_the_job() /** @test */
public function weSyndicateNotesToTwitter(): void
{ {
$json = json_encode([ $json = json_encode([
'url' => 'https://twitter.com/i/web/status/123' 'url' => 'https://twitter.com/i/web/status/123'

View file

@ -1,23 +1,27 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit; namespace Tests\Unit;
use Tests\TestCase;
use App\Models\Like; use App\Models\Like;
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_setting_author_url() /** @test */
public function weCanSetTheAuthorUrl(): void
{ {
$like = new Like(); $like = new Like();
$like->author_url = 'https://joe.bloggs/'; $like->author_url = 'https://joe.bloggs/';
$this->assertEquals('https://joe.bloggs', $like->author_url); $this->assertEquals('https://joe.bloggs', $like->author_url);
} }
public function test_plaintext_like_content() /** @test */
public function weDoNotModifyPlainTextContent(): void
{ {
$like = new Like(); $like = new Like();
$like->url = 'https://example.org/post/123'; $like->url = 'https://example.org/post/123';
@ -27,27 +31,28 @@ class LikesTest extends TestCase
$this->assertEquals('some plaintext content', $like->content); $this->assertEquals('some plaintext content', $like->content);
} }
public function test_html_like_content_is_filtered() /** @test */
public function htmlLikeContentIsFiltered(): void
{ {
$htmlEvil = <<<HTML $htmlEvil = <<<HTML
<div class="h-entry"> <div class="h-entry">
<div class="e-content"> <div class="e-content">
<p>Hello</p> <p>Hello</p>
<img src="javascript:evil();" onload="evil();" /> <img src="javascript:evil();" onload="evil();" />
</div> </div>
</div> </div>
HTML; HTML;
$htmlFiltered = <<<HTML $htmlFiltered = <<<HTML
<p>Hello</p> <p>Hello</p>
<img /> <img />
HTML; HTML;
$like = new Like(); $like = new Like();
$like->url = 'https://example.org/post/123'; $like->url = 'https://example.org/post/123';
$like->content = $htmlEvil; $like->content = $htmlEvil;
$like->save(); $like->save();
// HTMLPurifer will leave the whitespace before the <img> tag // HTMLPurifier will leave the whitespace before the <img> tag
// trim it, saving whitespace in $htmlFilteres can get removed by text editors // trim it, saving whitespace in $htmlFiltered can get removed by text editors
$this->assertEquals($htmlFiltered, trim($like->content)); $this->assertEquals($htmlFiltered, trim($like->content));
} }
} }

View file

@ -1,20 +1,24 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit; namespace Tests\Unit;
use Tests\TestCase;
use App\Models\Media; use App\Models\Media;
use Tests\TestCase;
class MediaTest extends TestCase class MediaTest extends TestCase
{ {
public function test_get_note_from_media() /** @test */
public function getTheNoteThatMediaInstanceBelongsTo(): void
{ {
$media = Media::find(1); $media = Media::find(1);
$note = $media->note; $note = $media->note;
$this->assertInstanceOf('App\Models\Note', $note); $this->assertInstanceOf('App\Models\Note', $note);
} }
public function test_media_absolute_url_returned_unmodified() /** @test */
public function absoluteUrlsAreReturnedUnmodified(): void
{ {
$absoluteUrl = 'https://instagram-cdn.com/image/uuid'; $absoluteUrl = 'https://instagram-cdn.com/image/uuid';
$media = new Media(); $media = new Media();

View file

@ -1,15 +1,17 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit; namespace Tests\Unit;
use Tests\TestCase;
use App\Models\MicropubClient; use App\Models\MicropubClient;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase;
class MicropbClientsTest extends TestCase class MicropubClientsTest extends TestCase
{ {
public function test_notes_relationship() /** @test */
public function weCanGetNotesRelatingToClient(): void
{ {
$client = MicropubClient::find(1); $client = MicropubClient::find(1);
$this->assertInstanceOf(Collection::class, $client->notes); $this->assertInstanceOf(Collection::class, $client->notes);

View file

@ -1,14 +1,16 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit; namespace Tests\Unit;
use Tests\TestCase; use App\Models\{Media, Note, Tag};
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use App\Models\{Media, Note, Tag};
use GuzzleHttp\Handler\MockHandler;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class NotesTest extends TestCase class NotesTest extends TestCase
{ {
@ -18,10 +20,12 @@ class NotesTest extends TestCase
* Test the getNoteAttribute method. This will then also call the * Test the getNoteAttribute method. This will then also call the
* relevant sub-methods. * relevant sub-methods.
* *
* @test
* @return void * @return void
*/ */
public function test_get_note_attribute_method() public function getNoteAttributeMethodCallsSubMethods(): void
{ {
// phpcs:ignore
$expected = '<p>Having a <a rel="tag" class="p-category" href="/notes/tagged/beer">#beer</a> at the local. 🍺</p>' . PHP_EOL; $expected = '<p>Having a <a rel="tag" class="p-category" href="/notes/tagged/beer">#beer</a> at the local. 🍺</p>' . PHP_EOL;
$note = Note::find(2); $note = Note::find(2);
$this->assertEquals($expected, $note->note); $this->assertEquals($expected, $note->note);
@ -30,10 +34,12 @@ class NotesTest extends TestCase
/** /**
* Look for a default image in the contacts h-card for the makeHCards method. * Look for a default image in the contacts h-card for the makeHCards method.
* *
* @test
* @return void * @return void
*/ */
public function test_default_image_used_in_makehcards_method() public function defaultImageUsedAsFallbackInMakehcardsMethod(): void
{ {
// phpcs:ignore
$expected = '<p>Hi <span class="u-category h-card mini-h-card"><a class="u-url p-name" href="http://tantek.com">Tantek Çelik</a><span class="hovercard"> <a class="u-url" href="https://twitter.com/t"><img class="social-icon" src="/assets/img/social-icons/twitter.svg"> t</a><img class="u-photo" alt="" src="/assets/profile-images/default-image"></span></span></p>' . PHP_EOL; $expected = '<p>Hi <span class="u-category h-card mini-h-card"><a class="u-url p-name" href="http://tantek.com">Tantek Çelik</a><span class="hovercard"> <a class="u-url" href="https://twitter.com/t"><img class="social-icon" src="/assets/img/social-icons/twitter.svg"> t</a><img class="u-photo" alt="" src="/assets/profile-images/default-image"></span></span></p>' . PHP_EOL;
$note = Note::find(4); $note = Note::find(4);
$this->assertEquals($expected, $note->note); $this->assertEquals($expected, $note->note);
@ -42,10 +48,12 @@ class NotesTest extends TestCase
/** /**
* Look for a specific profile image in the contacts h-card. * Look for a specific profile image in the contacts h-card.
* *
* @test
* @return void * @return void
*/ */
public function test_specific_profile_image_used_in_makehcards_method() public function specificProfileImageUsedInMakehcardsMethod(): void
{ {
// phpcs:ignore
$expected = '<p>Hi <span class="u-category h-card mini-h-card"><a class="u-url p-name" href="https://aaronparecki.com">Aaron Parecki</a><span class="hovercard"><a class="u-url" href="https://www.facebook.com/123456"><img class="social-icon" src="/assets/img/social-icons/facebook.svg"> Facebook</a> <img class="u-photo" alt="" src="/assets/profile-images/aaronparecki.com/image"></span></span></p>' . PHP_EOL; $expected = '<p>Hi <span class="u-category h-card mini-h-card"><a class="u-url p-name" href="https://aaronparecki.com">Aaron Parecki</a><span class="hovercard"><a class="u-url" href="https://www.facebook.com/123456"><img class="social-icon" src="/assets/img/social-icons/facebook.svg"> Facebook</a> <img class="u-photo" alt="" src="/assets/profile-images/aaronparecki.com/image"></span></span></p>' . PHP_EOL;
$note = Note::find(5); $note = Note::find(5);
$this->assertEquals($expected, $note->note); $this->assertEquals($expected, $note->note);
@ -54,42 +62,48 @@ class NotesTest extends TestCase
/** /**
* Look for twitter URL when theres no associated contact. * Look for twitter URL when theres no associated contact.
* *
* @test
* @return void * @return void
*/ */
public function test_twitter_link_created_when_no_contact_found() public function twitterLinkIsCreatedWhenNoContactFound(): void
{ {
$expected = '<p>Hi <a href="https://twitter.com/bob">@bob</a></p>' . PHP_EOL; $expected = '<p>Hi <a href="https://twitter.com/bob">@bob</a></p>' . PHP_EOL;
$note = Note::find(6); $note = Note::find(6);
$this->assertEquals($expected, $note->note); $this->assertEquals($expected, $note->note);
} }
public function test_shorturl_method() /** @test */
public function shorturlMethodReturnsExpectedValue(): void
{ {
$note = Note::find(14); $note = Note::find(14);
$this->assertEquals(config('app.shorturl') . '/notes/E', $note->shorturl); $this->assertEquals(config('app.shorturl') . '/notes/E', $note->shorturl);
} }
public function test_latlng_of_associated_place() /** @test */
public function weGetLatitudeLongitudeValuesOfAssociatedPlaceOfNote(): void
{ {
$note = Note::find(2); // should be having beer at bridgewater note $note = Note::find(2); // should be having beer at bridgewater note
$this->assertEquals('53.4983', $note->latitude); $this->assertEquals('53.4983', $note->latitude);
$this->assertEquals('-2.3805', $note->longitude); $this->assertEquals('-2.3805', $note->longitude);
} }
public function test_latlng_returns_null_otherwise() /** @test */
public function whenNoAssociatedPlaceWeGetNullForLatitudeLongitudeValues(): void
{ {
$note = Note::find(5); $note = Note::find(5);
$this->assertNull($note->latitude); $this->assertNull($note->latitude);
$this->assertNull($note->longitude); $this->assertNull($note->longitude);
} }
public function test_address_attribute_for_places() /** @test */
public function weCanGetAddressAttributeForAssociatedPlace(): void
{ {
$note = Note::find(2); $note = Note::find(2);
$this->assertEquals('The Bridgewater Pub', $note->address); $this->assertEquals('The Bridgewater Pub', $note->address);
} }
public function test_deleting_event_observer() /** @test */
public function deletingNotesAlsoDeletesTagsViaTheEventObserver(): void
{ {
// first well create a temporary note to delete // first well create a temporary note to delete
$note = Note::create(['note' => 'temporary #temp']); $note = Note::create(['note' => 'temporary #temp']);
@ -104,7 +118,7 @@ class NotesTest extends TestCase
} }
/** @test */ /** @test */
public function blank_note_should_be_saved_as_null() public function saveBlankNotesAsNull(): void
{ {
$note = new Note(['note' => '']); $note = new Note(['note' => '']);
@ -112,11 +126,13 @@ class NotesTest extends TestCase
} }
/** @test */ /** @test */
public function reverse_geocode_an_attraction() public function reverseGeocodeAnAttraction(): void
{ {
// phpcs:disable Generic.Files.LineLength.TooLong
$json = <<<JSON $json = <<<JSON
{"place_id":"198791063","licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright","osm_type":"relation","osm_id":"5208404","lat":"51.50084125","lon":"-0.142990166340849","display_name":"Buckingham Palace, Ambassador's Court, St. James's, Victoria, Westminster, London, Greater London, England, SW1E 6LA, United Kingdom","address":{"attraction":"Buckingham Palace","road":"Ambassador's Court","neighbourhood":"St. James's","suburb":"Victoria","city":"London","state_district":"Greater London","state":"England","postcode":"SW1E 6LA","country":"UK","country_code":"gb"},"boundingbox":["51.4997342","51.5019473","-0.143984","-0.1413002"]} {"place_id":"198791063","licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright","osm_type":"relation","osm_id":"5208404","lat":"51.50084125","lon":"-0.142990166340849","display_name":"Buckingham Palace, Ambassador's Court, St. James's, Victoria, Westminster, London, Greater London, England, SW1E 6LA, United Kingdom","address":{"attraction":"Buckingham Palace","road":"Ambassador's Court","neighbourhood":"St. James's","suburb":"Victoria","city":"London","state_district":"Greater London","state":"England","postcode":"SW1E 6LA","country":"UK","country_code":"gb"},"boundingbox":["51.4997342","51.5019473","-0.143984","-0.1413002"]}
JSON; JSON;
// phpcs:enable Generic.Files.LineLength.TooLong
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['Content-Type' => 'application/json'], $json), new Response(200, ['Content-Type' => 'application/json'], $json),
]); ]);
@ -128,15 +144,20 @@ JSON;
$note = new Note(); $note = new Note();
$address = $note->reverseGeoCode(51.50084, -0.14264); $address = $note->reverseGeoCode(51.50084, -0.14264);
$this->assertEquals('<span class="p-locality">Victoria, London</span>, <span class="p-country-name">UK</span>', $address); $this->assertEquals(
'<span class="p-locality">Victoria, London</span>, <span class="p-country-name">UK</span>',
$address
);
} }
/** @test */ /** @test */
public function reverse_geocode_a_suburb() public function reverseGeocodeASuburb(): void
{ {
// phpcs:disable Generic.Files.LineLength.TooLong
$json = <<<JSON $json = <<<JSON
{"place_id":"96518506","licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright","osm_type":"way","osm_id":"94107885","lat":"51.0225764535969","lon":"0.906664040464189","display_name":"Melon Lane, Newchurch, Shepway, Kent, South East, England, TN29 0AS, United Kingdom","address":{"road":"Melon Lane","suburb":"Newchurch","city":"Shepway","county":"Kent","state_district":"South East","state":"England","postcode":"TN29 0AS","country":"UK","country_code":"gb"},"boundingbox":["51.0140377","51.0371494","0.8873312","0.9109506"]} {"place_id":"96518506","licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright","osm_type":"way","osm_id":"94107885","lat":"51.0225764535969","lon":"0.906664040464189","display_name":"Melon Lane, Newchurch, Shepway, Kent, South East, England, TN29 0AS, United Kingdom","address":{"road":"Melon Lane","suburb":"Newchurch","city":"Shepway","county":"Kent","state_district":"South East","state":"England","postcode":"TN29 0AS","country":"UK","country_code":"gb"},"boundingbox":["51.0140377","51.0371494","0.8873312","0.9109506"]}
JSON; JSON;
// phpcs:enable Generic.Files.LineLength.TooLong
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['Content-Type' => 'application/json'], $json), new Response(200, ['Content-Type' => 'application/json'], $json),
]); ]);
@ -148,17 +169,22 @@ JSON;
$note = new Note(); $note = new Note();
$address = $note->reverseGeoCode(51.02, 0.91); $address = $note->reverseGeoCode(51.02, 0.91);
$this->assertEquals('<span class="p-locality">Newchurch, Shepway</span>, <span class="p-country-name">UK</span>', $address); $this->assertEquals(
'<span class="p-locality">Newchurch, Shepway</span>, <span class="p-country-name">UK</span>',
$address
);
} }
/** @test */ /** @test */
public function reverse_geocode_a_city() public function reverseGeocodeACity(): void
{ {
// Note Ive modified this JSON response so it only contains the // Note Ive modified this JSON response so it only contains the
// city the Uni is in // city the Uni is in
// phpcs:disable Generic.Files.LineLength.TooLong
$json = <<<JSON $json = <<<JSON
{"place_id":"198561071","licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright","osm_type":"relation","osm_id":"1839026","lat":"53.46600455","lon":"-2.23300880782987","display_name":"University of Manchester - Main Campus, Brunswick Street, Curry Mile, Ardwick, Manchester, Greater Manchester, North West England, England, M13 9NR, United Kingdom","address":{"university":"University of Manchester - Main Campus","city":"Manchester","county":"Greater Manchester","state_district":"North West England","state":"England","postcode":"M13 9NR","country":"UK","country_code":"gb"},"boundingbox":["53.4598667","53.4716848","-2.2390346","-2.2262754"]} {"place_id":"198561071","licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright","osm_type":"relation","osm_id":"1839026","lat":"53.46600455","lon":"-2.23300880782987","display_name":"University of Manchester - Main Campus, Brunswick Street, Curry Mile, Ardwick, Manchester, Greater Manchester, North West England, England, M13 9NR, United Kingdom","address":{"university":"University of Manchester - Main Campus","city":"Manchester","county":"Greater Manchester","state_district":"North West England","state":"England","postcode":"M13 9NR","country":"UK","country_code":"gb"},"boundingbox":["53.4598667","53.4716848","-2.2390346","-2.2262754"]}
JSON; JSON;
// phpcs:enable Generic.Files.LineLength.TooLong
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['Content-Type' => 'application/json'], $json), new Response(200, ['Content-Type' => 'application/json'], $json),
]); ]);
@ -170,17 +196,22 @@ JSON;
$note = new Note(); $note = new Note();
$address = $note->reverseGeoCode(53.466277988406, -2.2304474827445); $address = $note->reverseGeoCode(53.466277988406, -2.2304474827445);
$this->assertEquals('<span class="p-locality">Manchester</span>, <span class="p-country-name">UK</span>', $address); $this->assertEquals(
'<span class="p-locality">Manchester</span>, <span class="p-country-name">UK</span>',
$address
);
} }
/** @test */ /** @test */
public function reverse_geocode_a_county() public function reverseGeocodeACounty(): void
{ {
// Note Ive removed everything below county to test for querires where // Note Ive removed everything below county to test for querires where
// thats all that is returned // thats all that is returned
// phpcs:disable Generic.Files.LineLength.TooLong
$json = <<<JSON $json = <<<JSON
{"place_id":"98085404","licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright","osm_type":"way","osm_id":"103703318","lat":"51.0997470194065","lon":"0.609897771085209","display_name":"Biddenden, Ashford, Kent, South East, England, TN27 8ET, United Kingdom","address":{"county":"Kent","state_district":"South East","state":"England","postcode":"TN27 8ET","country":"UK","country_code":"gb"},"boundingbox":["51.0986632","51.104459","0.5954434","0.6167775"]} {"place_id":"98085404","licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright","osm_type":"way","osm_id":"103703318","lat":"51.0997470194065","lon":"0.609897771085209","display_name":"Biddenden, Ashford, Kent, South East, England, TN27 8ET, United Kingdom","address":{"county":"Kent","state_district":"South East","state":"England","postcode":"TN27 8ET","country":"UK","country_code":"gb"},"boundingbox":["51.0986632","51.104459","0.5954434","0.6167775"]}
JSON; JSON;
// phpcs:enable Generic.Files.LineLength.TooLong
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['Content-Type' => 'application/json'], $json), new Response(200, ['Content-Type' => 'application/json'], $json),
]); ]);
@ -196,13 +227,15 @@ JSON;
} }
/** @test */ /** @test */
public function reverse_geocode_a_country() public function reverseGeocodeACountry(): void
{ {
// Note Ive removed everything below country to test for querires where // Note Ive removed everything below country to test for querires where
// thats all that is returned // thats all that is returned
// phpcs:disable Generic.Files.LineLength.TooLong
$json = <<<JSON $json = <<<JSON
{"place_id":"120553244","licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright","osm_type":"way","osm_id":"191508282","lat":"54.3004150140189","lon":"-9.39993720828084","display_name":"R314, Doonfeeny Lower, Ballycastle ED, Ballina, County Mayo, Connacht, Ireland","address":{"country":"Ireland","country_code":"ie"},"boundingbox":["54.2964027","54.3045856","-9.4337961","-9.3960403"]} {"place_id":"120553244","licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright","osm_type":"way","osm_id":"191508282","lat":"54.3004150140189","lon":"-9.39993720828084","display_name":"R314, Doonfeeny Lower, Ballycastle ED, Ballina, County Mayo, Connacht, Ireland","address":{"country":"Ireland","country_code":"ie"},"boundingbox":["54.2964027","54.3045856","-9.4337961","-9.3960403"]}
JSON; JSON;
// phpcs:enable Generic.Files.LineLength.TooLong
$mock = new MockHandler([ $mock = new MockHandler([
new Response(200, ['Content-Type' => 'application/json'], $json), new Response(200, ['Content-Type' => 'application/json'], $json),
]); ]);
@ -218,12 +251,12 @@ JSON;
} }
/** @test */ /** @test */
public function add_image_element_to_note_content() public function addImageElementToNoteContentWhenMediaAssociated(): void
{ {
$media = new Media([ $media = new Media([
'type' => 'image', 'type' => 'image',
'path' => 'test.png'] 'path' => 'test.png',
); ]);
$media->save(); $media->save();
$note = new Note(['note' => 'A nice image']); $note = new Note(['note' => 'A nice image']);
$note->save(); $note->save();
@ -235,12 +268,12 @@ JSON;
} }
/** @test */ /** @test */
public function add_video_element_to_note_content() public function addVideoElementToNoteContentWhenMediaAssociated(): void
{ {
$media = new Media([ $media = new Media([
'type' => 'video', 'type' => 'video',
'path' => 'test.mkv'] 'path' => 'test.mkv',
); ]);
$media->save(); $media->save();
$note = new Note(['note' => 'A nice video']); $note = new Note(['note' => 'A nice video']);
$note->save(); $note->save();
@ -252,12 +285,12 @@ JSON;
} }
/** @test */ /** @test */
public function add_audio_element_to_note_content() public function addAudioElementToNoteContentWhenMediaAssociated(): void
{ {
$media = new Media([ $media = new Media([
'type' => 'audio', 'type' => 'audio',
'path' => 'test.flac'] 'path' => 'test.flac',
); ]);
$media->save(); $media->save();
$note = new Note(['note' => 'Some nice audio']); $note = new Note(['note' => 'Some nice audio']);
$note->save(); $note->save();
@ -268,24 +301,29 @@ JSON;
$this->assertEquals($expected, $note->content); $this->assertEquals($expected, $note->content);
} }
/** @test */ /**
public function blank_note_content() * @test
* @todo Why do we need to provide text?
*/
public function provideTextForBlankContent(): void
{ {
$note = new Note(); $note = new Note();
$this->assertEquals('A blank note', $note->content); $this->assertEquals('A blank note', $note->content);
} }
/** @test */ // @todo Sort out twitter requests
public function twitter_content_is_null_when_oembed_error_occurs() /** @test
public function setTwitterContentToNullWhenOembedErrorOccurs(): void
{ {
$note = new Note(); $note = new Note();
$note->in_reply_to = 'https://twitter.com/search'; $note->in_reply_to = 'https://twitter.com/search';
$this->assertNull($note->twitter); $this->assertNull($note->twitter);
} }*/
public function test_markdown_gets_converted() /** @test */
public function markdownContentGetsConverted(): void
{ {
$note = Note::create([ $note = Note::create([
'note' => 'The best search engine? https://duckduckgo.com', 'note' => 'The best search engine? https://duckduckgo.com',

View file

@ -1,55 +1,57 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit; namespace Tests\Unit;
use Tests\TestCase;
use App\Models\Place; use App\Models\Place;
use App\Services\PlaceService; use App\Services\PlaceService;
use MStaack\LaravelPostgis\Geometries\Point;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use InvalidArgumentException;
use Tests\TestCase;
class PlacesTest extends TestCase class PlacesTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function test_notes_method() /** @test */
public function canRetrieveAssociatedNotes(): void
{ {
$place = Place::find(1); $place = Place::find(1);
$this->assertInstanceOf(Collection::class, $place->notes); $this->assertInstanceOf(Collection::class, $place->notes);
} }
/** /** @test */
* Test the near method returns a collection. public function nearMethodReturnsCollection(): void
*
* @return void
*/
public function test_near_method()
{ {
$nearby = Place::near((object) ['latitude' => 53.5, 'longitude' => -2.38], 1000)->get(); $nearby = Place::near((object) ['latitude' => 53.5, 'longitude' => -2.38], 1000)->get();
$this->assertEquals('the-bridgewater-pub', $nearby[0]->slug); $this->assertEquals('the-bridgewater-pub', $nearby[0]->slug);
} }
public function test_longurl_method() /** @test */
public function getLongurl(): void
{ {
$place = Place::find(1); $place = Place::find(1);
$this->assertEquals(config('app.url') . '/places/the-bridgewater-pub', $place->longurl); $this->assertEquals(config('app.url') . '/places/the-bridgewater-pub', $place->longurl);
} }
public function test_uri_method() /** @test */
{ public function getShorturl()
$place = Place::find(1);
$this->assertEquals(config('app.url') . '/places/the-bridgewater-pub', $place->uri);
}
public function test_shorturl_method()
{ {
$place = Place::find(1); $place = Place::find(1);
$this->assertEquals(config('app.shorturl') . '/places/the-bridgewater-pub', $place->shorturl); $this->assertEquals(config('app.shorturl') . '/places/the-bridgewater-pub', $place->shorturl);
} }
public function test_service_returns_existing_place() /** @test */
public function getUri(): void
{
$place = Place::find(1);
$this->assertEquals(config('app.url') . '/places/the-bridgewater-pub', $place->uri);
}
/** @test */
public function placeServiceReturnsExistingPlaceBasedOnExternalUrlsSearch(): void
{ {
$place = new Place(); $place = new Place();
$place->name = 'Temp Place'; $place->name = 'Temp Place';
@ -64,28 +66,31 @@ class PlacesTest extends TestCase
] ]
]); ]);
$this->assertInstanceOf('App\Models\Place', $ret); // a place was returned $this->assertInstanceOf('App\Models\Place', $ret); // a place was returned
$this->assertEquals(12, count(Place::all())); // still 2 places $this->assertCount(12, Place::all()); // still 12 places
} }
public function test_service_requires_name() /** @test */
public function placeServiceRequiresNameWhenCreatingNewPlace(): void
{ {
$this->expectException(\InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Missing required name'); $this->expectExceptionMessage('Missing required name');
$service = new PlaceService(); $service = new PlaceService();
$service->createPlaceFromCheckin(['foo' => 'bar']); $service->createPlaceFromCheckin(['foo' => 'bar']);
} }
public function test_service_requires_latitude() /** @test */
public function placeServiceRequiresLatitudeWhenCreatingNewPlace(): void
{ {
$this->expectException(\InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Missing required longitude/latitude'); $this->expectExceptionMessage('Missing required longitude/latitude');
$service = new PlaceService(); $service = new PlaceService();
$service->createPlaceFromCheckin(['properties' => ['name' => 'bar']]); $service->createPlaceFromCheckin(['properties' => ['name' => 'bar']]);
} }
public function test_updating_external_urls() /** @test */
public function placeServcieCanupdateExternalUrls(): void
{ {
$place = Place::find(1); $place = Place::find(1);
$place->external_urls = 'https://bridgewater.pub'; $place->external_urls = 'https://bridgewater.pub';

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit; namespace Tests\Unit;
use App\Models\Tag; use App\Models\Tag;
@ -7,15 +9,17 @@ use Tests\TestCase;
class TagsTest extends TestCase class TagsTest extends TestCase
{ {
public function test_notes_method() /** @test */
public function canGetAssociatedNotes(): void
{ {
$tag = Tag::find(1); // should be beer tag $tag = Tag::find(1); // should be beer tag
$this->assertEquals(1, count($tag->notes)); $this->assertCount(1, $tag->notes);
} }
public function test_bookmarks_method() /** @test */
public function canGetAssociatedBookmarks(): void
{ {
$tag = Tag::find(5); //should be first random tag for bookmarks $tag = Tag::find(5); //should be first random tag for bookmarks
$this->assertEquals(1, count($tag->bookmarks)); $this->assertCount(1, $tag->bookmarks);
} }
} }

View file

@ -1,32 +1,38 @@
<?php <?php
declare(strict_types=1);
namespace Tests\Unit; namespace Tests\Unit;
use Codebird\Codebird;
use Tests\TestCase;
use App\Models\WebMention; use App\Models\WebMention;
use Thujohn\Twitter\Facades\Twitter; use Codebird\Codebird;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Tests\TestCase;
class WebMentionTest extends TestCase class WebMentionTest extends TestCase
{ {
public function test_commentable_method() /** @test */
public function commentableMethodLinksToNotes(): void
{ {
$webmention = WebMention::find(1); $webmention = WebMention::find(1);
$this->assertInstanceOf('App\Models\Note', $webmention->commentable); $this->assertInstanceOf('App\Models\Note', $webmention->commentable);
} }
public function test_published_attribute_when_no_relavent_mf2()
/** @test */
public function publishedAttributeUsesUpdatedAtWhenNoRelevantMf2Data(): void
{ {
$webmention = new WebMention(); $webmention = new WebMention();
$updated_at = carbon()->now(); $updated_at = Carbon::now();
$webmention->updated_at = $updated_at; $webmention->updated_at = $updated_at;
$this->assertEquals($updated_at->toDayDateTimeString(), $webmention->published); $this->assertEquals($updated_at->toDayDateTimeString(), $webmention->published);
} }
public function test_published_attribute_when_error_parsing_mf2() /** @test */
public function publishedAttributeUsesUpdatedAtWhenErrorParsingMf2Data(): void
{ {
$webmention = new WebMention(); $webmention = new WebMention();
$updated_at = carbon()->now(); $updated_at = Carbon::now();
$webmention->updated_at = $updated_at; $webmention->updated_at = $updated_at;
$webmention->mf2 = json_encode([ $webmention->mf2 = json_encode([
'items' => [[ 'items' => [[
@ -40,12 +46,8 @@ class WebMentionTest extends TestCase
$this->assertEquals($updated_at->toDayDateTimeString(), $webmention->published); $this->assertEquals($updated_at->toDayDateTimeString(), $webmention->published);
} }
/** /** @test */
* Test a correct profile link is formed from a generic URL. public function createPhotoLinkDoesNothingWithGenericUrlAndNoLocallySavedImage(): void
*
* @return void
*/
public function test_create_photo_link_with_non_cached_image()
{ {
$webmention = new WebMention(); $webmention = new WebMention();
$homepage = 'https://example.org/profile.png'; $homepage = 'https://example.org/profile.png';
@ -53,12 +55,8 @@ class WebMentionTest extends TestCase
$this->assertEquals($expected, $webmention->createPhotoLink($homepage)); $this->assertEquals($expected, $webmention->createPhotoLink($homepage));
} }
/** /** @test */
* Test a correct profile link is formed from a generic URL (cached). public function createPhotoLinkReturnsLocallySavedImageUrlIfItExists(): void
*
* @return void
*/
public function test_create_photo_link_with_cached_image()
{ {
$webmention = new WebMention(); $webmention = new WebMention();
$homepage = 'https://aaronparecki.com/profile.png'; $homepage = 'https://aaronparecki.com/profile.png';
@ -66,12 +64,8 @@ class WebMentionTest extends TestCase
$this->assertEquals($expected, $webmention->createPhotoLink($homepage)); $this->assertEquals($expected, $webmention->createPhotoLink($homepage));
} }
/** /** @test */
* Test a correct profile link is formed from a twitter URL. public function createPhotoLinkDealsWithSpecialCaseOfDirectTwitterPhotoLinks(): void
*
* @return void
*/
public function test_create_photo_link_with_twimg_profile_image_url()
{ {
$webmention = new WebMention(); $webmention = new WebMention();
$twitterProfileImage = 'http://pbs.twimg.com/1234'; $twitterProfileImage = 'http://pbs.twimg.com/1234';
@ -79,12 +73,8 @@ class WebMentionTest extends TestCase
$this->assertEquals($expected, $webmention->createPhotoLink($twitterProfileImage)); $this->assertEquals($expected, $webmention->createPhotoLink($twitterProfileImage));
} }
/** /** @test */
* Test `null` is returned for a twitter profile. public function createPhotoLinkReturnsCachedTwitterPhotoLinks(): void
*
* @return void
*/
public function test_create_photo_link_with_cached_twitter_url()
{ {
$webmention = new WebMention(); $webmention = new WebMention();
$twitterURL = 'https://twitter.com/example'; $twitterURL = 'https://twitter.com/example';
@ -93,10 +83,12 @@ class WebMentionTest extends TestCase
$this->assertEquals($expected, $webmention->createPhotoLink($twitterURL)); $this->assertEquals($expected, $webmention->createPhotoLink($twitterURL));
} }
public function test_create_photo_link_with_noncached_twitter_url() /** @test */
public function createPhotoLinkResolvesTwitterPhotoLinks(): void
{ {
$info = new \stdClass(); $info = (object) [
$info->profile_image_url_https = 'https://pbs.twimg.com/static_profile_link.jpg'; 'profile_image_url_https' => 'https://pbs.twimg.com/static_profile_link.jpg',
];
$codebirdMock = $this->getMockBuilder(Codebird::class) $codebirdMock = $this->getMockBuilder(Codebird::class)
->addMethods(['users_show']) ->addMethods(['users_show'])
->getMock(); ->getMock();
@ -117,13 +109,15 @@ class WebMentionTest extends TestCase
$this->assertEquals($expected, $webmention->createPhotoLink($twitterURL)); $this->assertEquals($expected, $webmention->createPhotoLink($twitterURL));
} }
public function test_get_reply_attribute_returns_null() /** @test */
public function getReplyAttributeDefaultsToNull(): void
{ {
$webmention = new WebMention(); $webmention = new WebMention();
$this->assertNull($webmention->reply); $this->assertNull($webmention->reply);
} }
public function test_get_reply_attribute_with_mf2_without_html_returns_null() /** @test */
public function getReplyAttributeWithMf2WithoutHtmlReturnsNull(): void
{ {
$webmention = new WebMention(); $webmention = new WebMention();
$webmention->mf2 = json_encode(['no_html' => 'found_here']); $webmention->mf2 = json_encode(['no_html' => 'found_here']);

View file

@ -1,39 +0,0 @@
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
#fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 1800;
fastcgi_read_timeout 1800;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_keep_conn on;

View file

@ -1,47 +0,0 @@
#!/bin/bash
set -e
set -x
DIR=$(realpath $(dirname "$0"))
USER=$(whoami)
PHP_VERSION=$(phpenv version-name)
ROOT=$(realpath "$DIR/..")
HTTP_PORT=8000
PHP_PORT=9000
SERVER="/tmp/php.sock"
function tpl {
sed \
-e "s|{DIR}|$DIR|g" \
-e "s|{USER}|$USER|g" \
-e "s|{PHP_VERSION}|$PHP_VERSION|g" \
-e "s|{ROOT}|$ROOT|g" \
-e "s|{HTTP_PORT}|$HTTP_PORT|g" \
-e "s|{PHP_PORT}|$PHP_PORT|g" \
-e "s|{SERVER}|$SERVER|g" \
< $1 > $2
}
# Make some working directories.
mkdir "$DIR/nginx"
mkdir "$DIR/nginx/sites-enabled"
mkdir "$DIR/var"
PHP_FPM_BIN="$HOME/.phpenv/versions/$PHP_VERSION/sbin/php-fpm"
PHP_FPM_CONF="$DIR/nginx/php-fpm.conf"
# Build the php-fpm.conf.
tpl "$DIR/php-fpm.tpl.conf" "$PHP_FPM_CONF"
# Start php-fpm
"$PHP_FPM_BIN" --fpm-config "$PHP_FPM_CONF"
# Build the default nginx config files.
tpl "$DIR/nginx.tpl.conf" "$DIR/nginx/nginx.conf"
tpl "$DIR/fastcgi.tpl.conf" "$DIR/nginx/fastcgi.conf"
tpl "$DIR/longurl.tpl.conf" "$DIR/nginx/sites-enabled/longurl.conf"
tpl "$DIR/shorturl.tpl.conf" "$DIR/nginx/sites-enabled/shorturl.conf"
# Start nginx.
nginx -c "$DIR/nginx/nginx.conf"

View file

@ -1,21 +0,0 @@
server {
listen {HTTP_PORT} default_server;
listen [::]:{HTTP_PORT} default_server ipv6only=on;
server_name jonnybarnes.localhost;
root {ROOT}/public;
index index.php;
access_log /tmp/access.log;
error_log /tmp/error.log;
location / {
# First attempt to serve request as file, then as directory, then fall back to index.php.
try_files $uri $uri/ /index.php$is_args$args;
}
location ~* "\.php(/|$)" {
include fastcgi.conf;
fastcgi_pass php;
}
}

View file

@ -1,53 +0,0 @@
worker_processes 1;
error_log /tmp/error.log;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
}
http {
# Set an array of temp and cache file options that will otherwise default to restricted locations accessible only to root.
client_body_temp_path /tmp/client_body;
fastcgi_temp_path /tmp/fastcgi_temp;
proxy_temp_path /tmp/proxy_temp;
scgi_temp_path /tmp/scgi_temp;
uwsgi_temp_path /tmp/uwsgi_temp;
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /tmp/access.log;
error_log /tmp/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
##
# Virtual Host Configs
##
# include {DIR}/nginx/conf.d/*.conf;
include {DIR}/nginx/sites-enabled/*;
upstream php {
server 127.0.0.1:{PHP_PORT};
}
}

View file

@ -1,10 +0,0 @@
[global]
error_log = /tmp/php-fpm.error.log
[travis]
user = {USER}
listen = {PHP_PORT}
listen.mode = 0666
pm = static
pm.max_children = 5
php_admin_value[memory_limit] = 32M

View file

@ -1,21 +0,0 @@
server {
listen {HTTP_PORT};
listen [::]:{HTTP_PORT};
server_name jmb.localhost;
root {ROOT}/public;
index index.php;
access_log /tmp/access.log;
error_log /tmp/error.log;
location / {
# First attempt to serve request as file, then as directory, then fall back to index.php.
try_files $uri $uri/ /index.php$is_args$args;
}
location ~* "\.php(/|$)" {
include fastcgi.conf;
fastcgi_pass php;
}
}