commit
da2c49a72c
58 changed files with 1329 additions and 1253 deletions
|
@ -41,11 +41,13 @@ class SaveProfileImage implements ShouldQueue
|
|||
{
|
||||
try {
|
||||
$author = $authorship->findAuthor($this->microformats);
|
||||
} catch (AuthorshipParserException $e) {
|
||||
return;
|
||||
} catch (AuthorshipParserException) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$photo = Arr::get($author, 'properties.photo.0');
|
||||
$home = Arr::get($author, 'properties.url.0');
|
||||
|
||||
//dont save pbs.twimg.com links
|
||||
if (
|
||||
$photo
|
||||
|
@ -53,16 +55,18 @@ class SaveProfileImage implements ShouldQueue
|
|||
&& parse_url($photo, PHP_URL_HOST) != 'twitter.com'
|
||||
) {
|
||||
$client = resolve(Client::class);
|
||||
|
||||
try {
|
||||
$response = $client->get($photo);
|
||||
$image = $response->getBody();
|
||||
} catch (RequestException $e) {
|
||||
} catch (RequestException) {
|
||||
// we are opening and reading the default image so that
|
||||
$default = public_path() . '/assets/profile-images/default-image';
|
||||
$handle = fopen($default, 'rb');
|
||||
$image = fread($handle, filesize($default));
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
$path = public_path() . '/assets/profile-images/' . parse_url($home, PHP_URL_HOST) . '/image';
|
||||
$parts = explode('/', $path);
|
||||
$name = array_pop($parts);
|
||||
|
|
659
composer.lock
generated
659
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,13 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer"
|
||||
processIsolation="false"
|
||||
stopOnFailure="true"
|
||||
>
|
||||
<testsuites>
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Note;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class ActivityStreamTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test request to homepage returns data for site owner.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_homepage_returns_data_for_site_owner()
|
||||
/** @test */
|
||||
public function homepageRequestReturnsDataForSiteOwner(): void
|
||||
{
|
||||
$response = $this->get('/', ['Accept' => 'application/activity+json']);
|
||||
$response->assertHeader('Content-Type', 'application/activity+json');
|
||||
|
@ -24,14 +22,10 @@ class ActivityStreamTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test request to a single note returns AS2.0 data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_single_note_returns_as_data()
|
||||
/** @test */
|
||||
public function requestForNoteIncludesActivityStreamData(): void
|
||||
{
|
||||
$note = \App\Models\Note::find(11);
|
||||
$note = Note::find(11);
|
||||
$response = $this->get('/notes/B', ['Accept' => 'application/activity+json']);
|
||||
$response->assertHeader('Content-Type', 'application/activity+json');
|
||||
$response->assertJson([
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminHomeControllerTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_admin_homepage()
|
||||
/** @test */
|
||||
public function adminHomepageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
|
|
@ -1,24 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminTest extends TestCase
|
||||
{
|
||||
public function test_admin_page_redirects_to_login()
|
||||
/** @test */
|
||||
public function adminPageRedirectsUnauthedUsersToLoginPage(): void
|
||||
{
|
||||
$response = $this->get('/admin');
|
||||
$response->assertRedirect('/login');
|
||||
}
|
||||
|
||||
public function test_login_page()
|
||||
/** @test */
|
||||
public function loginPageLoads(): void
|
||||
{
|
||||
$response = $this->get('/login');
|
||||
$response->assertViewIs('login');
|
||||
}
|
||||
|
||||
public function test_attempt_login_with_bad_credentials()
|
||||
/** @test */
|
||||
public function loginAttemptWithBadCredentialsFails(): void
|
||||
{
|
||||
$response = $this->post('/login', [
|
||||
'username' => 'bad',
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ArticlesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_index_page()
|
||||
/** @test */
|
||||
public function adminArticlesPageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -20,7 +24,8 @@ class ArticlesTest extends TestCase
|
|||
$response->assertSeeText('Select article to edit:');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
/** @test */
|
||||
public function adminCanLoadFormToCreateArticle(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -29,7 +34,8 @@ class ArticlesTest extends TestCase
|
|||
$response->assertSeeText('Title (URL)');
|
||||
}
|
||||
|
||||
public function test_create_new_article()
|
||||
/** @test */
|
||||
public function admiNCanCreateNewArticle(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -41,10 +47,11 @@ class ArticlesTest extends TestCase
|
|||
$this->assertDatabaseHas('articles', ['title' => 'Test Title']);
|
||||
}
|
||||
|
||||
public function test_create_new_article_with_upload()
|
||||
/** @test */
|
||||
public function adminCanCreateNewArticleWithFile(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$text = $faker->text;
|
||||
if ($fh = fopen(sys_get_temp_dir() . '/article.md', 'w')) {
|
||||
fwrite($fh, $text);
|
||||
|
@ -65,7 +72,8 @@ class ArticlesTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_see_edit_form()
|
||||
/** @test */
|
||||
public function articleCanLoadFormToEditArticle(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -74,7 +82,8 @@ class ArticlesTest extends TestCase
|
|||
$response->assertSeeText('This is *my* new blog. It uses `Markdown`.');
|
||||
}
|
||||
|
||||
public function test_edit_article()
|
||||
/** @test */
|
||||
public function adminCanEditArticle(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -90,7 +99,8 @@ class ArticlesTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_delete_article()
|
||||
/** @test */
|
||||
public function adminCanDeleteArticle(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClientsTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_index_page()
|
||||
/** @test */
|
||||
public function clientsPageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -19,7 +22,8 @@ class ClientsTest extends TestCase
|
|||
$response->assertSeeText('Clients');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
/** @test */
|
||||
public function adminCanLoadFormToCreateClient(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -28,7 +32,8 @@ class ClientsTest extends TestCase
|
|||
$response->assertSeeText('New Client');
|
||||
}
|
||||
|
||||
public function test_create_new_client()
|
||||
/** @test */
|
||||
public function adminCanCreateNewClient(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -43,7 +48,8 @@ class ClientsTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_see_edit_form()
|
||||
/** @test */
|
||||
public function adminCanLoadEditFormForClient(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -52,7 +58,8 @@ class ClientsTest extends TestCase
|
|||
$response->assertSee('https://jbl5.dev/notes/new');
|
||||
}
|
||||
|
||||
public function test_edit_client()
|
||||
/** @test */
|
||||
public function adminCanEditClient(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -68,7 +75,8 @@ class ClientsTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_delete_client()
|
||||
/** @test */
|
||||
public function adminCanDeleteClient(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use GuzzleHttp\Client;
|
||||
use App\Models\Contact;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ContactsTest extends TestCase
|
||||
{
|
||||
|
@ -25,7 +27,8 @@ class ContactsTest extends TestCase
|
|||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_index_page()
|
||||
/** @test */
|
||||
public function contactIndexPageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -33,7 +36,8 @@ class ContactsTest extends TestCase
|
|||
$response->assertViewIs('admin.contacts.index');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
/** @test */
|
||||
public function contactCreatePageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -41,7 +45,8 @@ class ContactsTest extends TestCase
|
|||
$response->assertViewIs('admin.contacts.create');
|
||||
}
|
||||
|
||||
public function test_create_new_contact()
|
||||
/** @test */
|
||||
public function adminCanCreateNewContact(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -57,7 +62,8 @@ class ContactsTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_see_edit_form()
|
||||
/** @test */
|
||||
public function adminCanSeeFormToEditContact(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -65,7 +71,8 @@ class ContactsTest extends TestCase
|
|||
$response->assertViewIs('admin.contacts.edit');
|
||||
}
|
||||
|
||||
public function test_update_contact_no_uploaded_avatar()
|
||||
/** @test */
|
||||
public function adminCanUpdateContact(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -82,7 +89,8 @@ class ContactsTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_edit_contact_with_uploaded_avatar()
|
||||
/** @test */
|
||||
public function adminCanEditContactAndUploadAvatar(): void
|
||||
{
|
||||
copy(__DIR__ . '/../../aaron.png', sys_get_temp_dir() . '/tantek.png');
|
||||
$path = sys_get_temp_dir() . '/tantek.png';
|
||||
|
@ -103,7 +111,8 @@ class ContactsTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function test_delete_contact()
|
||||
/** @test */
|
||||
public function adminCanDeleteContact(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -115,13 +124,14 @@ class ContactsTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_get_avatar_method()
|
||||
/** @test */
|
||||
public function adminCanTriggerRetrievalOfRemoteAvatar(): void
|
||||
{
|
||||
$html = <<<HTML
|
||||
<div class="h-card">
|
||||
<img class="u-photo" src="http://tantek.com/tantek.png">
|
||||
</div>
|
||||
HTML;
|
||||
<div class="h-card">
|
||||
<img class="u-photo" alt="" src="http://tantek.com/tantek.png">
|
||||
</div>
|
||||
HTML;
|
||||
$file = fopen(__DIR__ . '/../../aaron.png', 'r');
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['Content-Type' => 'text/html'], $html),
|
||||
|
@ -140,7 +150,8 @@ HTML;
|
|||
);
|
||||
}
|
||||
|
||||
public function test_get_avatar_method_redirects_with_failed_homepage()
|
||||
/** @test */
|
||||
public function gettingRemoteAvatarFailsGracefullyWithRemoteNotFound(): void
|
||||
{
|
||||
$mock = new MockHandler([
|
||||
new Response(404),
|
||||
|
@ -155,13 +166,14 @@ HTML;
|
|||
$response->assertRedirect('/admin/contacts/1/edit');
|
||||
}
|
||||
|
||||
public function test_get_avatar_method_redirects_with_failed_avatar_download()
|
||||
/** @test */
|
||||
public function gettingRemoteAvatarFailsGracefullyWithRemoteError(): void
|
||||
{
|
||||
$html = <<<HTML
|
||||
<div class="h-card">
|
||||
<div class="h-card">
|
||||
<img class="u-photo" src="http://tantek.com/tantek.png">
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['Content-Type' => 'text/html'], $html),
|
||||
new Response(404),
|
||||
|
@ -176,7 +188,8 @@ HTML;
|
|||
$response->assertRedirect('/admin/contacts/1/edit');
|
||||
}
|
||||
|
||||
public function test_get_avatar_for_contact_with_no_homepage()
|
||||
/** @test */
|
||||
public function gettingRemoteAvatarFailsGracefullyForContactWithNoHompage(): void
|
||||
{
|
||||
$contact = Contact::create([
|
||||
'nick' => 'fred',
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
use App\Models\Like;
|
||||
use App\Jobs\ProcessLike;
|
||||
use App\Models\Like;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LikesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_index_page()
|
||||
/** @test */
|
||||
public function likesPageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -22,7 +25,8 @@ class LikesTest extends TestCase
|
|||
$response->assertSeeText('Likes');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
/** @test */
|
||||
public function likeCreateFormLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -31,7 +35,8 @@ class LikesTest extends TestCase
|
|||
$response->assertSeeText('New Like');
|
||||
}
|
||||
|
||||
public function test_create_new_like()
|
||||
/** @test */
|
||||
public function adminCanCreateLike(): void
|
||||
{
|
||||
Queue::fake();
|
||||
$user = User::factory()->make();
|
||||
|
@ -46,7 +51,8 @@ class LikesTest extends TestCase
|
|||
Queue::assertPushed(ProcessLike::class);
|
||||
}
|
||||
|
||||
public function test_see_edit_form()
|
||||
/** @test */
|
||||
public function likeEditFormLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -55,7 +61,8 @@ class LikesTest extends TestCase
|
|||
$response->assertSee('Edit Like');
|
||||
}
|
||||
|
||||
public function test_edit_like()
|
||||
/** @test */
|
||||
public function adminCanEditLike(): void
|
||||
{
|
||||
Queue::fake();
|
||||
$user = User::factory()->make();
|
||||
|
@ -71,7 +78,8 @@ class LikesTest extends TestCase
|
|||
Queue::assertPushed(ProcessLike::class);
|
||||
}
|
||||
|
||||
public function test_delete_like()
|
||||
/** @test */
|
||||
public function adminCanDeleteLike(): void
|
||||
{
|
||||
$like = Like::find(1);
|
||||
$url = $like->url;
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\SendWebMentions;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NotesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_index_page()
|
||||
/** @test */
|
||||
public function notesPageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -20,7 +23,8 @@ class NotesTest extends TestCase
|
|||
$response->assertViewIs('admin.notes.index');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
/** @test */
|
||||
public function noteCreatePageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -28,7 +32,8 @@ class NotesTest extends TestCase
|
|||
$response->assertViewIs('admin.notes.create');
|
||||
}
|
||||
|
||||
public function test_create_a_new_note()
|
||||
/** @test */
|
||||
public function adminCanCreateNewNote(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -40,7 +45,8 @@ class NotesTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_edit_page()
|
||||
/** @test */
|
||||
public function noteEditFormLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -48,7 +54,8 @@ class NotesTest extends TestCase
|
|||
$response->assertViewIs('admin.notes.edit');
|
||||
}
|
||||
|
||||
public function test_edit_a_note()
|
||||
/** @test */
|
||||
public function adminCanEditNote(): void
|
||||
{
|
||||
Queue::fake();
|
||||
$user = User::factory()->make();
|
||||
|
@ -65,7 +72,8 @@ class NotesTest extends TestCase
|
|||
Queue::assertPushed(SendWebMentions::class);
|
||||
}
|
||||
|
||||
public function test_delete_note()
|
||||
/** @test */
|
||||
public function adminCanDeleteNote(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PlacesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_index_page()
|
||||
/** @test */
|
||||
public function placesPageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -18,7 +21,8 @@ class PlacesTest extends TestCase
|
|||
$response->assertViewIs('admin.places.index');
|
||||
}
|
||||
|
||||
public function test_create_page()
|
||||
/** @test */
|
||||
public function createPlacePageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -26,7 +30,8 @@ class PlacesTest extends TestCase
|
|||
$response->assertViewIs('admin.places.create');
|
||||
}
|
||||
|
||||
public function test_create_new_place()
|
||||
/** @test */
|
||||
public function adminCanCreateNewPlace(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -42,7 +47,8 @@ class PlacesTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_edit_page()
|
||||
/** @test */
|
||||
public function editPlacePageLoads(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
@ -50,7 +56,8 @@ class PlacesTest extends TestCase
|
|||
$response->assertViewIs('admin.places.edit');
|
||||
}
|
||||
|
||||
public function test_updating_a_place()
|
||||
/** @test */
|
||||
public function adminCanUpdatePlace(): void
|
||||
{
|
||||
$user = User::factory()->make();
|
||||
|
||||
|
|
|
@ -1,45 +1,50 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class ArticlesTest extends TestCase
|
||||
{
|
||||
public function test_articles_page()
|
||||
/** @test */
|
||||
public function articlesPageLoads(): void
|
||||
{
|
||||
$response = $this->get('/blog');
|
||||
$response->assertViewIs('articles.index');
|
||||
}
|
||||
|
||||
public function test_single_article()
|
||||
/** @test */
|
||||
public function singleArticlePageLoads()
|
||||
{
|
||||
$response = $this->get('/blog/' . date('Y') . '/' . date('m') . '/some-code-i-did');
|
||||
$response->assertViewIs('articles.show');
|
||||
}
|
||||
|
||||
public function test_wrong_date_redirects()
|
||||
/** @test */
|
||||
public function wrongDateInUrlRedirectsToCorrectDate()
|
||||
{
|
||||
$response = $this->get('/blog/1900/01/some-code-i-did');
|
||||
$response->assertRedirect('/blog/' . date('Y') . '/' . date('m') . '/some-code-i-did');
|
||||
}
|
||||
|
||||
public function test_redirect_for_id()
|
||||
/** @test */
|
||||
public function oldUrlsWithIdAreRedirected()
|
||||
{
|
||||
$response = $this->get('/blog/s/2');
|
||||
$response->assertRedirect('/blog/' . date('Y') . '/' . date('m') . '/some-code-i-did');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function unknownSlugGives404()
|
||||
public function unknownSlugGetsNotFoundResponse()
|
||||
{
|
||||
$response = $this->get('/blog/' . date('Y') . '/' . date('m') . '/unknown-slug');
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function unknownArticleIdGives404()
|
||||
public function unknownArticleIdGetsNotFoundResponse()
|
||||
{
|
||||
$response = $this->get('/blog/s/22');
|
||||
$response->assertNotFound();
|
||||
|
|
|
@ -1,31 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Tests\TestToken;
|
||||
use App\Jobs\ProcessBookmark;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use App\Jobs\SyndicateBookmarkToTwitter;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
use Tests\TestToken;
|
||||
|
||||
class BookmarksTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions, TestToken;
|
||||
|
||||
public function test_bookmarks_page()
|
||||
/** @test */
|
||||
public function bookmarksPageLoadsWithoutError(): void
|
||||
{
|
||||
$response = $this->get('/bookmarks');
|
||||
$response->assertViewIs('bookmarks.index');
|
||||
}
|
||||
|
||||
public function test_single_bookmark_page()
|
||||
/** @test */
|
||||
public function singleBookmarkPageLoadsWithoutError(): void
|
||||
{
|
||||
$response = $this->get('/bookmarks/1');
|
||||
$response->assertViewIs('bookmarks.show');
|
||||
}
|
||||
|
||||
public function test_browsershot_job_dispatches_when_bookmark_added_http_post_syntax()
|
||||
/** @test */
|
||||
public function whenBookmarkIsAddedUsingHttpSyntaxCheckJobToTakeScreenshotIsInvoked(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
|
@ -46,7 +51,8 @@ class BookmarksTest extends TestCase
|
|||
$this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']);
|
||||
}
|
||||
|
||||
public function test_browsershot_job_dispatches_when_bookmark_added_json_syntax()
|
||||
/** @test */
|
||||
public function whenBookmarkIsAddedUsingJsonSyntaxCheckJobToTakeScreenshotIsInvoked(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
|
@ -69,7 +75,8 @@ class BookmarksTest extends TestCase
|
|||
$this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']);
|
||||
}
|
||||
|
||||
public function test_single_twitter_syndication_target_causes_job_dispatch_http_post_syntax()
|
||||
/** @test */
|
||||
public function whenTheBookmarkIsMarkedForPostingToTwitterCheckWeInvokeTheCorrectJob(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
|
@ -88,7 +95,8 @@ class BookmarksTest extends TestCase
|
|||
$this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']);
|
||||
}
|
||||
|
||||
public function test_tags_created_with_new_bookmark()
|
||||
/** @test */
|
||||
public function whenTheBookmarkIsCreatedCheckNecessaryTagsAreAlsoCreated(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class BridgyPosseTest extends TestCase
|
||||
{
|
||||
public function test_bridgy_twitter_content()
|
||||
/** @test */
|
||||
public function notesWeWantCopiedToTwitterShouldHaveNecessaryMarkup(): void
|
||||
{
|
||||
$response = $this->get('/notes/4');
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
@ -7,9 +9,9 @@ use Tests\TestCase;
|
|||
class CSPHeadersTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function check_csp_headers_test()
|
||||
public function checkCspHeadersArePresent(): void
|
||||
{
|
||||
$response = $this->get('/');
|
||||
$response = $this->get('/blog');
|
||||
$response->assertHeader('Content-Security-Policy');
|
||||
$response->assertHeader('Report-To');
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
@ -9,9 +11,9 @@ class ContactsTest extends TestCase
|
|||
/**
|
||||
* Check the `/contacts` page gives a good response.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_contacts_page()
|
||||
public function contactsPageLoadsWithoutError(): void
|
||||
{
|
||||
$response = $this->get('/contacts');
|
||||
$response->assertStatus(200);
|
||||
|
@ -20,9 +22,9 @@ class ContactsTest extends TestCase
|
|||
/**
|
||||
* Test an individual contact page with default profile image.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_contact_page_with_default_pic()
|
||||
public function contactPageShouldFallbackToDefaultProfilePic(): void
|
||||
{
|
||||
$response = $this->get('/contacts/tantek');
|
||||
$response->assertViewHas('image', '/assets/profile-images/default-image');
|
||||
|
@ -31,16 +33,16 @@ class ContactsTest extends TestCase
|
|||
/**
|
||||
* Test an individual contact page with a specific profile image.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_contact_page_with_specific_pic()
|
||||
public function contactPageShouldUseSpecificProfilePicIfPresent(): void
|
||||
{
|
||||
$response = $this->get('/contacts/aaron');
|
||||
$response->assertViewHas('image', '/assets/profile-images/aaronparecki.com/image');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function unknownContactGives404()
|
||||
public function unknownContactReturnsNotFoundResponse(): void
|
||||
{
|
||||
$response = $this->get('/contacts/unknown');
|
||||
$response->assertNotFound();
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Tests\TestToken;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class CorsHeadersTest extends TestCase
|
||||
{
|
||||
use TestToken;
|
||||
|
||||
/** @test */
|
||||
public function check_cors_headers_on_media_endpoint_options_request()
|
||||
public function checkCorsHeadersOnMediaEndpoint(): void
|
||||
{
|
||||
$response = $this->call(
|
||||
'OPTIONS',
|
||||
|
@ -26,9 +26,9 @@ class CorsHeadersTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function check_missing_on_other_route()
|
||||
public function checkForNoCorsHeaderOnNonMediaEndpointLinks(): void
|
||||
{
|
||||
$response = $this->get('/');
|
||||
$response = $this->get('/blog');
|
||||
$response->assertHeaderMissing('Access-Control-Allow-Origin');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
@ -9,38 +11,41 @@ class FeedsTest extends TestCase
|
|||
/**
|
||||
* Test the blog RSS feed.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_blog_rss_feed()
|
||||
public function blogRssFeedIsPresent(): void
|
||||
{
|
||||
$response = $this->get('/blog/feed.rss');
|
||||
$response->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8');
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the notes RSS feed.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_notes_rss_feed()
|
||||
public function notesRssFeedIsPresent(): void
|
||||
{
|
||||
$response = $this->get('/notes/feed.rss');
|
||||
$response->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8');
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the blog RSS feed.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_blog_atom_feed()
|
||||
public function blogAtomFeedIsPresent(): void
|
||||
{
|
||||
$response = $this->get('/blog/feed.atom');
|
||||
$response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8');
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function blog_jf2_feed()
|
||||
public function blogJf2FeedIsPresent(): void
|
||||
{
|
||||
$response = $this->get('/blog/feed.jf2');
|
||||
$response->assertHeader('Content-Type', 'application/jf2feed+json');
|
||||
|
@ -63,38 +68,41 @@ class FeedsTest extends TestCase
|
|||
/**
|
||||
* Test the notes RSS feed.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_notes_atom_feed()
|
||||
public function notesAtomFeedIsPresent(): void
|
||||
{
|
||||
$response = $this->get('/notes/feed.atom');
|
||||
$response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8');
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the blog JSON feed.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_blog_json_feed()
|
||||
public function blogJsonFeedIsPresent(): void
|
||||
{
|
||||
$response = $this->get('/blog/feed.json');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the notes JSON feed.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_notes_json_feed()
|
||||
public function notesJsonFeedIsPresent(): void
|
||||
{
|
||||
$response = $this->get('/notes/feed.json');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function notes_jf2_feed()
|
||||
public function notesJf2FeedIsPresent(): void
|
||||
{
|
||||
$response = $this->get('/notes/feed.jf2');
|
||||
$response->assertHeader('Content-Type', 'application/jf2feed+json');
|
||||
|
@ -118,9 +126,9 @@ class FeedsTest extends TestCase
|
|||
* Each JSON feed item must have one of `content_text` or `content_html`,
|
||||
* and whichever one they have can’t be `null`.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_json_feed_has_one_content_attribute_and_it_isnt_null()
|
||||
public function jsonFeedsHaveRequiredAttributes(): void
|
||||
{
|
||||
$response = $this->get('/notes/feed.json');
|
||||
$data = json_decode($response->content());
|
||||
|
|
|
@ -1,40 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Codebird\Codebird;
|
||||
use Queue;
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
use App\Models\Like;
|
||||
use Tests\TestToken;
|
||||
use GuzzleHttp\Client;
|
||||
use App\Jobs\ProcessLike;
|
||||
use Lcobucci\JWT\Builder;
|
||||
use App\Models\Like;
|
||||
use Codebird\Codebird;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
||||
use Jonnybarnes\WebmentionsParser\Authorship;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Jonnybarnes\WebmentionsParser\Authorship;
|
||||
use Tests\TestCase;
|
||||
use Tests\TestToken;
|
||||
|
||||
class LikesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions, TestToken;
|
||||
use DatabaseTransactions;
|
||||
use TestToken;
|
||||
|
||||
public function test_likes_page()
|
||||
/** @test */
|
||||
public function likesPageHasCorrectView(): void
|
||||
{
|
||||
$response = $this->get('/likes');
|
||||
$response->assertViewIs('likes.index');
|
||||
}
|
||||
|
||||
public function test_single_like_page()
|
||||
/** @test */
|
||||
public function singleLikePageHasCorrectView(): void
|
||||
{
|
||||
$response = $this->get('/likes/1');
|
||||
$response->assertViewIs('likes.show');
|
||||
}
|
||||
|
||||
public function test_like_micropub_json_request()
|
||||
/** @test */
|
||||
public function checkLikeCreatedFromMicropubApiRequests(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
|
@ -53,7 +56,8 @@ class LikesTest extends TestCase
|
|||
$this->assertDatabaseHas('likes', ['url' => 'https://example.org/blog-post']);
|
||||
}
|
||||
|
||||
public function test_like_micropub_form_request()
|
||||
/** @test */
|
||||
public function checkLikeCreatedFromMicropubWebRequests(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
|
@ -70,7 +74,8 @@ class LikesTest extends TestCase
|
|||
$this->assertDatabaseHas('likes', ['url' => 'https://example.org/blog-post']);
|
||||
}
|
||||
|
||||
public function test_process_like_job_with_simple_author()
|
||||
/** @test */
|
||||
public function likeWithSimpleAuthor(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like->url = 'http://example.org/note/id';
|
||||
|
@ -80,17 +85,18 @@ class LikesTest extends TestCase
|
|||
$job = new ProcessLike($like);
|
||||
|
||||
$content = <<<END
|
||||
<html>
|
||||
<body>
|
||||
<html>
|
||||
<body>
|
||||
<div class="h-entry">
|
||||
<div class="e-content">
|
||||
A post that I like.
|
||||
</div>
|
||||
by <span class="p-author">Fred Bloggs</span>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
END;
|
||||
</body>
|
||||
</html>
|
||||
END;
|
||||
|
||||
$mock = new MockHandler([
|
||||
new Response(200, [], $content),
|
||||
new Response(200, [], $content),
|
||||
|
@ -107,7 +113,8 @@ END;
|
|||
$this->assertEquals('Fred Bloggs', Like::find($id)->author_name);
|
||||
}
|
||||
|
||||
public function test_process_like_job_with_h_card()
|
||||
/** @test */
|
||||
public function likeWithHCard(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like->url = 'http://example.org/note/id';
|
||||
|
@ -117,8 +124,8 @@ END;
|
|||
$job = new ProcessLike($like);
|
||||
|
||||
$content = <<<END
|
||||
<html>
|
||||
<body>
|
||||
<html>
|
||||
<body>
|
||||
<div class="h-entry">
|
||||
<div class="e-content">
|
||||
A post that I like.
|
||||
|
@ -129,9 +136,10 @@ END;
|
|||
<a class="u-url" href="https://fredd.blog/gs"></a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
END;
|
||||
</body>
|
||||
</html>
|
||||
END;
|
||||
|
||||
$mock = new MockHandler([
|
||||
new Response(200, [], $content),
|
||||
new Response(200, [], $content),
|
||||
|
@ -148,7 +156,8 @@ END;
|
|||
$this->assertEquals('Fred Bloggs', Like::find($id)->author_name);
|
||||
}
|
||||
|
||||
public function test_process_like_job_without_mf2()
|
||||
/** @test */
|
||||
public function likeWithoutMicroformats(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like->url = 'http://example.org/note/id';
|
||||
|
@ -158,14 +167,15 @@ END;
|
|||
$job = new ProcessLike($like);
|
||||
|
||||
$content = <<<END
|
||||
<html>
|
||||
<body>
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
I liked a post
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
END;
|
||||
</body>
|
||||
</html>
|
||||
END;
|
||||
|
||||
$mock = new MockHandler([
|
||||
new Response(200, [], $content),
|
||||
new Response(200, [], $content),
|
||||
|
@ -182,7 +192,8 @@ END;
|
|||
$this->assertNull(Like::find($id)->author_name);
|
||||
}
|
||||
|
||||
public function test_process_like_that_is_tweet()
|
||||
/** @test */
|
||||
public function likeThatIsATweet(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200';
|
||||
|
@ -202,10 +213,11 @@ END;
|
|||
return $client;
|
||||
});
|
||||
|
||||
$info = new stdClass();
|
||||
$info->author_name = 'Jonny Barnes';
|
||||
$info->author_url = 'https://twitter.com/jonnybarnes';
|
||||
$info->html = '<div>HTML of the tweet embed</div>';
|
||||
$info = (object) [
|
||||
'author_name' => 'Jonny Barnes',
|
||||
'author_url' => 'https://twitter.com/jonnybarnes',
|
||||
'html' => '<div>HTML of the tweet embed</div>',
|
||||
];
|
||||
$codebirdMock = $this->getMockBuilder(Codebird::class)
|
||||
->addMethods(['statuses_oembed'])
|
||||
->getMock();
|
||||
|
@ -221,7 +233,7 @@ END;
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function unknownLikeGives404()
|
||||
public function unknownLikeGivesNotFoundResponse(): void
|
||||
{
|
||||
$response = $this->get('/likes/202');
|
||||
$response->assertNotFound();
|
||||
|
|
|
@ -1,41 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Faker\Factory;
|
||||
use App\Jobs\{SendWebMentions, SyndicateNoteToTwitter};
|
||||
use App\Models\{Media, Place};
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
use Tests\TestToken;
|
||||
use App\Jobs\SendWebMentions;
|
||||
use App\Models\{Media, Place};
|
||||
use App\Jobs\SyndicateNoteToTwitter;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class MicropubControllerTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
use TestToken;
|
||||
|
||||
/**
|
||||
* Test a GET request for the micropub endpoint without a token gives a
|
||||
* 400 response. Also check the error message.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_micropub_get_request_without_token_returns_401_response()
|
||||
/** @test */
|
||||
public function micropubGetRequestWithoutTokenReturnsErrorResponse(): void
|
||||
{
|
||||
$response = $this->get('/api/post');
|
||||
$response->assertStatus(401);
|
||||
$response->assertJsonFragment(['error_description' => 'No access token was provided in the request']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a GET request for the micropub endpoint without a valid token gives
|
||||
* a 400 response. Also check the error message.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_micropub_get_request_without_valid_token_returns_400_response()
|
||||
/** @test */
|
||||
public function micropubGetRequestWithoutValidTokenReturnsErrorResponse(): void
|
||||
{
|
||||
$response = $this->get('/api/post', ['HTTP_Authorization' => 'Bearer abc123']);
|
||||
$response->assertStatus(400);
|
||||
|
@ -44,80 +36,59 @@ class MicropubControllerTest extends TestCase
|
|||
|
||||
/**
|
||||
* Test a GET request for the micropub endpoint with a valid token gives a
|
||||
* 200 response. Check token information is returned in the response.
|
||||
* 200 response. Check token information is also returned in the response.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_micropub_get_request_with_valid_token_returns_200_response()
|
||||
public function micropubGetRequestWithValidTokenReturnsOkResponse(): void
|
||||
{
|
||||
$response = $this->get('/api/post', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonFragment(['response' => 'token']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a GET request for syndication targets.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_micropub_get_request_for_syndication_targets()
|
||||
/** @test */
|
||||
public function micropubClientsCanRequestSyndicationTargets(): void
|
||||
{
|
||||
$response = $this->get('/api/post?q=syndicate-to', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
|
||||
$response->assertJsonFragment(['uid' => 'https://twitter.com/jonnybarnes']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a request for places.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_micropub_get_request_for_nearby_places()
|
||||
{
|
||||
$response = $this->get('/api/post?q=geo:53.5,-2.38', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
|
||||
$response->assertJson(['places' => [['slug' =>'the-bridgewater-pub']]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a request for places, this time with an uncertainty parameter.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_micropub_get_request_for_nearby_places_with_uncertainty_parameter()
|
||||
/** @test */
|
||||
public function micropubClientsCanRequestKnownNearbyPlaces(): void
|
||||
{
|
||||
$response = $this->get('/api/post?q=geo:53.5,-2.38', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
|
||||
$response->assertJson(['places' => [['slug' => 'the-bridgewater-pub']]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a request for places, where there will be an “empty” response.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
* @todo Add uncertainty parameter
|
||||
*/
|
||||
public function test_micropub_get_request_for_nearby_places_where_non_exist()
|
||||
public function micropubClientsCanRequestKnownNearbyPlacesWithUncertaintyParameter(): void
|
||||
{
|
||||
$response = $this->get('/api/post?q=geo:53.5,-2.38', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
|
||||
$response->assertJson(['places' => [['slug' => 'the-bridgewater-pub']]]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function returnEmptyResultWhenMicropubClientRequestsKnownNearbyPlaces(): void
|
||||
{
|
||||
$response = $this->get('/api/post?q=geo:1.23,4.56', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
|
||||
$response->assertJson(['places' => []]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a request for the micropub config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_micropub_get_request_for_config()
|
||||
/** @test */
|
||||
public function micropubClientCanRequestEndpointConfig(): void
|
||||
{
|
||||
$response = $this->get('/api/post?q=config', ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
|
||||
$response->assertJsonFragment(['uid' => 'https://twitter.com/jonnybarnes']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a valid micropub requests creates a new note.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_micropub_post_request_creates_new_note()
|
||||
/** @test */
|
||||
public function micropubClientCanCreateNewNote(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
$response = $this->post(
|
||||
'/api/post',
|
||||
|
@ -133,15 +104,11 @@ class MicropubControllerTest extends TestCase
|
|||
$this->assertDatabaseHas('notes', ['note' => $note]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a valid micropub requests creates a new note and syndicates to Twitter.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_micropub_post_request_creates_new_note_sends_to_twitter()
|
||||
/** @test */
|
||||
public function micropubClientCanRequestTheNewNoteIsSyndicatedToTwitter(): void
|
||||
{
|
||||
Queue::fake();
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
$response = $this->post(
|
||||
'/api/post',
|
||||
|
@ -157,12 +124,8 @@ class MicropubControllerTest extends TestCase
|
|||
Queue::assertPushed(SyndicateNoteToTwitter::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a valid micropub requests creates a new place.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_micropub_post_request_creates_new_place()
|
||||
/** @test */
|
||||
public function micropubClientsCanCreateNewPlaces(): void
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/post',
|
||||
|
@ -177,13 +140,8 @@ class MicropubControllerTest extends TestCase
|
|||
$this->assertDatabaseHas('places', ['slug' => 'the-barton-arms']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a valid micropub requests creates a new place with latitude
|
||||
* and longitude values defined separately.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_micropub_post_request_creates_new_place_with_latlng()
|
||||
/** @test */
|
||||
public function micropubClientsCanCreateNewPlacesWithOldLocationSyntax(): void
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/post',
|
||||
|
@ -199,7 +157,8 @@ class MicropubControllerTest extends TestCase
|
|||
$this->assertDatabaseHas('places', ['slug' => 'the-barton-arms']);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_invalid_token_returns_expected_error_response()
|
||||
/** @test */
|
||||
public function micropubClientWebRequestWithInvalidTokenReturnsErrorResponse(): void
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/post',
|
||||
|
@ -213,7 +172,8 @@ class MicropubControllerTest extends TestCase
|
|||
$response->assertJson(['error' => 'invalid_token']);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_scopeless_token_returns_expected_error_response()
|
||||
/** @test */
|
||||
public function micropubClientWebRequestWithTokenWithoutAnyScopesReturnsErrorResponse(): void
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/post',
|
||||
|
@ -227,7 +187,8 @@ class MicropubControllerTest extends TestCase
|
|||
$response->assertJson(['error_description' => 'The provided token has no scopes']);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_for_place_without_create_scope_errors()
|
||||
/** @test */
|
||||
public function micropubClientWebRequestWithTokenWithoutCreateScopesReturnsErrorResponse(): void
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/post',
|
||||
|
@ -245,16 +206,16 @@ class MicropubControllerTest extends TestCase
|
|||
/**
|
||||
* Test a valid micropub requests using JSON syntax creates a new note.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_micropub_post_request_with_json_syntax_creates_new_note()
|
||||
public function micropubClientApiRequestCreatesNewNote(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Media::create([
|
||||
'path' => 'test-photo.jpg',
|
||||
'type' => 'image',
|
||||
]);
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -282,16 +243,16 @@ class MicropubControllerTest extends TestCase
|
|||
* Test a valid micropub requests using JSON syntax creates a new note with
|
||||
* existing self-created place.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_micropub_post_request_with_json_syntax_creates_new_note_with_existing_place_in_location()
|
||||
public function micropubClientApiRequestCreatesNewNoteWithExistingPlaceInLocationData(): void
|
||||
{
|
||||
$place = new Place();
|
||||
$place->name = 'Test Place';
|
||||
$place->latitude = 1.23;
|
||||
$place->longitude = 4.56;
|
||||
$place->save();
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -313,11 +274,11 @@ class MicropubControllerTest extends TestCase
|
|||
* Test a valid micropub requests using JSON syntax creates a new note with
|
||||
* a new place defined in the location block.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_micropub_post_request_with_json_syntax_creates_new_note_with_new_place_in_location()
|
||||
public function micropubClientApiRequestCreatesNewNoteWithNewPlaceInLocationData(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -349,11 +310,11 @@ class MicropubControllerTest extends TestCase
|
|||
* Test a valid micropub requests using JSON syntax creates a new note without
|
||||
* a new place defined in the location block if there is missing data.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_micropub_post_request_with_json_syntax_creates_new_note_without_new_place_in_location()
|
||||
public function micropubClientApiRequestCreatesNewNoteWithoutNewPlaceInLocationData(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -383,11 +344,11 @@ class MicropubControllerTest extends TestCase
|
|||
* Test a micropub requests using JSON syntax without a token returns an
|
||||
* error. Also check the message.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_micropub_post_request_with_json_syntax_without_token_returns_error()
|
||||
public function micropubClientApiRequestWithoutTokenReturnsError(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -410,11 +371,11 @@ class MicropubControllerTest extends TestCase
|
|||
* Test a micropub requests using JSON syntax without a valid token returns
|
||||
* an error. Also check the message.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_micropub_post_request_with_json_syntax_with_insufficient_token_returns_error()
|
||||
public function micropubClientApiRequestWithTokenWithInsufficientPermissionReturnsError(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -434,7 +395,8 @@ class MicropubControllerTest extends TestCase
|
|||
->assertStatus(401);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_for_unsupported_type_returns_error()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestForUnsupportedPostTypeReturnsError(): void
|
||||
{
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -454,9 +416,10 @@ class MicropubControllerTest extends TestCase
|
|||
->assertStatus(500);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_creates_new_place()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestCreatesNewPlace(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
[
|
||||
|
@ -473,9 +436,10 @@ class MicropubControllerTest extends TestCase
|
|||
->assertStatus(201);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_and_uncertainty_parameter_creates_new_place()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestCreatesNewPlaceWithUncertaintyParameter(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
[
|
||||
|
@ -492,7 +456,8 @@ class MicropubControllerTest extends TestCase
|
|||
->assertStatus(201);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_update_replace_post()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestUpdatesExistingNote(): void
|
||||
{
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -510,7 +475,8 @@ class MicropubControllerTest extends TestCase
|
|||
->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_update_add_post()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestUpdatesNoteSyndicationLinks(): void
|
||||
{
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -535,7 +501,8 @@ class MicropubControllerTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_update_add_image_to_post()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestAddsImageToNote(): void
|
||||
{
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -556,7 +523,8 @@ class MicropubControllerTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_update_add_post_errors_for_non_note()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestReturnsErrorTryingToUpdateNonNoteModel(): void
|
||||
{
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -574,7 +542,8 @@ class MicropubControllerTest extends TestCase
|
|||
->assertStatus(500);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_update_add_post_errors_for_note_not_found()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestReturnsErrorTryingToUpdateNonExistingNote(): void
|
||||
{
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -592,7 +561,8 @@ class MicropubControllerTest extends TestCase
|
|||
->assertStatus(404);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_update_add_post_errors_for_unsupported_request()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestReturnsErrorWhenTryingToUpdateUnsupportedProperty(): void
|
||||
{
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -610,7 +580,8 @@ class MicropubControllerTest extends TestCase
|
|||
->assertStatus(500);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_update_errors_for_insufficient_scope()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestWithTokenWithInsufficientScopeReturnsError(): void
|
||||
{
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -628,7 +599,8 @@ class MicropubControllerTest extends TestCase
|
|||
->assertJson(['error' => 'insufficient_scope']);
|
||||
}
|
||||
|
||||
public function test_micropub_post_request_with_json_syntax_update_replace_post_syndication()
|
||||
/** @test */
|
||||
public function micropubClientApiRequestCanReplaceNoteSyndicationTargets(): void
|
||||
{
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
|
@ -653,9 +625,10 @@ class MicropubControllerTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_access_token_form_encoded()
|
||||
/** @test */
|
||||
public function micropubClientWebReauestCanEncodeTokenWithinTheForm(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
$response = $this->post(
|
||||
'/api/post',
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\ProcessMedia;
|
||||
|
@ -17,7 +19,7 @@ class MicropubMediaTest extends TestCase
|
|||
use TestToken;
|
||||
|
||||
/** @test */
|
||||
public function emptyResponseForLastUploadWhenNoneFound()
|
||||
public function emptyResponseForLastUploadWhenNoneFound(): void
|
||||
{
|
||||
// Make sure there’s no media
|
||||
Media::all()->each(function ($media) {
|
||||
|
@ -33,7 +35,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function clientCanListLastUpload()
|
||||
public function clientCanListLastUpload(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
|
@ -61,7 +63,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function clientCanSourceUploads()
|
||||
public function clientCanSourceUploads(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
|
@ -91,7 +93,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function clientCanSourceUploadsWithLimit()
|
||||
public function clientCanSourceUploadsWithLimit(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
|
@ -123,7 +125,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function errorResponseForUnknownQValue()
|
||||
public function errorResponseForUnknownQValue(): void
|
||||
{
|
||||
$response = $this->get(
|
||||
'/api/media?q=unknown',
|
||||
|
@ -134,7 +136,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function optionsRequestReturnsCorsResponse()
|
||||
public function optionsRequestReturnsCorsResponse(): void
|
||||
{
|
||||
$response = $this->options('/api/media');
|
||||
|
||||
|
@ -143,7 +145,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointRequestWithInvalidTokenReturns400Response()
|
||||
public function mediaEndpointRequestWithInvalidTokenReturns400Response(): void
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
|
@ -155,7 +157,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointRequestWithTokenWithNoScopeReturns400Response()
|
||||
public function mediaEndpointRequestWithTokenWithNoScopeReturns400Response(): void
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
|
@ -167,7 +169,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointRequestWithInsufficientTokenScopesReturns401Response()
|
||||
public function mediaEndpointRequestWithInsufficientTokenScopesReturns401Response(): void
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
|
@ -181,7 +183,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointUploadFile()
|
||||
public function mediaEndpointUploadFile(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
|
@ -204,7 +206,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointUploadAudioFile()
|
||||
public function mediaEndpointUploadAudioFile(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
|
@ -227,7 +229,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointUploadVideoFile()
|
||||
public function mediaEndpointUploadVideoFile(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
|
@ -250,7 +252,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointUploadDocumentFile()
|
||||
public function mediaEndpointUploadDocumentFile(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
|
@ -272,7 +274,7 @@ class MicropubMediaTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointUploadInvalidFileReturnsError()
|
||||
public function mediaEndpointUploadInvalidFileReturnsError(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('local');
|
||||
|
|
|
@ -1,47 +1,49 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Note;
|
||||
|
||||
class NotesControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
/*
|
||||
* Test the `/notes` page returns 200, this should
|
||||
* mean the database is being hit.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_notes_page()
|
||||
* @test
|
||||
*
|
||||
public function notesPageLoads(): void
|
||||
{
|
||||
$response = $this->get('/notes');
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Test a specific note.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_specific_note()
|
||||
public function specificNotePageLoads(): void
|
||||
{
|
||||
$response = $this->get('/notes/D');
|
||||
$response->assertViewHas('note');
|
||||
}
|
||||
|
||||
public function test_note_replying_to_tweet()
|
||||
/* @test *
|
||||
public function noteReplyingToTweet(): void
|
||||
{
|
||||
$response = $this->get('/notes/B');
|
||||
$response->assertViewHas('note');
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Test that `/note/{decID}` redirects to `/notes/{nb60id}`.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_dec_id_redirect()
|
||||
public function oldNoteUrlsRedirect(): void
|
||||
{
|
||||
$response = $this->get('/note/11');
|
||||
$response->assertRedirect(config('app.url') . '/notes/B');
|
||||
|
@ -50,9 +52,9 @@ class NotesControllerTest extends TestCase
|
|||
/**
|
||||
* Visit the tagged page and check the tag view data.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_tagged_notes_page()
|
||||
public function taggedNotesPageLoads(): void
|
||||
{
|
||||
$response = $this->get('/notes/tagged/beer');
|
||||
$response->assertViewHas('tag', 'beer');
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\TestCase;
|
||||
use Tests\TestToken;
|
||||
use Lcobucci\JWT\Builder;
|
||||
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class OwnYourGramTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions, TestToken;
|
||||
use DatabaseTransactions;
|
||||
use TestToken;
|
||||
|
||||
public function test_ownyourgram_post()
|
||||
/** @test */
|
||||
public function postingInstagramUrlSavesMediaPath(): void
|
||||
{
|
||||
$response = $this->json(
|
||||
'POST',
|
||||
|
@ -21,10 +24,13 @@ class OwnYourGramTest extends TestCase
|
|||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'content' => ['How beautiful are the plates and chopsticks'],
|
||||
'published' => [\Carbon\Carbon::now()->toIso8601String()],
|
||||
'published' => [Carbon::now()->toIso8601String()],
|
||||
'location' => ['geo:53.802419075834,-1.5431942917637'],
|
||||
'syndication' => ['https://www.instagram.com/p/BVC_nVTBFfi/'],
|
||||
'photo' => ['https://scontent-sjc2-1.cdninstagram.com/t51.2885-15/e35/18888604_425332491185600_326487281944756224_n.jpg'],
|
||||
'photo' => [
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
'https://scontent-sjc2-1.cdninstagram.com/t51.2885-15/e35/18888604_425332491185600_326487281944756224_n.jpg'
|
||||
],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
|
@ -34,6 +40,7 @@ class OwnYourGramTest extends TestCase
|
|||
'response' => 'created'
|
||||
]);
|
||||
$this->assertDatabaseHas('media_endpoint', [
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
'path' => 'https://scontent-sjc2-1.cdninstagram.com/t51.2885-15/e35/18888604_425332491185600_326487281944756224_n.jpg'
|
||||
]);
|
||||
$this->assertDatabaseHas('notes', [
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\WebMention;
|
||||
use Illuminate\FileSystem\FileSystem;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ParseCachedWebMentionsTest extends TestCase
|
||||
{
|
||||
|
@ -18,11 +20,12 @@ class ParseCachedWebMentionsTest extends TestCase
|
|||
|
||||
mkdir(storage_path('HTML') . '/https/aaronpk.localhost/reply', 0777, true);
|
||||
mkdir(storage_path('HTML') . '/http/tantek.com', 0777, true);
|
||||
copy(__DIR__.'/../aaron.html', storage_path('HTML') . '/https/aaronpk.localhost/reply/1');
|
||||
copy(__DIR__.'/../tantek.html', storage_path('HTML') . '/http/tantek.com/index.html');
|
||||
copy(__DIR__ . '/../aaron.html', storage_path('HTML') . '/https/aaronpk.localhost/reply/1');
|
||||
copy(__DIR__ . '/../tantek.html', storage_path('HTML') . '/http/tantek.com/index.html');
|
||||
}
|
||||
|
||||
public function test_parsing_html()
|
||||
/** @test */
|
||||
public function parseWebmentionHtml(): void
|
||||
{
|
||||
$this->assertFileExists(storage_path('HTML') . '/https/aaronpk.localhost/reply/1');
|
||||
$this->assertFileExists(storage_path('HTML') . '/http/tantek.com/index.html');
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Place;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PlacesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test the `/places` page for OK response.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_places_page()
|
||||
public function placesPageLoads(): void
|
||||
{
|
||||
$response = $this->get('/places');
|
||||
$response->assertStatus(200);
|
||||
|
@ -21,9 +23,9 @@ class PlacesTest extends TestCase
|
|||
/**
|
||||
* Test a specific place.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_single_place()
|
||||
public function singlePlacePageLoads(): void
|
||||
{
|
||||
$place = Place::where('slug', 'the-bridgewater-pub')->first();
|
||||
$response = $this->get('/places/the-bridgewater-pub');
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\DownloadWebMention;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ReDownloadWebMentionsTest extends TestCase
|
||||
{
|
||||
public function test_jobs_are_dispatched()
|
||||
/** @test */
|
||||
public function downloadJobGetsQueued(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class SearchControllerTest extends TestCase
|
||||
{
|
||||
public function test_search()
|
||||
/** @test */
|
||||
public function searchPageReturnsResult(): void
|
||||
{
|
||||
$response = $this->get('/search?terms=love');
|
||||
$response->assertSee('duckduckgo.com');
|
||||
|
|
|
@ -1,33 +1,38 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class ShortURLsControllerTest extends TestCase
|
||||
{
|
||||
public function test_short_domain_redirects_to_long_domain()
|
||||
/** @test */
|
||||
public function shortDomainRedirectsToLongDomain(): void
|
||||
{
|
||||
$response = $this->get('http://' . config('app.shorturl'));
|
||||
$response = $this->get('https://' . config('app.shorturl'));
|
||||
$response->assertRedirect(config('app.url'));
|
||||
}
|
||||
|
||||
public function test_short_domain_slashat_redirects_to_twitter()
|
||||
/** @test */
|
||||
public function shortDomainSlashAtRedirectsToTwitter(): void
|
||||
{
|
||||
$response = $this->get('http://' . config('app.shorturl') . '/@');
|
||||
$response = $this->get('https://' . config('app.shorturl') . '/@');
|
||||
$response->assertRedirect('https://twitter.com/jonnybarnes');
|
||||
}
|
||||
|
||||
public function test_short_domain_slasht_redirects_to_long_domain_slash_notes()
|
||||
/** @test */
|
||||
public function shortDomainSlashTRedirectsToLongDomainSlashNotes(): void
|
||||
{
|
||||
$response = $this->get('http://' . config('app.shorturl') . '/t/E');
|
||||
$response = $this->get('https://' . config('app.shorturl') . '/t/E');
|
||||
$response->assertRedirect(config('app.url') . '/notes/E');
|
||||
}
|
||||
|
||||
public function test_short_domain_slashb_redirects_to_long_domain_slash_blog()
|
||||
/** @test */
|
||||
public function shortDomainSlashBRedirectsToLongDomainSlashBlog(): void
|
||||
{
|
||||
$response = $this->get('http://' . config('app.shorturl') . '/b/1');
|
||||
$response = $this->get('https://' . config('app.shorturl') . '/b/1');
|
||||
$response->assertRedirect(config('app.url') . '/blog/s/1');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\SendWebMentions;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
use Tests\TestToken;
|
||||
use Lcobucci\JWT\Builder;
|
||||
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class SwarmTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions, TestToken;
|
||||
use DatabaseTransactions;
|
||||
use TestToken;
|
||||
|
||||
public function test_faked_ownyourswarm_request_with_foursquare()
|
||||
/**
|
||||
* Given a check in to Foursquare, this is the content Ownyourswarm will post to us.
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function mockedOwnyourswarmRequestWithFoursquare(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$response = $this->json(
|
||||
'POST',
|
||||
'api/post',
|
||||
[
|
||||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
|
||||
'published' => [Carbon::now()->toDateTimeString()],
|
||||
'syndication' => ['https://www.swarmapp.com/checkin/abc'],
|
||||
'content' => [[
|
||||
'value' => 'My first #checkin using Example Product',
|
||||
|
@ -48,18 +59,27 @@ class SwarmTest extends TestCase
|
|||
$this->assertDatabaseHas('places', [
|
||||
'external_urls' => '{"foursquare": "https://foursquare.com/v/123456"}'
|
||||
]);
|
||||
|
||||
Queue::assertPushed(SendWebMentions::class);
|
||||
}
|
||||
|
||||
// this request would actually come from another client than OwnYourSwarm
|
||||
public function test_faked_ownyourswarm_request_with_osm()
|
||||
/**
|
||||
* This request would actually come from another client than OwnYourSwarm, but we’re testing
|
||||
* OpenStreetMap data.
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function mockedOwnyourswarmRequestWithOsm(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$response = $this->json(
|
||||
'POST',
|
||||
'api/post',
|
||||
[
|
||||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
|
||||
'published' => [Carbon::now()->toDateTimeString()],
|
||||
'content' => [[
|
||||
'value' => 'My first #checkin using Example Product',
|
||||
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
|
||||
|
@ -83,18 +103,26 @@ class SwarmTest extends TestCase
|
|||
$this->assertDatabaseHas('places', [
|
||||
'external_urls' => '{"osm": "https://www.openstreetmap.org/way/123456"}'
|
||||
]);
|
||||
|
||||
Queue::assertPushed(SendWebMentions::class);
|
||||
}
|
||||
|
||||
// this request would actually come from another client than OwnYourSwarm
|
||||
public function test_faked_ownyourswarm_request_without_known_external_url()
|
||||
/**
|
||||
* This request would actually come from another client than OwnYourSwarm, as that would include a Foursquare URL
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function mockedOwnyourswarmRequestWithoutKnownExternalUrl(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$response = $this->json(
|
||||
'POST',
|
||||
'api/post',
|
||||
[
|
||||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
|
||||
'published' => [Carbon::now()->toDateTimeString()],
|
||||
'content' => [[
|
||||
'value' => 'My first #checkin using Example Product',
|
||||
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
|
||||
|
@ -118,9 +146,12 @@ class SwarmTest extends TestCase
|
|||
$this->assertDatabaseHas('places', [
|
||||
'external_urls' => '{"default": "https://www.example.org/way/123456"}'
|
||||
]);
|
||||
|
||||
Queue::assertPushed(SendWebMentions::class);
|
||||
}
|
||||
|
||||
public function test_faked_ownyourswarm_request_with_no_text_content()
|
||||
/** @test */
|
||||
public function mockedOwnyourswarmRequestWithNoTextContent(): void
|
||||
{
|
||||
$response = $this->json(
|
||||
'POST',
|
||||
|
@ -128,7 +159,7 @@ class SwarmTest extends TestCase
|
|||
[
|
||||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
|
||||
'published' => [Carbon::now()->toDateTimeString()],
|
||||
'syndication' => ['https://www.swarmapp.com/checkin/def'],
|
||||
],
|
||||
'checkin' => [
|
||||
|
@ -152,18 +183,22 @@ class SwarmTest extends TestCase
|
|||
$this->assertDatabaseHas('notes', [
|
||||
'swarm_url' => 'https://www.swarmapp.com/checkin/def'
|
||||
]);
|
||||
// Check the default text content for the note was saved
|
||||
$this->get($response->__get('headers')->get('location'))->assertSee('📍');
|
||||
}
|
||||
|
||||
public function test_faked_ownyourswarm_request_saves_just_post_when_error_in_checkin_data()
|
||||
/** @test */
|
||||
public function mockedOwnyourswarmRequestSavesJustThePostWhenAnErrorOccursInTheCheckinData(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$response = $this->json(
|
||||
'POST',
|
||||
'api/post',
|
||||
[
|
||||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
|
||||
'published' => [Carbon::now()->toDateTimeString()],
|
||||
'syndication' => ['https://www.swarmapp.com/checkin/abc'],
|
||||
'content' => [[
|
||||
'value' => 'My first #checkin using Example Product',
|
||||
|
@ -186,17 +221,22 @@ class SwarmTest extends TestCase
|
|||
$this->assertDatabaseMissing('places', [
|
||||
'name' => 'Awesome Venue',
|
||||
]);
|
||||
|
||||
Queue::assertPushed(SendWebMentions::class);
|
||||
}
|
||||
|
||||
public function test_ownyourswarm_request_with_hadr_location()
|
||||
/** @test */
|
||||
public function mockedOwnyourswarmRequestWithHAdrLocation(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$response = $this->json(
|
||||
'POST',
|
||||
'api/post',
|
||||
[
|
||||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
|
||||
'published' => [Carbon::now()->toDateTimeString()],
|
||||
'syndication' => ['https://www.swarmapp.com/checkin/abc'],
|
||||
'content' => [[
|
||||
'value' => 'My first #checkin using Example Product',
|
||||
|
@ -227,18 +267,20 @@ class SwarmTest extends TestCase
|
|||
$this->assertDatabaseMissing('places', [
|
||||
'name' => 'Awesome Venue',
|
||||
]);
|
||||
|
||||
Queue::assertPushed(SendWebMentions::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_real_ownyourswarm_checkin()
|
||||
public function ownyourswarmCheckinTestUsingRealData(): void
|
||||
{
|
||||
$response = $this->json(
|
||||
'POST',
|
||||
'api/post',
|
||||
[
|
||||
'type' => ['h-entry'],
|
||||
'properties' =>[
|
||||
'published' => [\Carbon\Carbon::now()->toDateTimeString()]
|
||||
'properties' => [
|
||||
'published' => [Carbon::now()->toDateTimeString()]
|
||||
],
|
||||
'syndication' => [
|
||||
'https://www.swarmapp.com/user/199841/checkin/5c4b1ac56dcf04002c0a4f58'
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use IndieAuth\Client;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
use IndieAuth\Client;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class TokenEndpointTest extends TestCase
|
||||
{
|
||||
public function test_token_endpoint_issues_token()
|
||||
/** @test */
|
||||
public function tokenEndpointIssuesToken(): void
|
||||
{
|
||||
$mockClient = Mockery::mock(Client::class);
|
||||
$mockClient->shouldReceive('discoverAuthorizationEndpoint')
|
||||
|
@ -35,7 +37,8 @@ class TokenEndpointTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_token_endpoint_returns_error_when_auth_endpoint_lacks_me_data()
|
||||
/** @test */
|
||||
public function tokenEndpointReturnsErrorWhenAuthEndpointLacksMeData(): void
|
||||
{
|
||||
$mockClient = Mockery::mock(Client::class);
|
||||
$mockClient->shouldReceive('discoverAuthorizationEndpoint')
|
||||
|
@ -60,7 +63,8 @@ class TokenEndpointTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_token_endpoint_returns_error_when_no_auth_endpoint_found()
|
||||
/** @test */
|
||||
public function tokenEndpointReturnsErrorWhenNoAuthEndpointFound(): void
|
||||
{
|
||||
$mockClient = Mockery::mock(Client::class);
|
||||
$mockClient->shouldReceive('discoverAuthorizationEndpoint')
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Services\TokenService;
|
||||
use DateTimeImmutable;
|
||||
use Lcobucci\JWT\Configuration;
|
||||
use Lcobucci\JWT\Signer\Key\InMemory;
|
||||
use Lcobucci\JWT\Validation\RequiredConstraintsViolated;
|
||||
use Tests\TestCase;
|
||||
use App\Services\TokenService;
|
||||
|
||||
class TokenServiceTest extends TestCase
|
||||
{
|
||||
|
@ -15,9 +17,9 @@ class TokenServiceTest extends TestCase
|
|||
* Given the token is dependent on a random nonce, the time of creation and
|
||||
* the APP_KEY, to test, we shall create a token, and then verify it.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_token_creation_and_validation()
|
||||
public function tokenserviceCreatesAndValidatesTokens(): void
|
||||
{
|
||||
$tokenService = new TokenService();
|
||||
$data = [
|
||||
|
@ -35,7 +37,8 @@ class TokenServiceTest extends TestCase
|
|||
$this->assertSame($data, $validData);
|
||||
}
|
||||
|
||||
public function test_token_with_different_signing_key_throws_exception()
|
||||
/** @test */
|
||||
public function tokensWithDifferentSigningKeyThrowsException(): void
|
||||
{
|
||||
$this->expectException(RequiredConstraintsViolated::class);
|
||||
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\ProcessWebMention;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WebMentionsControllerTest extends TestCase
|
||||
{
|
||||
public function test_get_endpoint()
|
||||
/** @test */
|
||||
public function webmentionEndpointCanServeBrowserRequest(): void
|
||||
{
|
||||
$response = $this->get('/webmention');
|
||||
$response->assertViewIs('webmention-endpoint');
|
||||
|
@ -17,20 +20,22 @@ class WebMentionsControllerTest extends TestCase
|
|||
/**
|
||||
* Test webmentions without source and target are rejected.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_webmentions_without_source_and_target_are_rejected()
|
||||
public function webmentionsWithoutSourceAndTargetAreRejected(): void
|
||||
{
|
||||
$response = $this->call('POST', '/webmention', ['source' => 'https://example.org/post/123']);
|
||||
$response->assertStatus(400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid target gets a 400 response.
|
||||
* Test invalid target gives a 400 response.
|
||||
*
|
||||
* @return void
|
||||
* In this case an invalid target is a URL that doesn’t exist on our domain.
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function test_invalid_target_returns_400_response()
|
||||
public function invalidTargetReturnsErrorResponse(): void
|
||||
{
|
||||
$response = $this->call('POST', '/webmention', [
|
||||
'source' => 'https://example.org/post/123',
|
||||
|
@ -40,11 +45,11 @@ class WebMentionsControllerTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test blog target gets a 501 response due to me not supporting it.
|
||||
* Test blog target gets a 501 response due to our not supporting it.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_blog_target_returns_501_response()
|
||||
public function blogTargetReturns501Response(): void
|
||||
{
|
||||
$response = $this->call('POST', '/webmention', [
|
||||
'source' => 'https://example.org/post/123',
|
||||
|
@ -54,11 +59,11 @@ class WebMentionsControllerTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that a non-existant note gives a 400 response.
|
||||
* Test that a non-existent note gives a 400 response.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function test_nonexistant_note_returns_400_response()
|
||||
public function nonexistentNoteReturnsErrorResponse(): void
|
||||
{
|
||||
$response = $this->call('POST', '/webmention', [
|
||||
'source' => 'https://example.org/post/123',
|
||||
|
@ -67,12 +72,8 @@ class WebMentionsControllerTest extends TestCase
|
|||
$response->assertStatus(400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a legit webmention triggers the ProcessWebMention job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_legitimate_webmnetion_triggers_processwebmention_job()
|
||||
/** @test */
|
||||
public function legitimateWebmentionTriggersProcesswebmentionJob(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Article;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ArticlesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_sluggable_method()
|
||||
/** @test */
|
||||
public function titleSlugIsGeneratedAutomatically(): void
|
||||
{
|
||||
$article = new Article();
|
||||
$article->title = 'My Title';
|
||||
|
@ -20,15 +23,17 @@ class ArticlesTest extends TestCase
|
|||
$this->assertEquals('my-title', $article->titleurl);
|
||||
}
|
||||
|
||||
public function test_markdown_conversion()
|
||||
/** @test */
|
||||
public function markdownContentIsConverted(): void
|
||||
{
|
||||
$article = new Article();
|
||||
$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([
|
||||
'title' => 'Test',
|
||||
|
@ -41,7 +46,8 @@ class ArticlesTest extends TestCase
|
|||
$this->assertEquals($article->pubdate, $article->updated_at->toRSSString());
|
||||
}
|
||||
|
||||
public function test_link_accessor()
|
||||
/** @test */
|
||||
public function weGenerateTheArticleLinkFromTheSlug(): void
|
||||
{
|
||||
$article = Article::create([
|
||||
'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();
|
||||
$this->assertTrue(count($yearAndMonth) === 1);
|
||||
|
|
|
@ -1,27 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Exceptions\InternetArchiveException;
|
||||
use App\Services\BookmarkService;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use App\Services\BookmarkService;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use App\Exceptions\InternetArchiveException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BookmarksTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @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'));
|
||||
}
|
||||
}*/
|
||||
|
||||
public function test_archive_link_method()
|
||||
/** @test */
|
||||
public function archiveLinkMethodCallsArchiveService(): void
|
||||
{
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['Content-Location' => '/web/1234/example.org']),
|
||||
|
@ -33,7 +37,8 @@ class BookmarksTest extends TestCase
|
|||
$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);
|
||||
|
||||
|
@ -43,10 +48,11 @@ class BookmarksTest extends TestCase
|
|||
$handler = HandlerStack::create($mock);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
$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);
|
||||
|
||||
|
@ -56,6 +62,6 @@ class BookmarksTest extends TestCase
|
|||
$handler = HandlerStack::create($mock);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
$this->app->instance(Client::class, $client);
|
||||
$url = (new BookmarkService())->getArchiveLink('https://example.org');
|
||||
(new BookmarkService())->getArchiveLink('https://example.org');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,47 +1,42 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\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';
|
||||
$this->assertEquals(normalize_url(normalize_url($input)), normalize_url($input));
|
||||
}
|
||||
|
||||
public function urlProvider()
|
||||
{
|
||||
return [
|
||||
['https://example.org/', 'https://example.org'],
|
||||
['https://example.org:443/', 'https://example.org'],
|
||||
['http://www.foo.bar/index.php/', 'http://www.foo.bar'],
|
||||
['https://example.org/?foo=bar&baz=true', 'https://example.org?baz=true&foo=bar'],
|
||||
[
|
||||
'http://example.org/?ref_src=twcamp^share|twsrc^ios|twgr^software.studioh.Indigenous.share-micropub',
|
||||
'http://example.org',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider urlProvider
|
||||
* @group temp
|
||||
* @param string $input
|
||||
* @param string $output
|
||||
*/
|
||||
public function test_normalize_url($input, $output)
|
||||
public function normalizeUrlOnDataProvider(string $input, string $output): void
|
||||
{
|
||||
$this->assertEquals($output, normalize_url($input));
|
||||
}
|
||||
|
||||
public function test_pretty_print_json()
|
||||
/** @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;
|
||||
{"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": {
|
||||
|
@ -65,8 +60,23 @@ JSON;
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EXPECTED;
|
||||
}
|
||||
EXPECTED;
|
||||
|
||||
$this->assertEquals($expected, prettyPrintJson($json));
|
||||
}
|
||||
|
||||
public function urlProvider(): array
|
||||
{
|
||||
return [
|
||||
['https://example.org/', 'https://example.org'],
|
||||
['https://example.org:443/', 'https://example.org'],
|
||||
['http://www.foo.bar/index.php/', 'http://www.foo.bar'],
|
||||
['https://example.org/?foo=bar&baz=true', 'https://example.org?baz=true&foo=bar'],
|
||||
[
|
||||
'http://example.org/?ref_src=twcamp^share|twsrc^ios|twgr^software.studioh.Indigenous.share-micropub',
|
||||
'http://example.org',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\AddClientToDatabase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AddClientToDatabaseJobTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_job_adds_client()
|
||||
/** @test */
|
||||
public function clientIsAddedToDatabaseByJob(): void
|
||||
{
|
||||
$job = new AddClientToDatabase('https://example.org/client');
|
||||
$job->handle();
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\DownloadWebMention;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use App\Jobs\DownloadWebMention;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use Illuminate\FileSystem\FileSystem;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DownloadWebMentionJobTest extends TestCase
|
||||
{
|
||||
|
@ -21,15 +23,16 @@ class DownloadWebMentionJobTest extends TestCase
|
|||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_the_job_saves_html()
|
||||
/** @test */
|
||||
public function htmlIsSavedByJob(): void
|
||||
{
|
||||
$this->assertFileDoesNotExist(storage_path('HTML/https'));
|
||||
$source = 'https://example.org/reply/1';
|
||||
$html = <<<HTML
|
||||
<div class="h-entry">
|
||||
<div class="h-entry">
|
||||
<a class="u-like-of" href=""></a>
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html);
|
||||
$mock = new MockHandler([
|
||||
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');
|
||||
}
|
||||
|
||||
public function test_the_job_saves_html_and_backup()
|
||||
/** @test */
|
||||
public function htmlAndBackupSavedByJob(): void
|
||||
{
|
||||
$this->assertFileDoesNotExist(storage_path('HTML/https'));
|
||||
$source = 'https://example.org/reply/1';
|
||||
$html = <<<HTML
|
||||
<div class="h-entry">
|
||||
<div class="h-entry">
|
||||
<a class="u-like-of" href=""></a>
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$html2 = <<<HTML
|
||||
<div class="h-entry">
|
||||
<div class="h-entry">
|
||||
<a class="u-like-of" href=""></a>
|
||||
<a class="u-repost-of" href=""></a>
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html);
|
||||
$html2 = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html2);
|
||||
$mock = new MockHandler([
|
||||
|
@ -82,15 +86,16 @@ HTML;
|
|||
$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'));
|
||||
$source = 'https://example.org/reply-one/';
|
||||
$html = <<<HTML
|
||||
<div class="h-entry">
|
||||
<div class="h-entry">
|
||||
<a class="u-like-of" href=""></a>
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html);
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['X-Foo' => 'Bar'], $html),
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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\Jobs\ProcessBookmark;
|
||||
use App\Models\Bookmark;
|
||||
use App\Services\BookmarkService;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProcessBookmarkJobTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_screenshot_and_archive_link_are_saved()
|
||||
/** @test */
|
||||
public function screenshotAndArchiveLinkAreSavedByJob(): void
|
||||
{
|
||||
$bookmark = Bookmark::find(1);
|
||||
$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);
|
||||
$uuid = Uuid::uuid4();
|
||||
|
@ -46,7 +46,7 @@ class ProcessBookmarkJobTest extends TestCase
|
|||
$service->method('saveScreenshot')
|
||||
->willReturn($uuid->toString());
|
||||
$service->method('getArchiveLink')
|
||||
->will($this->throwException(new InternetArchiveException));
|
||||
->will($this->throwException(new InternetArchiveException()));
|
||||
$this->app->instance(BookmarkService::class, $service);
|
||||
|
||||
$job = new ProcessBookmark($bookmark);
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use Storage;
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\ProcessMedia;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProcessMediaJobTest extends TestCase
|
||||
{
|
||||
public function test_job_does_nothing_to_non_image()
|
||||
/** @test */
|
||||
public function nonMediaFilesAreNotSaved(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
$manager = app()->make(ImageManager::class);
|
||||
|
@ -20,18 +23,20 @@ class ProcessMediaJobTest extends TestCase
|
|||
$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');
|
||||
$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->handle($manager);
|
||||
|
||||
$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);
|
||||
Storage::disk('local')->put('test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Exceptions\RemoteContentNotFoundException;
|
||||
use App\Jobs\ProcessWebMention;
|
||||
use App\Jobs\SaveProfileImage;
|
||||
use App\Models\Note;
|
||||
use GuzzleHttp\Client;
|
||||
use App\Models\WebMention;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use App\Jobs\SaveProfileImage;
|
||||
use App\Jobs\ProcessWebMention;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use Illuminate\FileSystem\FileSystem;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Jonnybarnes\WebmentionsParser\Parser;
|
||||
use App\Exceptions\RemoteContentNotFoundException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProcessWebMentionJobTest extends TestCase
|
||||
{
|
||||
|
@ -30,7 +32,8 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_for_exception_from_failure_to_get_webmention()
|
||||
/** @test */
|
||||
public function failureGettingWebmentionThrowsAnException(): void
|
||||
{
|
||||
$this->expectException(RemoteContentNotFoundException::class);
|
||||
|
||||
|
@ -48,17 +51,18 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
$job->handle($parser, $client);
|
||||
}
|
||||
|
||||
public function test_a_new_webmention_gets_saved()
|
||||
/** @test */
|
||||
public function newWebmentionGetsSavedByJob(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$parser = new Parser();
|
||||
|
||||
$html = <<<HTML
|
||||
<div class="h-entry">
|
||||
<div class="h-entry">
|
||||
I liked <a class="u-like-of" href="/notes/1">a note</a>.
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$html = str_replace('href="', 'href="' . config('app.url'), $html);
|
||||
$mock = new MockHandler([
|
||||
new Response(200, [], $html),
|
||||
|
@ -79,18 +83,19 @@ HTML;
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_existing_webmention_gets_updated()
|
||||
/** @test */
|
||||
public function existingWebmentionGetsUpdatedByJob(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$parser = new Parser();
|
||||
|
||||
$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>
|
||||
<div class="e-content">Updated reply</div>
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$html = str_replace('href="', 'href="' . config('app.url'), $html);
|
||||
$mock = new MockHandler([
|
||||
new Response(200, [], $html),
|
||||
|
@ -108,20 +113,22 @@ HTML;
|
|||
$this->assertDatabaseHas('webmentions', [
|
||||
'source' => $source,
|
||||
'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": []}',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_webmention_reply_gets_deleted()
|
||||
/** @test */
|
||||
public function webmentionReplyGetsDeletedWhenReplyToValueChanges(): void
|
||||
{
|
||||
$parser = new Parser();
|
||||
|
||||
$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>
|
||||
<div class="e-content">Replying to someone else</div>
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$mock = new MockHandler([
|
||||
new Response(200, [], $html),
|
||||
]);
|
||||
|
@ -148,16 +155,17 @@ HTML;
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_webmention_like_gets_deleted()
|
||||
/** @test */
|
||||
public function webmentionLikeGetsDeletedWhenLikeOfValueChanges(): void
|
||||
{
|
||||
$parser = new Parser();
|
||||
|
||||
$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>
|
||||
<div class="e-content">I like someone else now</div>
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$mock = new MockHandler([
|
||||
new Response(200, [], $html),
|
||||
]);
|
||||
|
@ -184,16 +192,17 @@ HTML;
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_webmention_repost_gets_deleted()
|
||||
/** @test */
|
||||
public function webmentionRepostGetsDeletedWhenRepostOfValueChanges(): void
|
||||
{
|
||||
$parser = new Parser();
|
||||
|
||||
$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>
|
||||
<div class="e-content">Reposting someone else</div>
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$mock = new MockHandler([
|
||||
new Response(200, [], $html),
|
||||
]);
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\SaveProfileImage;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use App\Jobs\SaveProfileImage;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use Jonnybarnes\WebmentionsParser\Authorship;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SaveProfileImageJobTest extends TestCase
|
||||
{
|
||||
|
@ -22,18 +23,21 @@ class SaveProfileImageJobTest extends TestCase
|
|||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
public function test_authorship_algo_exception_return_null()
|
||||
|
||||
/** @test */
|
||||
public function authorshipAlgorithmReturnsNullOnException(): void
|
||||
{
|
||||
$mf = ['items' => []];
|
||||
$authorship = $this->createMock(Authorship::class);
|
||||
$authorship->method('findAuthor')
|
||||
->will($this->throwException(new AuthorshipParserException));
|
||||
->will($this->throwException(new AuthorshipParserException()));
|
||||
$job = new SaveProfileImage($mf);
|
||||
|
||||
$this->assertNull($job->handle($authorship));
|
||||
}
|
||||
|
||||
public function test_we_dont_process_twitter_images()
|
||||
/** @test */
|
||||
public function weDoNotProcessTwitterImages(): void
|
||||
{
|
||||
$mf = ['items' => []];
|
||||
$author = [
|
||||
|
@ -50,7 +54,8 @@ class SaveProfileImageJobTest extends TestCase
|
|||
$this->assertNull($job->handle($authorship));
|
||||
}
|
||||
|
||||
public function test_saving_of_remote_image()
|
||||
/** @test */
|
||||
public function remoteAuthorImagesAreSavedLocally(): void
|
||||
{
|
||||
$mock = new MockHandler([
|
||||
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');
|
||||
}
|
||||
|
||||
public function test_copying_of_local_image()
|
||||
/** @test */
|
||||
public function localDefaultAuthorImageIsUsedAsFallback(): void
|
||||
{
|
||||
$mock = new MockHandler([
|
||||
new Response(404),
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\SendWebMentions;
|
||||
use App\Models\Note;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use App\Jobs\SendWebMentions;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SendWebMentionJobTest extends TestCase
|
||||
{
|
||||
public function test_dicover_endoint_method_on_self()
|
||||
/** @test */
|
||||
public function discoverWebmentionEndpointOnOwnDomain(): void
|
||||
{
|
||||
$note = new Note();
|
||||
$job = new SendWebMentions($note);
|
||||
|
@ -21,7 +23,8 @@ class SendWebMentionJobTest extends TestCase
|
|||
$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';
|
||||
$mock = new MockHandler([
|
||||
|
@ -35,7 +38,8 @@ class SendWebMentionJobTest extends TestCase
|
|||
$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">';
|
||||
$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">';
|
||||
$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());
|
||||
$this->assertNull($job->handle());
|
||||
}
|
||||
|
||||
public function test_resolve_uri()
|
||||
/** @test */
|
||||
public function weResolveRelativeUris(): void
|
||||
{
|
||||
$uri = '/blog/post';
|
||||
$base = 'https://example.org/';
|
||||
|
@ -83,7 +90,8 @@ class SendWebMentionJobTest extends TestCase
|
|||
$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">';
|
||||
$mock = new MockHandler([
|
||||
|
@ -98,6 +106,7 @@ class SendWebMentionJobTest extends TestCase
|
|||
$note->note = 'Hi [Aaron](https://aaronparecki.com)';
|
||||
$note->save();
|
||||
$job = new SendWebMentions($note);
|
||||
$this->assertNull($job->handle());
|
||||
$job->handle();
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use Tests\TestCase;
|
||||
use GuzzleHttp\Client;
|
||||
use App\Jobs\SyndicateBookmarkToTwitter;
|
||||
use App\Models\Bookmark;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use App\Jobs\SyndicateBookmarkToTwitter;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SyndicateBookmarkToTwitterJobTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_the_job()
|
||||
/** @test */
|
||||
public function weSendBookmarksToTwitter(): void
|
||||
{
|
||||
$json = json_encode([
|
||||
'url' => 'https://twitter.com/123'
|
||||
|
|
|
@ -2,20 +2,21 @@
|
|||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\SyndicateNoteToTwitter;
|
||||
use App\Models\Note;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use App\Jobs\SyndicateNoteToTwitter;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SyndicateNoteToTwitterJobTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_the_job()
|
||||
/** @test */
|
||||
public function weSyndicateNotesToTwitter(): void
|
||||
{
|
||||
$json = json_encode([
|
||||
'url' => 'https://twitter.com/i/web/status/123'
|
||||
|
|
|
@ -1,23 +1,27 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Like;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LikesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_setting_author_url()
|
||||
/** @test */
|
||||
public function weCanSetTheAuthorUrl(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like->author_url = 'https://joe.bloggs/';
|
||||
$this->assertEquals('https://joe.bloggs', $like->author_url);
|
||||
}
|
||||
|
||||
public function test_plaintext_like_content()
|
||||
/** @test */
|
||||
public function weDoNotModifyPlainTextContent(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like->url = 'https://example.org/post/123';
|
||||
|
@ -27,27 +31,28 @@ class LikesTest extends TestCase
|
|||
$this->assertEquals('some plaintext content', $like->content);
|
||||
}
|
||||
|
||||
public function test_html_like_content_is_filtered()
|
||||
/** @test */
|
||||
public function htmlLikeContentIsFiltered(): void
|
||||
{
|
||||
$htmlEvil = <<<HTML
|
||||
<div class="h-entry">
|
||||
<div class="h-entry">
|
||||
<div class="e-content">
|
||||
<p>Hello</p>
|
||||
<img src="javascript:evil();" onload="evil();" />
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
</div>
|
||||
HTML;
|
||||
$htmlFiltered = <<<HTML
|
||||
<p>Hello</p>
|
||||
<p>Hello</p>
|
||||
<img />
|
||||
HTML;
|
||||
HTML;
|
||||
$like = new Like();
|
||||
$like->url = 'https://example.org/post/123';
|
||||
$like->content = $htmlEvil;
|
||||
$like->save();
|
||||
|
||||
// HTMLPurifer will leave the whitespace before the <img> tag
|
||||
// trim it, saving whitespace in $htmlFilteres can get removed by text editors
|
||||
// HTMLPurifier will leave the whitespace before the <img> tag
|
||||
// trim it, saving whitespace in $htmlFiltered can get removed by text editors
|
||||
$this->assertEquals($htmlFiltered, trim($like->content));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Media;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MediaTest extends TestCase
|
||||
{
|
||||
public function test_get_note_from_media()
|
||||
/** @test */
|
||||
public function getTheNoteThatMediaInstanceBelongsTo(): void
|
||||
{
|
||||
$media = Media::find(1);
|
||||
$note = $media->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';
|
||||
$media = new Media();
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\MicropubClient;
|
||||
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);
|
||||
$this->assertInstanceOf(Collection::class, $client->notes);
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\{Media, Note, Tag};
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use App\Models\{Media, Note, Tag};
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NotesTest extends TestCase
|
||||
{
|
||||
|
@ -18,10 +20,12 @@ class NotesTest extends TestCase
|
|||
* Test the getNoteAttribute method. This will then also call the
|
||||
* relevant sub-methods.
|
||||
*
|
||||
* @test
|
||||
* @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;
|
||||
$note = Note::find(2);
|
||||
$this->assertEquals($expected, $note->note);
|
||||
|
@ -30,10 +34,12 @@ class NotesTest extends TestCase
|
|||
/**
|
||||
* Look for a default image in the contact’s h-card for the makeHCards method.
|
||||
*
|
||||
* @test
|
||||
* @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;
|
||||
$note = Note::find(4);
|
||||
$this->assertEquals($expected, $note->note);
|
||||
|
@ -42,10 +48,12 @@ class NotesTest extends TestCase
|
|||
/**
|
||||
* Look for a specific profile image in the contact’s h-card.
|
||||
*
|
||||
* @test
|
||||
* @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;
|
||||
$note = Note::find(5);
|
||||
$this->assertEquals($expected, $note->note);
|
||||
|
@ -54,42 +62,48 @@ class NotesTest extends TestCase
|
|||
/**
|
||||
* Look for twitter URL when there’s no associated contact.
|
||||
*
|
||||
* @test
|
||||
* @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;
|
||||
$note = Note::find(6);
|
||||
$this->assertEquals($expected, $note->note);
|
||||
}
|
||||
|
||||
public function test_shorturl_method()
|
||||
/** @test */
|
||||
public function shorturlMethodReturnsExpectedValue(): void
|
||||
{
|
||||
$note = Note::find(14);
|
||||
$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
|
||||
$this->assertEquals('53.4983', $note->latitude);
|
||||
$this->assertEquals('-2.3805', $note->longitude);
|
||||
}
|
||||
|
||||
public function test_latlng_returns_null_otherwise()
|
||||
/** @test */
|
||||
public function whenNoAssociatedPlaceWeGetNullForLatitudeLongitudeValues(): void
|
||||
{
|
||||
$note = Note::find(5);
|
||||
$this->assertNull($note->latitude);
|
||||
$this->assertNull($note->longitude);
|
||||
}
|
||||
|
||||
public function test_address_attribute_for_places()
|
||||
/** @test */
|
||||
public function weCanGetAddressAttributeForAssociatedPlace(): void
|
||||
{
|
||||
$note = Note::find(2);
|
||||
$this->assertEquals('The Bridgewater Pub', $note->address);
|
||||
}
|
||||
|
||||
public function test_deleting_event_observer()
|
||||
/** @test */
|
||||
public function deletingNotesAlsoDeletesTagsViaTheEventObserver(): void
|
||||
{
|
||||
// first we’ll create a temporary note to delete
|
||||
$note = Note::create(['note' => 'temporary #temp']);
|
||||
|
@ -104,7 +118,7 @@ class NotesTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function blank_note_should_be_saved_as_null()
|
||||
public function saveBlankNotesAsNull(): void
|
||||
{
|
||||
$note = new Note(['note' => '']);
|
||||
|
||||
|
@ -112,11 +126,13 @@ class NotesTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function reverse_geocode_an_attraction()
|
||||
public function reverseGeocodeAnAttraction(): void
|
||||
{
|
||||
// phpcs:disable Generic.Files.LineLength.TooLong
|
||||
$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"]}
|
||||
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"]}
|
||||
JSON;
|
||||
// phpcs:enable Generic.Files.LineLength.TooLong
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['Content-Type' => 'application/json'], $json),
|
||||
]);
|
||||
|
@ -128,15 +144,20 @@ JSON;
|
|||
$note = new Note();
|
||||
$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 */
|
||||
public function reverse_geocode_a_suburb()
|
||||
public function reverseGeocodeASuburb(): void
|
||||
{
|
||||
// phpcs:disable Generic.Files.LineLength.TooLong
|
||||
$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"]}
|
||||
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"]}
|
||||
JSON;
|
||||
// phpcs:enable Generic.Files.LineLength.TooLong
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['Content-Type' => 'application/json'], $json),
|
||||
]);
|
||||
|
@ -148,17 +169,22 @@ JSON;
|
|||
$note = new Note();
|
||||
$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 */
|
||||
public function reverse_geocode_a_city()
|
||||
public function reverseGeocodeACity(): void
|
||||
{
|
||||
// Note I’ve modified this JSON response so it only contains the
|
||||
// city the Uni is in
|
||||
// phpcs:disable Generic.Files.LineLength.TooLong
|
||||
$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"]}
|
||||
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"]}
|
||||
JSON;
|
||||
// phpcs:enable Generic.Files.LineLength.TooLong
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['Content-Type' => 'application/json'], $json),
|
||||
]);
|
||||
|
@ -170,17 +196,22 @@ JSON;
|
|||
$note = new Note();
|
||||
$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 */
|
||||
public function reverse_geocode_a_county()
|
||||
public function reverseGeocodeACounty(): void
|
||||
{
|
||||
// Note I’ve removed everything below county to test for querires where
|
||||
// that’s all that is returned
|
||||
// phpcs:disable Generic.Files.LineLength.TooLong
|
||||
$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"]}
|
||||
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"]}
|
||||
JSON;
|
||||
// phpcs:enable Generic.Files.LineLength.TooLong
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['Content-Type' => 'application/json'], $json),
|
||||
]);
|
||||
|
@ -196,13 +227,15 @@ JSON;
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function reverse_geocode_a_country()
|
||||
public function reverseGeocodeACountry(): void
|
||||
{
|
||||
// Note I’ve removed everything below country to test for querires where
|
||||
// that’s all that is returned
|
||||
// phpcs:disable Generic.Files.LineLength.TooLong
|
||||
$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"]}
|
||||
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"]}
|
||||
JSON;
|
||||
// phpcs:enable Generic.Files.LineLength.TooLong
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['Content-Type' => 'application/json'], $json),
|
||||
]);
|
||||
|
@ -218,12 +251,12 @@ JSON;
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function add_image_element_to_note_content()
|
||||
public function addImageElementToNoteContentWhenMediaAssociated(): void
|
||||
{
|
||||
$media = new Media([
|
||||
'type' => 'image',
|
||||
'path' => 'test.png']
|
||||
);
|
||||
'path' => 'test.png',
|
||||
]);
|
||||
$media->save();
|
||||
$note = new Note(['note' => 'A nice image']);
|
||||
$note->save();
|
||||
|
@ -235,12 +268,12 @@ JSON;
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function add_video_element_to_note_content()
|
||||
public function addVideoElementToNoteContentWhenMediaAssociated(): void
|
||||
{
|
||||
$media = new Media([
|
||||
'type' => 'video',
|
||||
'path' => 'test.mkv']
|
||||
);
|
||||
'path' => 'test.mkv',
|
||||
]);
|
||||
$media->save();
|
||||
$note = new Note(['note' => 'A nice video']);
|
||||
$note->save();
|
||||
|
@ -252,12 +285,12 @@ JSON;
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function add_audio_element_to_note_content()
|
||||
public function addAudioElementToNoteContentWhenMediaAssociated(): void
|
||||
{
|
||||
$media = new Media([
|
||||
'type' => 'audio',
|
||||
'path' => 'test.flac']
|
||||
);
|
||||
'path' => 'test.flac',
|
||||
]);
|
||||
$media->save();
|
||||
$note = new Note(['note' => 'Some nice audio']);
|
||||
$note->save();
|
||||
|
@ -268,24 +301,29 @@ JSON;
|
|||
$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();
|
||||
|
||||
$this->assertEquals('A blank note', $note->content);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function twitter_content_is_null_when_oembed_error_occurs()
|
||||
// @todo Sort out twitter requests
|
||||
/** @test
|
||||
public function setTwitterContentToNullWhenOembedErrorOccurs(): void
|
||||
{
|
||||
$note = new Note();
|
||||
$note->in_reply_to = 'https://twitter.com/search';
|
||||
|
||||
$this->assertNull($note->twitter);
|
||||
}
|
||||
}*/
|
||||
|
||||
public function test_markdown_gets_converted()
|
||||
/** @test */
|
||||
public function markdownContentGetsConverted(): void
|
||||
{
|
||||
$note = Note::create([
|
||||
'note' => 'The best search engine? https://duckduckgo.com',
|
||||
|
|
|
@ -1,55 +1,57 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Place;
|
||||
use App\Services\PlaceService;
|
||||
use MStaack\LaravelPostgis\Geometries\Point;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use InvalidArgumentException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PlacesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_notes_method()
|
||||
/** @test */
|
||||
public function canRetrieveAssociatedNotes(): void
|
||||
{
|
||||
$place = Place::find(1);
|
||||
$this->assertInstanceOf(Collection::class, $place->notes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the near method returns a collection.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_near_method()
|
||||
/** @test */
|
||||
public function nearMethodReturnsCollection(): void
|
||||
{
|
||||
$nearby = Place::near((object) ['latitude' => 53.5, 'longitude' => -2.38], 1000)->get();
|
||||
$this->assertEquals('the-bridgewater-pub', $nearby[0]->slug);
|
||||
}
|
||||
|
||||
public function test_longurl_method()
|
||||
/** @test */
|
||||
public function getLongurl(): void
|
||||
{
|
||||
$place = Place::find(1);
|
||||
$this->assertEquals(config('app.url') . '/places/the-bridgewater-pub', $place->longurl);
|
||||
}
|
||||
|
||||
public function test_uri_method()
|
||||
{
|
||||
$place = Place::find(1);
|
||||
$this->assertEquals(config('app.url') . '/places/the-bridgewater-pub', $place->uri);
|
||||
|
||||
}
|
||||
|
||||
public function test_shorturl_method()
|
||||
/** @test */
|
||||
public function getShorturl()
|
||||
{
|
||||
$place = Place::find(1);
|
||||
$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->name = 'Temp Place';
|
||||
|
@ -64,28 +66,31 @@ class PlacesTest extends TestCase
|
|||
]
|
||||
]);
|
||||
$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');
|
||||
|
||||
$service = new PlaceService();
|
||||
$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');
|
||||
|
||||
$service = new PlaceService();
|
||||
$service->createPlaceFromCheckin(['properties' => ['name' => 'bar']]);
|
||||
}
|
||||
|
||||
public function test_updating_external_urls()
|
||||
/** @test */
|
||||
public function placeServcieCanupdateExternalUrls(): void
|
||||
{
|
||||
$place = Place::find(1);
|
||||
$place->external_urls = 'https://bridgewater.pub';
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Tag;
|
||||
|
@ -7,15 +9,17 @@ use Tests\TestCase;
|
|||
|
||||
class TagsTest extends TestCase
|
||||
{
|
||||
public function test_notes_method()
|
||||
/** @test */
|
||||
public function canGetAssociatedNotes(): void
|
||||
{
|
||||
$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
|
||||
$this->assertEquals(1, count($tag->bookmarks));
|
||||
$this->assertCount(1, $tag->bookmarks);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +1,38 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Codebird\Codebird;
|
||||
use Tests\TestCase;
|
||||
use App\Models\WebMention;
|
||||
use Thujohn\Twitter\Facades\Twitter;
|
||||
use Codebird\Codebird;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WebMentionTest extends TestCase
|
||||
{
|
||||
public function test_commentable_method()
|
||||
/** @test */
|
||||
public function commentableMethodLinksToNotes(): void
|
||||
{
|
||||
$webmention = WebMention::find(1);
|
||||
$this->assertInstanceOf('App\Models\Note', $webmention->commentable);
|
||||
}
|
||||
public function test_published_attribute_when_no_relavent_mf2()
|
||||
|
||||
/** @test */
|
||||
public function publishedAttributeUsesUpdatedAtWhenNoRelevantMf2Data(): void
|
||||
{
|
||||
$webmention = new WebMention();
|
||||
$updated_at = carbon()->now();
|
||||
$updated_at = Carbon::now();
|
||||
$webmention->updated_at = $updated_at;
|
||||
$this->assertEquals($updated_at->toDayDateTimeString(), $webmention->published);
|
||||
}
|
||||
|
||||
public function test_published_attribute_when_error_parsing_mf2()
|
||||
/** @test */
|
||||
public function publishedAttributeUsesUpdatedAtWhenErrorParsingMf2Data(): void
|
||||
{
|
||||
$webmention = new WebMention();
|
||||
$updated_at = carbon()->now();
|
||||
$updated_at = Carbon::now();
|
||||
$webmention->updated_at = $updated_at;
|
||||
$webmention->mf2 = json_encode([
|
||||
'items' => [[
|
||||
|
@ -40,12 +46,8 @@ class WebMentionTest extends TestCase
|
|||
$this->assertEquals($updated_at->toDayDateTimeString(), $webmention->published);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a correct profile link is formed from a generic URL.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_create_photo_link_with_non_cached_image()
|
||||
/** @test */
|
||||
public function createPhotoLinkDoesNothingWithGenericUrlAndNoLocallySavedImage(): void
|
||||
{
|
||||
$webmention = new WebMention();
|
||||
$homepage = 'https://example.org/profile.png';
|
||||
|
@ -53,12 +55,8 @@ class WebMentionTest extends TestCase
|
|||
$this->assertEquals($expected, $webmention->createPhotoLink($homepage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a correct profile link is formed from a generic URL (cached).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_create_photo_link_with_cached_image()
|
||||
/** @test */
|
||||
public function createPhotoLinkReturnsLocallySavedImageUrlIfItExists(): void
|
||||
{
|
||||
$webmention = new WebMention();
|
||||
$homepage = 'https://aaronparecki.com/profile.png';
|
||||
|
@ -66,12 +64,8 @@ class WebMentionTest extends TestCase
|
|||
$this->assertEquals($expected, $webmention->createPhotoLink($homepage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a correct profile link is formed from a twitter URL.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_create_photo_link_with_twimg_profile_image_url()
|
||||
/** @test */
|
||||
public function createPhotoLinkDealsWithSpecialCaseOfDirectTwitterPhotoLinks(): void
|
||||
{
|
||||
$webmention = new WebMention();
|
||||
$twitterProfileImage = 'http://pbs.twimg.com/1234';
|
||||
|
@ -79,12 +73,8 @@ class WebMentionTest extends TestCase
|
|||
$this->assertEquals($expected, $webmention->createPhotoLink($twitterProfileImage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test `null` is returned for a twitter profile.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_create_photo_link_with_cached_twitter_url()
|
||||
/** @test */
|
||||
public function createPhotoLinkReturnsCachedTwitterPhotoLinks(): void
|
||||
{
|
||||
$webmention = new WebMention();
|
||||
$twitterURL = 'https://twitter.com/example';
|
||||
|
@ -93,10 +83,12 @@ class WebMentionTest extends TestCase
|
|||
$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->profile_image_url_https = 'https://pbs.twimg.com/static_profile_link.jpg';
|
||||
$info = (object) [
|
||||
'profile_image_url_https' => 'https://pbs.twimg.com/static_profile_link.jpg',
|
||||
];
|
||||
$codebirdMock = $this->getMockBuilder(Codebird::class)
|
||||
->addMethods(['users_show'])
|
||||
->getMock();
|
||||
|
@ -117,13 +109,15 @@ class WebMentionTest extends TestCase
|
|||
$this->assertEquals($expected, $webmention->createPhotoLink($twitterURL));
|
||||
}
|
||||
|
||||
public function test_get_reply_attribute_returns_null()
|
||||
/** @test */
|
||||
public function getReplyAttributeDefaultsToNull(): void
|
||||
{
|
||||
$webmention = new WebMention();
|
||||
$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->mf2 = json_encode(['no_html' => 'found_here']);
|
||||
|
|
|
@ -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;
|
|
@ -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"
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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};
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue