Host images locally
Some checks failed
PHP Unit / PHPUnit test suite (pull_request) Has been cancelled
Laravel Pint / Laravel Pint (pull_request) Has been cancelled

We don’t need the complexity of S3. Sepcifically the complexity of
managing my own AWS account, flysystem made the Laravel side easy.

A command is added to copy the the S3 files over to local storage.
This commit is contained in:
Jonny Barnes 2024-10-25 20:40:52 +01:00
parent d80e8164c8
commit d7da42b626
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
47 changed files with 295 additions and 214 deletions

View file

@ -32,7 +32,7 @@ abstract class DuskTestCase extends BaseTestCase
{
$desiredCapabilities = DesiredCapabilities::chrome();
$options = new ChromeOptions();
$options = new ChromeOptions;
$options->addArguments([
'headless',
'disable-gpu',

View file

@ -78,7 +78,7 @@ class LikesTest extends TestCase
/** @test */
public function likeWithSimpleAuthor(): void
{
$like = new Like();
$like = new Like;
$like->url = 'http://example.org/note/id';
$like->save();
$id = $like->id;
@ -107,7 +107,7 @@ class LikesTest extends TestCase
$this->app->bind(Client::class, function () use ($client) {
return $client;
});
$authorship = new Authorship();
$authorship = new Authorship;
$job->handle($client, $authorship);
@ -117,7 +117,7 @@ class LikesTest extends TestCase
/** @test */
public function likeWithHCard(): void
{
$like = new Like();
$like = new Like;
$like->url = 'http://example.org/note/id';
$like->save();
$id = $like->id;
@ -150,7 +150,7 @@ class LikesTest extends TestCase
$this->app->bind(Client::class, function () use ($client) {
return $client;
});
$authorship = new Authorship();
$authorship = new Authorship;
$job->handle($client, $authorship);
@ -160,7 +160,7 @@ class LikesTest extends TestCase
/** @test */
public function likeWithoutMicroformats(): void
{
$like = new Like();
$like = new Like;
$like->url = 'http://example.org/note/id';
$like->save();
$id = $like->id;
@ -186,7 +186,7 @@ class LikesTest extends TestCase
$this->app->bind(Client::class, function () use ($client) {
return $client;
});
$authorship = new Authorship();
$authorship = new Authorship;
$job->handle($client, $authorship);
@ -196,7 +196,7 @@ class LikesTest extends TestCase
/** @test */
public function likeThatIsATweet(): void
{
$like = new Like();
$like = new Like;
$like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200';
$like->save();
$id = $like->id;
@ -226,7 +226,7 @@ class LikesTest extends TestCase
->willReturn($info);
$this->app->instance(Codebird::class, $codebirdMock);
$authorship = new Authorship();
$authorship = new Authorship;
$job->handle($client, $authorship);
@ -236,7 +236,7 @@ class LikesTest extends TestCase
/** @test */
public function noErrorForFailureToPosseWithBridgy(): void
{
$like = new Like();
$like = new Like;
$like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200';
$like->save();
$id = $like->id;
@ -264,7 +264,7 @@ class LikesTest extends TestCase
->willReturn($info);
$this->app->instance(Codebird::class, $codebirdMock);
$authorship = new Authorship();
$authorship = new Authorship;
$job->handle($client, $authorship);

View file

@ -291,7 +291,7 @@ class MicropubControllerTest extends TestCase
*/
public function micropubClientApiRequestCreatesNewNoteWithExistingPlaceInLocationData(): void
{
$place = new Place();
$place = new Place;
$place->name = 'Test Place';
$place->latitude = 1.23;
$place->longitude = 4.56;

View file

@ -10,6 +10,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Tests\TestCase;
use Tests\TestToken;
@ -22,9 +23,7 @@ class MicropubMediaTest extends TestCase
public function emptyResponseForLastUploadWhenNoneFound(): void
{
// Make sure theres no media
Media::all()->each(function ($media) {
$media->delete();
});
$this->assertCount(0, Media::all());
$response = $this->get(
'/api/media?q=last',
@ -82,10 +81,8 @@ class MicropubMediaTest extends TestCase
public function clientCanListLastUpload(): void
{
Queue::fake();
Storage::fake('s3');
$file = __DIR__ . '/../aaron.png';
$token = $this->getToken();
config(['filesystems.disks.s3.url' => 'https://s3.example.com']);
$response = $this->post(
'/api/media',
@ -95,12 +92,8 @@ class MicropubMediaTest extends TestCase
['HTTP_Authorization' => 'Bearer ' . $token]
);
$location = $response->headers->get('Location');
$this->assertStringStartsWith('https://s3.example.com/', $location);
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
$filename = substr($path, 7);
$filename = Str::chopStart($path, '/media/');
$lastUploadResponse = $this->get(
'/api/media?q=last',
@ -109,14 +102,14 @@ class MicropubMediaTest extends TestCase
$lastUploadResponse->assertJson(['url' => $response->headers->get('Location')]);
// now remove file
unlink(storage_path('app/') . $filename);
unlink(storage_path('app/media/') . $filename);
$this->removeDirIfEmpty(storage_path('app/media'));
}
/** @test */
public function clientCanSourceUploads(): void
{
Queue::fake();
Storage::fake('s3');
$file = __DIR__ . '/../aaron.png';
$token = $this->getToken();
@ -129,7 +122,7 @@ class MicropubMediaTest extends TestCase
);
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
$filename = substr($path, 7);
$filename = Str::chopStart($path, '/media/');
$sourceUploadResponse = $this->get(
'/api/media?q=source',
@ -141,14 +134,14 @@ class MicropubMediaTest extends TestCase
]]]);
// now remove file
unlink(storage_path('app/') . $filename);
unlink(storage_path('app/media/') . $filename);
$this->removeDirIfEmpty(storage_path('app/media'));
}
/** @test */
public function clientCanSourceUploadsWithLimit(): void
{
Queue::fake();
Storage::fake('s3');
$file = __DIR__ . '/../aaron.png';
$token = $this->getToken();
@ -161,7 +154,7 @@ class MicropubMediaTest extends TestCase
);
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
$filename = substr($path, 7);
$filename = Str::chopStart($path, '/media/');
$sourceUploadResponse = $this->get(
'/api/media?q=source&limit=1',
@ -175,7 +168,8 @@ class MicropubMediaTest extends TestCase
$this->assertCount(1, json_decode($sourceUploadResponse->getContent(), true)['items']);
// now remove file
unlink(storage_path('app/') . $filename);
unlink(storage_path('app/media/') . $filename);
$this->removeDirIfEmpty(storage_path('app/media'));
}
/** @test */
@ -256,7 +250,6 @@ class MicropubMediaTest extends TestCase
public function mediaEndpointUploadFile(): void
{
Queue::fake();
Storage::fake('s3');
$file = __DIR__ . '/../aaron.png';
$response = $this->post(
@ -268,18 +261,18 @@ class MicropubMediaTest extends TestCase
);
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
$filename = substr($path, 7);
$filename = Str::chopStart($path, '/media/');
Queue::assertPushed(ProcessMedia::class);
Storage::disk('local')->assertExists($filename);
Storage::disk('local')->assertExists($path);
// now remove file
unlink(storage_path('app/') . $filename);
unlink(storage_path('app/media/') . $filename);
$this->removeDirIfEmpty(storage_path('app/media'));
}
/** @test */
public function mediaEndpointUploadAudioFile(): void
{
Queue::fake();
Storage::fake('s3');
$file = __DIR__ . '/../audio.mp3';
$response = $this->post(
@ -291,18 +284,18 @@ class MicropubMediaTest extends TestCase
);
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
$filename = substr($path, 7);
$filename = Str::chopStart($path, '/media/');
Queue::assertPushed(ProcessMedia::class);
Storage::disk('local')->assertExists($filename);
Storage::disk('local')->assertExists($path);
// now remove file
unlink(storage_path('app/') . $filename);
unlink(storage_path('app/media/') . $filename);
$this->removeDirIfEmpty(storage_path('app/media'));
}
/** @test */
public function mediaEndpointUploadVideoFile(): void
{
Queue::fake();
Storage::fake('s3');
$file = __DIR__ . '/../video.ogv';
$response = $this->post(
@ -314,18 +307,18 @@ class MicropubMediaTest extends TestCase
);
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
$filename = substr($path, 7);
$filename = Str::chopStart($path, '/media/');
Queue::assertPushed(ProcessMedia::class);
Storage::disk('local')->assertExists($filename);
Storage::disk('local')->assertExists($path);
// now remove file
unlink(storage_path('app/') . $filename);
unlink(storage_path('app/media/') . $filename);
$this->removeDirIfEmpty(storage_path('app/media'));
}
/** @test */
public function mediaEndpointUploadDocumentFile(): void
{
Queue::fake();
Storage::fake('s3');
$response = $this->post(
'/api/media',
@ -336,11 +329,12 @@ class MicropubMediaTest extends TestCase
);
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
$filename = substr($path, 7);
$filename = Str::chopStart($path, '/media/');
Queue::assertPushed(ProcessMedia::class);
Storage::disk('local')->assertExists($filename);
Storage::disk('local')->assertExists($path);
// now remove file
unlink(storage_path('app/') . $filename);
unlink(storage_path('app/media/') . $filename);
$this->removeDirIfEmpty(storage_path('app/media'));
}
/** @test */

View file

@ -60,7 +60,7 @@ class ParseCachedWebMentionsTest extends TestCase
protected function tearDown(): void
{
$fs = new FileSystem();
$fs = new FileSystem;
if ($fs->exists(storage_path() . '/HTML/https')) {
$fs->deleteDirectory(storage_path() . '/HTML/https');
}

View file

@ -21,7 +21,7 @@ class TokenServiceTest extends TestCase
*/
public function tokenserviceCreatesAndValidatesTokens(): void
{
$tokenService = new TokenService();
$tokenService = new TokenService;
$data = [
'me' => 'https://example.org',
'client_id' => 'https://quill.p3k.io',
@ -55,7 +55,7 @@ class TokenServiceTest extends TestCase
$config = resolve(Configuration::class);
$token = $config->builder()
->issuedAt(new DateTimeImmutable())
->issuedAt(new DateTimeImmutable)
->withClaim('client_id', $data['client_id'])
->withClaim('me', $data['me'])
->withClaim('scope', $data['scope'])
@ -63,7 +63,7 @@ class TokenServiceTest extends TestCase
->getToken($config->signer(), InMemory::plainText(random_bytes(32)))
->toString();
$service = new TokenService();
$service = new TokenService;
$service->validateToken($token);
}
}

View file

@ -7,4 +7,13 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
public function removeDirIfEmpty(string $dir): void
{
// scandir() will always return `.` and `..` so even an “empty”
// directory will have a count of 2
if (is_dir($dir) && count(scandir($dir)) === 2) {
rmdir($dir);
}
}
}

View file

@ -12,7 +12,7 @@ trait TestToken
$config = $this->app->make(Configuration::class);
return $config->builder()
->issuedAt(new DateTimeImmutable())
->issuedAt(new DateTimeImmutable)
->withClaim('client_id', 'https://quill.p3k.io')
->withClaim('me', 'http://jonnybarnes.localhost')
->withClaim('scope', ['create', 'update'])
@ -25,7 +25,7 @@ trait TestToken
$config = $this->app->make(Configuration::class);
return $config->builder()
->issuedAt(new DateTimeImmutable())
->issuedAt(new DateTimeImmutable)
->withClaim('client_id', 'https://quill.p3k.io')
->withClaim('me', 'https://jonnybarnes.localhost')
->withClaim('scope', 'view')
@ -38,7 +38,7 @@ trait TestToken
$config = $this->app->make(Configuration::class);
return $config->builder()
->issuedAt(new DateTimeImmutable())
->issuedAt(new DateTimeImmutable)
->withClaim('client_id', 'https://quill.p3k.io')
->withClaim('me', 'https://jonnybarnes.localhost')
->getToken($config->signer(), $config->signingKey())

View file

@ -16,7 +16,7 @@ class ArticlesTest extends TestCase
/** @test */
public function titleSlugIsGeneratedAutomatically(): void
{
$article = new Article();
$article = new Article;
$article->title = 'My Title';
$article->main = 'Content';
$article->save();
@ -27,7 +27,7 @@ class ArticlesTest extends TestCase
/** @test */
public function markdownContentIsConverted(): void
{
$article = new Article();
$article = new Article;
$article->main = 'Some *markdown*';
$this->assertEquals('<p>Some <em>markdown</em></p>' . PHP_EOL, $article->html);

View file

@ -34,7 +34,7 @@ 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');
$url = (new BookmarkService)->getArchiveLink('https://example.org');
$this->assertEquals('/web/1234/example.org', $url);
}
@ -49,7 +49,7 @@ class BookmarksTest extends TestCase
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
(new BookmarkService())->getArchiveLink('https://example.org');
(new BookmarkService)->getArchiveLink('https://example.org');
}
/** @test */
@ -63,6 +63,6 @@ class BookmarksTest extends TestCase
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
(new BookmarkService())->getArchiveLink('https://example.org');
(new BookmarkService)->getArchiveLink('https://example.org');
}
}

View file

@ -16,7 +16,7 @@ class DownloadWebMentionJobTest extends TestCase
{
protected function tearDown(): void
{
$fs = new FileSystem();
$fs = new FileSystem;
if ($fs->exists(storage_path() . '/HTML/https')) {
$fs->deleteDirectory(storage_path() . '/HTML/https');
}

View file

@ -46,7 +46,7 @@ class ProcessBookmarkJobTest extends TestCase
$bookmark = Bookmark::factory()->create();
$service = $this->createMock(BookmarkService::class);
$service->method('getArchiveLink')
->will($this->throwException(new InternetArchiveException()));
->will($this->throwException(new InternetArchiveException));
$this->app->instance(BookmarkService::class, $service);
$job = new ProcessBookmark($bookmark);

View file

@ -14,38 +14,48 @@ class ProcessMediaJobTest extends TestCase
/** @test */
public function nonMediaFilesAreNotSaved(): void
{
Storage::fake('s3');
$manager = app()->make(ImageManager::class);
Storage::disk('local')->put('file.txt', 'This is not an image');
Storage::disk('local')->put('media/file.txt', 'This is not an image');
$job = new ProcessMedia('file.txt');
$job->handle($manager);
$this->assertFalse(file_exists(storage_path('app') . '/file.txt'));
$this->assertFileDoesNotExist(storage_path('app/media/') . 'file.txt');
}
/** @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('media/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'));
$this->assertFileDoesNotExist(storage_path('app/media/') . 'aaron.png');
// Tidy up files created by the job
Storage::disk('local')->delete('public/media/aaron.png');
Storage::disk('local')->delete('public/media');
}
/** @test */
public function largeImagesHaveSmallerImagesCreated(): void
{
$manager = app()->make(ImageManager::class);
Storage::disk('local')->put('test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));
Storage::fake('s3');
Storage::disk('local')->put('media/test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));
$job = new ProcessMedia('test-image.jpg');
$job->handle($manager);
Storage::disk('s3')->assertExists('media/test-image-small.jpg');
Storage::disk('s3')->assertExists('media/test-image-medium.jpg');
$this->assertFalse(file_exists(storage_path('app') . '/test-image.jpg'));
Storage::disk('local')->assertExists('public/media/test-image.jpg');
Storage::disk('local')->assertExists('public/media/test-image-small.jpg');
Storage::disk('local')->assertExists('public/media/test-image-medium.jpg');
$this->assertFileDoesNotExist(storage_path('app/media/') . 'test-image.jpg');
// Tidy up files created by the job
Storage::disk('local')->delete('public/media/test-image.jpg');
Storage::disk('local')->delete('public/media/test-image-small.jpg');
Storage::disk('local')->delete('public/media/test-image-medium.jpg');
$this->removeDirIfEmpty(storage_path('app/public/media'));
$this->removeDirIfEmpty(storage_path('app/media'));
}
}

View file

@ -25,7 +25,7 @@ class ProcessWebMentionJobTest extends TestCase
protected function tearDown(): void
{
$fs = new FileSystem();
$fs = new FileSystem;
if ($fs->exists(storage_path() . '/HTML/https')) {
$fs->deleteDirectory(storage_path() . '/HTML/https');
}
@ -37,7 +37,7 @@ class ProcessWebMentionJobTest extends TestCase
{
$this->expectException(RemoteContentNotFoundException::class);
$parser = new Parser();
$parser = new Parser;
$mock = new MockHandler([
new Response(404),
]);
@ -56,7 +56,7 @@ class ProcessWebMentionJobTest extends TestCase
{
Queue::fake();
$parser = new Parser();
$parser = new Parser;
$html = <<<'HTML'
<div class="h-entry">
@ -88,7 +88,7 @@ class ProcessWebMentionJobTest extends TestCase
{
Queue::fake();
$parser = new Parser();
$parser = new Parser;
$note = Note::factory()->create();
$source = 'https://aaronpk.localhost/reply/1';
WebMention::factory()->create([
@ -123,7 +123,7 @@ class ProcessWebMentionJobTest extends TestCase
/** @test */
public function webmentionReplyGetsDeletedWhenReplyToValueChanges(): void
{
$parser = new Parser();
$parser = new Parser;
$html = <<<'HTML'
<div class="h-entry">
@ -139,7 +139,7 @@ class ProcessWebMentionJobTest extends TestCase
$note = Note::factory()->create();
$source = 'https://example.org/reply/1';
$webmention = new WebMention();
$webmention = new WebMention;
$webmention->source = $source;
$webmention->target = config('app.url') . '/notes/E';
$webmention->type = 'in-reply-to';
@ -160,7 +160,7 @@ class ProcessWebMentionJobTest extends TestCase
/** @test */
public function webmentionLikeGetsDeletedWhenLikeOfValueChanges(): void
{
$parser = new Parser();
$parser = new Parser;
$html = <<<'HTML'
<div class="h-entry">
@ -176,7 +176,7 @@ class ProcessWebMentionJobTest extends TestCase
$note = Note::factory()->create();
$source = 'https://example.org/reply/1';
$webmention = new WebMention();
$webmention = new WebMention;
$webmention->source = $source;
$webmention->target = config('app.url') . '/notes/E';
$webmention->type = 'like-of';
@ -197,7 +197,7 @@ class ProcessWebMentionJobTest extends TestCase
/** @test */
public function webmentionRepostGetsDeletedWhenRepostOfValueChanges(): void
{
$parser = new Parser();
$parser = new Parser;
$html = <<<'HTML'
<div class="h-entry">
@ -213,7 +213,7 @@ class ProcessWebMentionJobTest extends TestCase
$note = Note::factory()->create();
$source = 'https://example.org/reply/1';
$webmention = new WebMention();
$webmention = new WebMention;
$webmention->source = $source;
$webmention->target = config('app.url') . '/notes/E';
$webmention->type = 'repost-of';

View file

@ -30,7 +30,7 @@ class SaveProfileImageJobTest extends TestCase
$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));

View file

@ -17,7 +17,7 @@ class SendWebMentionJobTest extends TestCase
/** @test */
public function discoverWebmentionEndpointOnOwnDomain(): void
{
$note = new Note();
$note = new Note;
$job = new SendWebMentions($note);
$this->assertNull($job->discoverWebmentionEndpoint(config('app.url')));
$this->assertNull($job->discoverWebmentionEndpoint('/notes/tagged/test'));
@ -34,7 +34,7 @@ class SendWebMentionJobTest extends TestCase
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$job = new SendWebMentions(new Note());
$job = new SendWebMentions(new Note);
$this->assertEquals($url, $job->discoverWebmentionEndpoint('https://example.org'));
}
@ -49,7 +49,7 @@ class SendWebMentionJobTest extends TestCase
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$job = new SendWebMentions(new Note());
$job = new SendWebMentions(new Note);
$this->assertEquals(
'https://example.org/webmention',
$job->discoverWebmentionEndpoint('https://example.org')
@ -67,7 +67,7 @@ class SendWebMentionJobTest extends TestCase
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$job = new SendWebMentions(new Note());
$job = new SendWebMentions(new Note);
$this->assertEquals(
'https://example.org/webmention',
$job->discoverWebmentionEndpoint('https://example.org')
@ -77,7 +77,7 @@ class SendWebMentionJobTest extends TestCase
/** @test */
public function ensureEmptyNoteDoesNotTriggerAnyActions(): void
{
$job = new SendWebMentions(new Note());
$job = new SendWebMentions(new Note);
$this->assertNull($job->handle());
}
@ -86,7 +86,7 @@ class SendWebMentionJobTest extends TestCase
{
$uri = '/blog/post';
$base = 'https://example.org/';
$job = new SendWebMentions(new Note());
$job = new SendWebMentions(new Note);
$this->assertEquals('https://example.org/blog/post', $job->resolveUri($uri, $base));
}
@ -102,7 +102,7 @@ class SendWebMentionJobTest extends TestCase
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$note = new Note();
$note = new Note;
$note->note = 'Hi [Aaron](https://aaronparecki.com)';
$note->save();
$job = new SendWebMentions($note);
@ -121,7 +121,7 @@ class SendWebMentionJobTest extends TestCase
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$job = new SendWebMentions(new Note());
$job = new SendWebMentions(new Note);
$this->assertNull($job->discoverWebmentionEndpoint('https://example.org'));
}
}

View file

@ -15,7 +15,7 @@ class LikesTest extends TestCase
/** @test */
public function weCanSetTheAuthorUrl(): void
{
$like = new Like();
$like = new Like;
$like->author_url = 'https://joe.bloggs/';
$this->assertEquals('https://joe.bloggs', $like->author_url);
}
@ -23,7 +23,7 @@ class LikesTest extends TestCase
/** @test */
public function weDoNotModifyPlainTextContent(): void
{
$like = new Like();
$like = new Like;
$like->url = 'https://example.org/post/123';
$like->content = 'some plaintext content';
$like->save();
@ -34,7 +34,7 @@ class LikesTest extends TestCase
/** @test */
public function weCanHandleBlankContent(): void
{
$like = new Like();
$like = new Like;
$like->url = 'https://example.org/post/123';
$like->content = null;
$like->save();
@ -57,7 +57,7 @@ class LikesTest extends TestCase
<p>Hello</p>
<img />
HTML;
$like = new Like();
$like = new Like;
$like->url = 'https://example.org/post/123';
$like->content = $htmlEvil;
$like->save();

View file

@ -25,7 +25,7 @@ class MediaTest extends TestCase
public function absoluteUrlsAreReturnedUnmodified(): void
{
$absoluteUrl = 'https://instagram-cdn.com/image/uuid';
$media = new Media();
$media = new Media;
$media->path = $absoluteUrl;
$this->assertEquals($absoluteUrl, $media->url);

View file

@ -82,7 +82,7 @@ class NotesTest extends TestCase
'twitter' => null,
'facebook' => 123456,
]);
$fileSystem = new Filesystem();
$fileSystem = new Filesystem;
$fileSystem->ensureDirectoryExists(public_path('/assets/profile-images/aaronparecki.com'));
if (! $fileSystem->exists(public_path('/assets/profile-images/aaronparecki.com/image'))) {
$fileSystem->copy('./tests/aaron.png', public_path('/assets/profile-images/aaronparecki.com/image'));
@ -201,7 +201,7 @@ class NotesTest extends TestCase
$this->app->instance(Client::class, $client);
$note = new Note();
$note = new Note;
$address = $note->reverseGeoCode(51.50084, -0.14264);
$this->assertEquals(
@ -226,7 +226,7 @@ class NotesTest extends TestCase
$this->app->instance(Client::class, $client);
$note = new Note();
$note = new Note;
$address = $note->reverseGeoCode(51.02, 0.91);
$this->assertEquals(
@ -253,7 +253,7 @@ class NotesTest extends TestCase
$this->app->instance(Client::class, $client);
$note = new Note();
$note = new Note;
$address = $note->reverseGeoCode(53.466277988406, -2.2304474827445);
$this->assertEquals(
@ -280,7 +280,7 @@ class NotesTest extends TestCase
$this->app->instance(Client::class, $client);
$note = new Note();
$note = new Note;
$address = $note->reverseGeoCode(51.1, 0.61);
$this->assertEquals('<span class="p-region">Kent</span>, <span class="p-country-name">UK</span>', $address);
@ -304,7 +304,7 @@ class NotesTest extends TestCase
$this->app->instance(Client::class, $client);
$note = new Note();
$note = new Note;
$address = $note->reverseGeoCode(54.3, 9.4);
$this->assertEquals('<span class="p-country-name">Ireland</span>', $address);
@ -323,7 +323,7 @@ class NotesTest extends TestCase
$note->media()->save($media);
$expected = 'A nice image
<img src="' . config('filesystems.disks.s3.url') . '/test.png" alt="">';
<img src="' . config('app.url') . '/test.png" alt="">';
$this->assertEquals($expected, $note->content);
}
@ -340,7 +340,7 @@ class NotesTest extends TestCase
$note->media()->save($media);
$expected = 'A nice video
<video src="' . config('filesystems.disks.s3.url') . '/test.mkv">';
<video src="' . config('app.url') . '/test.mkv">';
$this->assertEquals($expected, $note->content);
}
@ -357,7 +357,7 @@ class NotesTest extends TestCase
$note->media()->save($media);
$expected = 'Some nice audio
<audio src="' . config('filesystems.disks.s3.url') . '/test.flac">';
<audio src="' . config('app.url') . '/test.flac">';
$this->assertEquals($expected, $note->content);
}
@ -368,7 +368,7 @@ class NotesTest extends TestCase
*/
public function provideTextForBlankContent(): void
{
$note = new Note();
$note = new Note;
$this->assertEquals('A blank note', $note->content);
}

View file

@ -71,13 +71,13 @@ class PlacesTest extends TestCase
{
Place::factory(10)->create();
$place = new Place();
$place = new Place;
$place->name = 'Temp Place';
$place->latitude = 37.422009;
$place->longitude = -122.084047;
$place->external_urls = 'https://www.openstreetmap.org/way/1234';
$place->save();
$service = new PlaceService();
$service = new PlaceService;
$ret = $service->createPlaceFromCheckin([
'properties' => [
'url' => ['https://www.openstreetmap.org/way/1234'],
@ -92,7 +92,7 @@ class PlacesTest extends TestCase
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Missing required name');
$service = new PlaceService();
$service = new PlaceService;
$service->createPlaceFromCheckin(['foo' => 'bar']);
}
@ -102,7 +102,7 @@ class PlacesTest extends TestCase
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Missing required longitude/latitude');
$service = new PlaceService();
$service = new PlaceService;
$service->createPlaceFromCheckin(['properties' => ['name' => 'bar']]);
}

View file

@ -30,7 +30,7 @@ class WebMentionTest extends TestCase
/** @test */
public function publishedAttributeUsesUpdatedAtWhenNoRelevantMf2Data(): void
{
$webmention = new WebMention();
$webmention = new WebMention;
$updated_at = Carbon::now();
$webmention->updated_at = $updated_at;
$this->assertEquals($updated_at->toDayDateTimeString(), $webmention->published);
@ -39,7 +39,7 @@ class WebMentionTest extends TestCase
/** @test */
public function publishedAttributeUsesUpdatedAtWhenErrorParsingMf2Data(): void
{
$webmention = new WebMention();
$webmention = new WebMention;
$updated_at = Carbon::now();
$webmention->updated_at = $updated_at;
$webmention->mf2 = json_encode([
@ -57,7 +57,7 @@ class WebMentionTest extends TestCase
/** @test */
public function createPhotoLinkDoesNothingWithGenericUrlAndNoLocallySavedImage(): void
{
$webmention = new WebMention();
$webmention = new WebMention;
$homepage = 'https://example.org/profile.png';
$expected = 'https://example.org/profile.png';
$this->assertEquals($expected, $webmention->createPhotoLink($homepage));
@ -66,7 +66,7 @@ class WebMentionTest extends TestCase
/** @test */
public function createPhotoLinkReturnsLocallySavedImageUrlIfItExists(): void
{
$webmention = new WebMention();
$webmention = new WebMention;
$homepage = 'https://aaronparecki.com/profile.png';
$expected = '/assets/profile-images/aaronparecki.com/image';
$this->assertEquals($expected, $webmention->createPhotoLink($homepage));
@ -75,7 +75,7 @@ class WebMentionTest extends TestCase
/** @test */
public function createPhotoLinkDealsWithSpecialCaseOfDirectTwitterPhotoLinks(): void
{
$webmention = new WebMention();
$webmention = new WebMention;
$twitterProfileImage = 'http://pbs.twimg.com/1234';
$expected = 'https://pbs.twimg.com/1234';
$this->assertEquals($expected, $webmention->createPhotoLink($twitterProfileImage));
@ -84,7 +84,7 @@ class WebMentionTest extends TestCase
/** @test */
public function createPhotoLinkReturnsCachedTwitterPhotoLinks(): void
{
$webmention = new WebMention();
$webmention = new WebMention;
$twitterURL = 'https://twitter.com/example';
$expected = 'https://pbs.twimg.com/static_profile_link.jpg';
Cache::put($twitterURL, $expected, 1);
@ -111,7 +111,7 @@ class WebMentionTest extends TestCase
->once()
->andReturn(true);
$webmention = new WebMention();
$webmention = new WebMention;
$twitterURL = 'https://twitter.com/example';
$expected = 'https://pbs.twimg.com/static_profile_link.jpg';
$this->assertEquals($expected, $webmention->createPhotoLink($twitterURL));
@ -120,14 +120,14 @@ class WebMentionTest extends TestCase
/** @test */
public function getReplyAttributeDefaultsToNull(): void
{
$webmention = new WebMention();
$webmention = new WebMention;
$this->assertNull($webmention->reply);
}
/** @test */
public function getReplyAttributeWithMf2WithoutHtmlReturnsNull(): void
{
$webmention = new WebMention();
$webmention = new WebMention;
$webmention->mf2 = json_encode(['no_html' => 'found_here']);
$this->assertNull($webmention->reply);
}