MTM Host images locally #12
47 changed files with 295 additions and 214 deletions
Host images locally
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.
commit
d7da42b626
69
app/Console/Commands/CopyMediaToLocal.php
Normal file
69
app/Console/Commands/CopyMediaToLocal.php
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Media;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
class CopyMediaToLocal extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'app:copy-media-to-local';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Copy any historic media saved to S3 to the local filesystem';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
// Load all the Media records
|
||||||
|
$media = Media::all();
|
||||||
|
|
||||||
|
// Loop through each media record and copy the file from S3 to the local filesystem
|
||||||
|
foreach ($media as $mediaItem) {
|
||||||
|
$filename = $mediaItem->path;
|
||||||
|
|
||||||
|
$this->info('Processing: ' . $filename);
|
||||||
|
|
||||||
|
// If the file is already saved locally skip to next one
|
||||||
|
if (Storage::disk('local')->exists('public/' . $filename)) {
|
||||||
|
$this->info('File already exists locally, skipping');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the file from S3 to the local filesystem
|
||||||
|
if (! Storage::disk('s3')->exists($filename)) {
|
||||||
|
$this->error('File does not exist on S3');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$contents = Storage::disk('s3')->get($filename);
|
||||||
|
Storage::disk('local')->put('public/' . $filename, $contents);
|
||||||
|
|
||||||
|
// Copy -medium and -small versions if they exist
|
||||||
|
$filenameParts = explode('.', $filename);
|
||||||
|
$extension = array_pop($filenameParts);
|
||||||
|
$basename = trim(implode('.', $filenameParts), '.');
|
||||||
|
$mediumFilename = $basename . '-medium.' . $extension;
|
||||||
|
$smallFilename = $basename . '-small.' . $extension;
|
||||||
|
if (Storage::disk('s3')->exists($mediumFilename)) {
|
||||||
|
Storage::disk('local')->put('public/' . $mediumFilename, Storage::disk('s3')->get($mediumFilename));
|
||||||
|
}
|
||||||
|
if (Storage::disk('s3')->exists($smallFilename)) {
|
||||||
|
Storage::disk('local')->put('public/' . $smallFilename, Storage::disk('s3')->get($smallFilename));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -40,7 +40,7 @@ class ContactsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function store(): RedirectResponse
|
public function store(): RedirectResponse
|
||||||
{
|
{
|
||||||
$contact = new Contact();
|
$contact = new Contact;
|
||||||
$contact->name = request()->input('name');
|
$contact->name = request()->input('name');
|
||||||
$contact->nick = request()->input('nick');
|
$contact->nick = request()->input('nick');
|
||||||
$contact->homepage = request()->input('homepage');
|
$contact->homepage = request()->input('homepage');
|
||||||
|
|
@ -79,7 +79,7 @@ class ContactsController extends Controller
|
||||||
if (request()->hasFile('avatar') && (request()->input('homepage') != '')) {
|
if (request()->hasFile('avatar') && (request()->input('homepage') != '')) {
|
||||||
$dir = parse_url(request()->input('homepage'), PHP_URL_HOST);
|
$dir = parse_url(request()->input('homepage'), PHP_URL_HOST);
|
||||||
$destination = public_path() . '/assets/profile-images/' . $dir;
|
$destination = public_path() . '/assets/profile-images/' . $dir;
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem;
|
||||||
if ($filesystem->isDirectory($destination) === false) {
|
if ($filesystem->isDirectory($destination) === false) {
|
||||||
$filesystem->makeDirectory($destination);
|
$filesystem->makeDirectory($destination);
|
||||||
}
|
}
|
||||||
|
|
@ -139,7 +139,7 @@ class ContactsController extends Controller
|
||||||
}
|
}
|
||||||
if ($avatar !== null) {
|
if ($avatar !== null) {
|
||||||
$directory = public_path() . '/assets/profile-images/' . parse_url($contact->homepage, PHP_URL_HOST);
|
$directory = public_path() . '/assets/profile-images/' . parse_url($contact->homepage, PHP_URL_HOST);
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem;
|
||||||
if ($filesystem->isDirectory($directory) === false) {
|
if ($filesystem->isDirectory($directory) === false) {
|
||||||
$filesystem->makeDirectory($directory);
|
$filesystem->makeDirectory($directory);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,8 +116,8 @@ class PasskeysController extends Controller
|
||||||
throw new WebAuthnException('No public key credential request options found');
|
throw new WebAuthnException('No public key credential request options found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$attestationStatementSupportManager = new AttestationStatementSupportManager();
|
$attestationStatementSupportManager = new AttestationStatementSupportManager;
|
||||||
$attestationStatementSupportManager->add(new NoneAttestationStatementSupport());
|
$attestationStatementSupportManager->add(new NoneAttestationStatementSupport);
|
||||||
|
|
||||||
$webauthnSerializer = (new WebauthnSerializerFactory(
|
$webauthnSerializer = (new WebauthnSerializerFactory(
|
||||||
$attestationStatementSupportManager
|
$attestationStatementSupportManager
|
||||||
|
|
@ -133,12 +133,12 @@ class PasskeysController extends Controller
|
||||||
throw new WebAuthnException('Invalid response type');
|
throw new WebAuthnException('Invalid response type');
|
||||||
}
|
}
|
||||||
|
|
||||||
$algorithmManager = new Manager();
|
$algorithmManager = new Manager;
|
||||||
$algorithmManager->add(new Ed25519());
|
$algorithmManager->add(new Ed25519);
|
||||||
$algorithmManager->add(new ES256());
|
$algorithmManager->add(new ES256);
|
||||||
$algorithmManager->add(new RS256());
|
$algorithmManager->add(new RS256);
|
||||||
|
|
||||||
$ceremonyStepManagerFactory = new CeremonyStepManagerFactory();
|
$ceremonyStepManagerFactory = new CeremonyStepManagerFactory;
|
||||||
$ceremonyStepManagerFactory->setAlgorithmManager($algorithmManager);
|
$ceremonyStepManagerFactory->setAlgorithmManager($algorithmManager);
|
||||||
$ceremonyStepManagerFactory->setAttestationStatementSupportManager(
|
$ceremonyStepManagerFactory->setAttestationStatementSupportManager(
|
||||||
$attestationStatementSupportManager
|
$attestationStatementSupportManager
|
||||||
|
|
@ -206,8 +206,8 @@ class PasskeysController extends Controller
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$attestationStatementSupportManager = new AttestationStatementSupportManager();
|
$attestationStatementSupportManager = new AttestationStatementSupportManager;
|
||||||
$attestationStatementSupportManager->add(new NoneAttestationStatementSupport());
|
$attestationStatementSupportManager->add(new NoneAttestationStatementSupport);
|
||||||
|
|
||||||
$webauthnSerializer = (new WebauthnSerializerFactory(
|
$webauthnSerializer = (new WebauthnSerializerFactory(
|
||||||
$attestationStatementSupportManager
|
$attestationStatementSupportManager
|
||||||
|
|
@ -240,15 +240,15 @@ class PasskeysController extends Controller
|
||||||
'json'
|
'json'
|
||||||
);
|
);
|
||||||
|
|
||||||
$algorithmManager = new Manager();
|
$algorithmManager = new Manager;
|
||||||
$algorithmManager->add(new Ed25519());
|
$algorithmManager->add(new Ed25519);
|
||||||
$algorithmManager->add(new ES256());
|
$algorithmManager->add(new ES256);
|
||||||
$algorithmManager->add(new RS256());
|
$algorithmManager->add(new RS256);
|
||||||
|
|
||||||
$attestationStatementSupportManager = new AttestationStatementSupportManager();
|
$attestationStatementSupportManager = new AttestationStatementSupportManager;
|
||||||
$attestationStatementSupportManager->add(new NoneAttestationStatementSupport());
|
$attestationStatementSupportManager->add(new NoneAttestationStatementSupport);
|
||||||
|
|
||||||
$ceremonyStepManagerFactory = new CeremonyStepManagerFactory();
|
$ceremonyStepManagerFactory = new CeremonyStepManagerFactory;
|
||||||
$ceremonyStepManagerFactory->setAlgorithmManager($algorithmManager);
|
$ceremonyStepManagerFactory->setAlgorithmManager($algorithmManager);
|
||||||
$ceremonyStepManagerFactory->setAttestationStatementSupportManager(
|
$ceremonyStepManagerFactory->setAttestationStatementSupportManager(
|
||||||
$attestationStatementSupportManager
|
$attestationStatementSupportManager
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class ContactsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function index(): View
|
public function index(): View
|
||||||
{
|
{
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem;
|
||||||
$contacts = Contact::all();
|
$contacts = Contact::all();
|
||||||
foreach ($contacts as $contact) {
|
foreach ($contacts as $contact) {
|
||||||
$contact->homepageHost = parse_url($contact->homepage, PHP_URL_HOST);
|
$contact->homepageHost = parse_url($contact->homepage, PHP_URL_HOST);
|
||||||
|
|
@ -40,7 +40,7 @@ class ContactsController extends Controller
|
||||||
$contact->homepageHost = parse_url($contact->homepage, PHP_URL_HOST);
|
$contact->homepageHost = parse_url($contact->homepage, PHP_URL_HOST);
|
||||||
$file = public_path() . '/assets/profile-images/' . $contact->homepageHost . '/image';
|
$file = public_path() . '/assets/profile-images/' . $contact->homepageHost . '/image';
|
||||||
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem;
|
||||||
$image = ($filesystem->exists($file)) ?
|
$image = ($filesystem->exists($file)) ?
|
||||||
'/assets/profile-images/' . $contact->homepageHost . '/image'
|
'/assets/profile-images/' . $contact->homepageHost . '/image'
|
||||||
:
|
:
|
||||||
|
|
|
||||||
|
|
@ -53,13 +53,13 @@ class MicropubController extends Controller
|
||||||
try {
|
try {
|
||||||
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
|
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
|
||||||
} catch (RequiredConstraintsViolated|InvalidTokenStructure|CannotDecodeContent) {
|
} catch (RequiredConstraintsViolated|InvalidTokenStructure|CannotDecodeContent) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->invalidTokenResponse();
|
return $micropubResponses->invalidTokenResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($tokenData->claims()->has('scope') === false) {
|
if ($tokenData->claims()->has('scope') === false) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->tokenHasNoScopeResponse();
|
return $micropubResponses->tokenHasNoScopeResponse();
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +73,7 @@ class MicropubController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! in_array('create', $scopes)) {
|
if (! in_array('create', $scopes)) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->insufficientScopeResponse();
|
return $micropubResponses->insufficientScopeResponse();
|
||||||
}
|
}
|
||||||
|
|
@ -91,7 +91,7 @@ class MicropubController extends Controller
|
||||||
$scopes = explode(' ', $scopes);
|
$scopes = explode(' ', $scopes);
|
||||||
}
|
}
|
||||||
if (! in_array('create', $scopes)) {
|
if (! in_array('create', $scopes)) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->insufficientScopeResponse();
|
return $micropubResponses->insufficientScopeResponse();
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ class MicropubController extends Controller
|
||||||
$scopes = explode(' ', $scopes);
|
$scopes = explode(' ', $scopes);
|
||||||
}
|
}
|
||||||
if (! in_array('update', $scopes)) {
|
if (! in_array('update', $scopes)) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->insufficientScopeResponse();
|
return $micropubResponses->insufficientScopeResponse();
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +136,7 @@ class MicropubController extends Controller
|
||||||
try {
|
try {
|
||||||
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
|
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
|
||||||
} catch (RequiredConstraintsViolated|InvalidTokenStructure) {
|
} catch (RequiredConstraintsViolated|InvalidTokenStructure) {
|
||||||
return (new MicropubResponses())->invalidTokenResponse();
|
return (new MicropubResponses)->invalidTokenResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->input('q') === 'syndicate-to') {
|
if ($request->input('q') === 'syndicate-to') {
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,13 @@ class MicropubMediaController extends Controller
|
||||||
try {
|
try {
|
||||||
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
|
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
|
||||||
} catch (RequiredConstraintsViolated|InvalidTokenStructure) {
|
} catch (RequiredConstraintsViolated|InvalidTokenStructure) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->invalidTokenResponse();
|
return $micropubResponses->invalidTokenResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($tokenData->claims()->has('scope') === false) {
|
if ($tokenData->claims()->has('scope') === false) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->tokenHasNoScopeResponse();
|
return $micropubResponses->tokenHasNoScopeResponse();
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +55,7 @@ class MicropubMediaController extends Controller
|
||||||
$scopes = explode(' ', $scopes);
|
$scopes = explode(' ', $scopes);
|
||||||
}
|
}
|
||||||
if (! in_array('create', $scopes)) {
|
if (! in_array('create', $scopes)) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->insufficientScopeResponse();
|
return $micropubResponses->insufficientScopeResponse();
|
||||||
}
|
}
|
||||||
|
|
@ -111,13 +111,13 @@ class MicropubMediaController extends Controller
|
||||||
try {
|
try {
|
||||||
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
|
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
|
||||||
} catch (RequiredConstraintsViolated|InvalidTokenStructure) {
|
} catch (RequiredConstraintsViolated|InvalidTokenStructure) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->invalidTokenResponse();
|
return $micropubResponses->invalidTokenResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($tokenData->claims()->has('scope') === false) {
|
if ($tokenData->claims()->has('scope') === false) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->tokenHasNoScopeResponse();
|
return $micropubResponses->tokenHasNoScopeResponse();
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +127,7 @@ class MicropubMediaController extends Controller
|
||||||
$scopes = explode(' ', $scopes);
|
$scopes = explode(' ', $scopes);
|
||||||
}
|
}
|
||||||
if (! in_array('create', $scopes)) {
|
if (! in_array('create', $scopes)) {
|
||||||
$micropubResponses = new MicropubResponses();
|
$micropubResponses = new MicropubResponses;
|
||||||
|
|
||||||
return $micropubResponses->insufficientScopeResponse();
|
return $micropubResponses->insufficientScopeResponse();
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +140,10 @@ class MicropubMediaController extends Controller
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->file('file')->isValid() === false) {
|
/** @var UploadedFile $file */
|
||||||
|
$file = $request->file('file');
|
||||||
|
|
||||||
|
if ($file->isValid() === false) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'response' => 'error',
|
'response' => 'error',
|
||||||
'error' => 'invalid_request',
|
'error' => 'invalid_request',
|
||||||
|
|
@ -148,7 +151,7 @@ class MicropubMediaController extends Controller
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = $this->saveFile($request->file('file'));
|
$filename = Storage::disk('local')->putFile('media', $file);
|
||||||
|
|
||||||
/** @var ImageManager $manager */
|
/** @var ImageManager $manager */
|
||||||
$manager = resolve(ImageManager::class);
|
$manager = resolve(ImageManager::class);
|
||||||
|
|
@ -162,18 +165,11 @@ class MicropubMediaController extends Controller
|
||||||
|
|
||||||
$media = Media::create([
|
$media = Media::create([
|
||||||
'token' => $request->bearerToken(),
|
'token' => $request->bearerToken(),
|
||||||
'path' => 'media/' . $filename,
|
'path' => $filename,
|
||||||
'type' => $this->getFileTypeFromMimeType($request->file('file')->getMimeType()),
|
'type' => $this->getFileTypeFromMimeType($request->file('file')->getMimeType()),
|
||||||
'image_widths' => $width,
|
'image_widths' => $width,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// put the file on S3 initially, the ProcessMedia job may edit this
|
|
||||||
Storage::disk('s3')->putFileAs(
|
|
||||||
'media',
|
|
||||||
new File(storage_path('app') . '/' . $filename),
|
|
||||||
$filename
|
|
||||||
);
|
|
||||||
|
|
||||||
ProcessMedia::dispatch($filename);
|
ProcessMedia::dispatch($filename);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
|
@ -237,7 +233,7 @@ class MicropubMediaController extends Controller
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function saveFile(UploadedFile $file): string
|
private function saveFileToLocal(UploadedFile $file): string
|
||||||
{
|
{
|
||||||
$filename = Uuid::uuid4()->toString() . '.' . $file->extension();
|
$filename = Uuid::uuid4()->toString() . '.' . $file->extension();
|
||||||
Storage::disk('local')->putFileAs('', $file, $filename);
|
Storage::disk('local')->putFileAs('', $file, $filename);
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ class NotesController extends Controller
|
||||||
*/
|
*/
|
||||||
public function redirect(int $decId): RedirectResponse
|
public function redirect(int $decId): RedirectResponse
|
||||||
{
|
{
|
||||||
return redirect(config('app.url') . '/notes/' . (new Numbers())->numto60($decId));
|
return redirect(config('app.url') . '/notes/' . (new Numbers)->numto60($decId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ class DownloadWebMention implements ShouldQueue
|
||||||
//4XX and 5XX responses should get Guzzle to throw an exception,
|
//4XX and 5XX responses should get Guzzle to throw an exception,
|
||||||
//Laravel should catch and retry these automatically.
|
//Laravel should catch and retry these automatically.
|
||||||
if ($response->getStatusCode() === 200) {
|
if ($response->getStatusCode() === 200) {
|
||||||
$filesystem = new FileSystem();
|
$filesystem = new FileSystem;
|
||||||
$filename = storage_path('HTML') . '/' . $this->createFilenameFromURL($this->source);
|
$filename = storage_path('HTML') . '/' . $this->createFilenameFromURL($this->source);
|
||||||
//backup file first
|
//backup file first
|
||||||
$filenameBackup = $filename . '.' . date('Y-m-d') . '.backup';
|
$filenameBackup = $filename . '.' . date('Y-m-d') . '.backup';
|
||||||
|
|
|
||||||
|
|
@ -32,35 +32,35 @@ class ProcessMedia implements ShouldQueue
|
||||||
*/
|
*/
|
||||||
public function handle(ImageManager $manager): void
|
public function handle(ImageManager $manager): void
|
||||||
{
|
{
|
||||||
//open file
|
// Open file
|
||||||
try {
|
try {
|
||||||
$image = $manager->read(storage_path('app') . '/' . $this->filename);
|
$image = $manager->read(storage_path('app/media/') . $this->filename);
|
||||||
} catch (DecoderException) {
|
} catch (DecoderException) {
|
||||||
// not an image; delete file and end job
|
// not an image; delete file and end job
|
||||||
unlink(storage_path('app') . '/' . $this->filename);
|
unlink(storage_path('app/media/') . $this->filename);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//create smaller versions if necessary
|
|
||||||
|
// Save the file publicly
|
||||||
|
Storage::disk('local')->copy('media/' . $this->filename, 'public/media/' . $this->filename);
|
||||||
|
|
||||||
|
// Create smaller versions if necessary
|
||||||
if ($image->width() > 1000) {
|
if ($image->width() > 1000) {
|
||||||
$filenameParts = explode('.', $this->filename);
|
$filenameParts = explode('.', $this->filename);
|
||||||
$extension = array_pop($filenameParts);
|
$extension = array_pop($filenameParts);
|
||||||
// the following achieves this data flow
|
// the following achieves this data flow
|
||||||
// foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar
|
// foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar
|
||||||
$basename = ltrim(array_reduce($filenameParts, function ($carry, $item) {
|
$basename = trim(implode('.', $filenameParts), '.');
|
||||||
return $carry . '.' . $item;
|
|
||||||
}, ''), '.');
|
$medium = $image->resize(width: 1000);
|
||||||
$medium = $image->resize(1000, null, function ($constraint) {
|
Storage::disk('local')->put('public/media/' . $basename . '-medium.' . $extension, (string) $medium->encode());
|
||||||
$constraint->aspectRatio();
|
|
||||||
});
|
$small = $image->resize(width: 500);
|
||||||
Storage::disk('s3')->put('media/' . $basename . '-medium.' . $extension, (string) $medium->encode());
|
Storage::disk('local')->put('public/media/' . $basename . '-small.' . $extension, (string) $small->encode());
|
||||||
$small = $image->resize(500, null, function ($constraint) {
|
|
||||||
$constraint->aspectRatio();
|
|
||||||
});
|
|
||||||
Storage::disk('s3')->put('media/' . $basename . '-small.' . $extension, (string) $small->encode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// now we can delete the locally saved image
|
// Now we can delete the locally saved image
|
||||||
unlink(storage_path('app') . '/' . $this->filename);
|
unlink(storage_path('app/media/') . $this->filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class ProcessWebMention implements ShouldQueue
|
||||||
try {
|
try {
|
||||||
$response = $guzzle->request('GET', $this->source);
|
$response = $guzzle->request('GET', $this->source);
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
throw new RemoteContentNotFoundException();
|
throw new RemoteContentNotFoundException;
|
||||||
}
|
}
|
||||||
$this->saveRemoteContent((string) $response->getBody(), $this->source);
|
$this->saveRemoteContent((string) $response->getBody(), $this->source);
|
||||||
$microformats = Mf2\parse((string) $response->getBody(), $this->source);
|
$microformats = Mf2\parse((string) $response->getBody(), $this->source);
|
||||||
|
|
@ -85,7 +85,7 @@ class ProcessWebMention implements ShouldQueue
|
||||||
}// foreach
|
}// foreach
|
||||||
|
|
||||||
// no webmention in the db so create new one
|
// no webmention in the db so create new one
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$type = $parser->getMentionType($microformats); // throw error here?
|
$type = $parser->getMentionType($microformats); // throw error here?
|
||||||
dispatch(new SaveProfileImage($microformats));
|
dispatch(new SaveProfileImage($microformats));
|
||||||
$webmention->source = $this->source;
|
$webmention->source = $this->source;
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ class SendWebMentions implements ShouldQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
$urls = [];
|
$urls = [];
|
||||||
$dom = new \DOMDocument();
|
$dom = new \DOMDocument;
|
||||||
$dom->loadHTML($html);
|
$dom->loadHTML($html);
|
||||||
$anchors = $dom->getElementsByTagName('a');
|
$anchors = $dom->getElementsByTagName('a');
|
||||||
foreach ($anchors as $anchor) {
|
foreach ($anchors as $anchor) {
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,10 @@ class Article extends Model
|
||||||
{
|
{
|
||||||
return Attribute::get(
|
return Attribute::get(
|
||||||
get: function () {
|
get: function () {
|
||||||
$environment = new Environment();
|
$environment = new Environment;
|
||||||
$environment->addExtension(new CommonMarkCoreExtension());
|
$environment->addExtension(new CommonMarkCoreExtension);
|
||||||
$environment->addRenderer(FencedCode::class, new FencedCodeRenderer());
|
$environment->addRenderer(FencedCode::class, new FencedCodeRenderer);
|
||||||
$environment->addRenderer(IndentedCode::class, new IndentedCodeRenderer());
|
$environment->addRenderer(IndentedCode::class, new IndentedCodeRenderer);
|
||||||
$markdownConverter = new MarkdownConverter($environment);
|
$markdownConverter = new MarkdownConverter($environment);
|
||||||
|
|
||||||
return $markdownConverter->convert($this->main)->getContent();
|
return $markdownConverter->convert($this->main)->getContent();
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class Media extends Model
|
||||||
return $attributes['path'];
|
return $attributes['path'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return config('filesystems.disks.s3.url') . '/' . $attributes['path'];
|
return config('app.url') . '/storage/' . $attributes['path'];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +78,7 @@ class Media extends Model
|
||||||
$basename = $this->getBasename($path);
|
$basename = $this->getBasename($path);
|
||||||
$extension = $this->getExtension($path);
|
$extension = $this->getExtension($path);
|
||||||
|
|
||||||
return config('filesystems.disks.s3.url') . '/' . $basename . '-' . $size . '.' . $extension;
|
return config('app.url') . '/storage/' . $basename . '-' . $size . '.' . $extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBasename(string $path): string
|
private function getBasename(string $path): string
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@ class Note extends Model
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($oEmbed->httpstatus >= 400) {
|
if ($oEmbed->httpstatus >= 400) {
|
||||||
throw new Exception();
|
throw new Exception;
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -388,18 +388,18 @@ class Note extends Model
|
||||||
'mentions_handle' => [
|
'mentions_handle' => [
|
||||||
'prefix' => '@',
|
'prefix' => '@',
|
||||||
'pattern' => '([\w@.])+(\b)',
|
'pattern' => '([\w@.])+(\b)',
|
||||||
'generator' => new MentionGenerator(),
|
'generator' => new MentionGenerator,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$environment = new Environment($config);
|
$environment = new Environment($config);
|
||||||
$environment->addExtension(new CommonMarkCoreExtension());
|
$environment->addExtension(new CommonMarkCoreExtension);
|
||||||
$environment->addExtension(new AutolinkExtension());
|
$environment->addExtension(new AutolinkExtension);
|
||||||
$environment->addExtension(new MentionExtension());
|
$environment->addExtension(new MentionExtension);
|
||||||
$environment->addRenderer(Mention::class, new MentionRenderer());
|
$environment->addRenderer(Mention::class, new MentionRenderer);
|
||||||
$environment->addRenderer(FencedCode::class, new FencedCodeRenderer());
|
$environment->addRenderer(FencedCode::class, new FencedCodeRenderer);
|
||||||
$environment->addRenderer(IndentedCode::class, new IndentedCodeRenderer());
|
$environment->addRenderer(IndentedCode::class, new IndentedCodeRenderer);
|
||||||
$markdownConverter = new MarkdownConverter($environment);
|
$markdownConverter = new MarkdownConverter($environment);
|
||||||
|
|
||||||
return $markdownConverter->convert($note)->getContent();
|
return $markdownConverter->convert($note)->getContent();
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class WebMention extends Model
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$authorship = new Authorship();
|
$authorship = new Authorship;
|
||||||
$hCard = $authorship->findAuthor(json_decode($attributes['mf2'], true));
|
$hCard = $authorship->findAuthor(json_decode($attributes['mf2'], true));
|
||||||
|
|
||||||
if ($hCard === false) {
|
if ($hCard === false) {
|
||||||
|
|
@ -140,7 +140,7 @@ class WebMention extends Model
|
||||||
return $profile_image;
|
return $profile_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem;
|
||||||
if ($filesystem->exists(public_path() . '/assets/profile-images/' . $host . '/image')) {
|
if ($filesystem->exists(public_path() . '/assets/profile-images/' . $host . '/image')) {
|
||||||
return '/assets/profile-images/' . $host . '/image';
|
return '/assets/profile-images/' . $host . '/image';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,9 +88,9 @@ class AppServiceProvider extends ServiceProvider
|
||||||
$this->app->bind('Lcobucci\JWT\Configuration', function () {
|
$this->app->bind('Lcobucci\JWT\Configuration', function () {
|
||||||
$key = InMemory::plainText(config('app.key'));
|
$key = InMemory::plainText(config('app.key'));
|
||||||
|
|
||||||
$config = Configuration::forSymmetricSigner(new Sha256(), $key);
|
$config = Configuration::forSymmetricSigner(new Sha256, $key);
|
||||||
|
|
||||||
$config->setValidationConstraints(new SignedWith(new Sha256(), $key));
|
$config->setValidationConstraints(new SignedWith(new Sha256, $key));
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
});
|
});
|
||||||
|
|
@ -98,7 +98,7 @@ class AppServiceProvider extends ServiceProvider
|
||||||
// Configure HtmlSanitizer
|
// Configure HtmlSanitizer
|
||||||
$this->app->bind(HtmlSanitizer::class, function () {
|
$this->app->bind(HtmlSanitizer::class, function () {
|
||||||
return new HtmlSanitizer(
|
return new HtmlSanitizer(
|
||||||
(new HtmlSanitizerConfig())
|
(new HtmlSanitizerConfig)
|
||||||
->allowSafeElements()
|
->allowSafeElements()
|
||||||
->forceAttribute('a', 'rel', 'noopener nofollow')
|
->forceAttribute('a', 'rel', 'noopener nofollow')
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class BookmarkService extends Service
|
||||||
$response = $client->request('GET', 'https://web.archive.org/save/' . $url);
|
$response = $client->request('GET', 'https://web.archive.org/save/' . $url);
|
||||||
} catch (ClientException $e) {
|
} catch (ClientException $e) {
|
||||||
//throw an exception to be caught
|
//throw an exception to be caught
|
||||||
throw new InternetArchiveException();
|
throw new InternetArchiveException;
|
||||||
}
|
}
|
||||||
if ($response->hasHeader('Content-Location')) {
|
if ($response->hasHeader('Content-Location')) {
|
||||||
if (Str::startsWith(Arr::get($response->getHeader('Content-Location'), 0), '/web')) {
|
if (Str::startsWith(Arr::get($response->getHeader('Content-Location'), 0), '/web')) {
|
||||||
|
|
@ -71,6 +71,6 @@ class BookmarkService extends Service
|
||||||
}
|
}
|
||||||
|
|
||||||
//throw an exception to be caught
|
//throw an exception to be caught
|
||||||
throw new InternetArchiveException();
|
throw new InternetArchiveException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ class UpdateService
|
||||||
if ($property === 'photo') {
|
if ($property === 'photo') {
|
||||||
foreach ($value as $photoURL) {
|
foreach ($value as $photoURL) {
|
||||||
if (Str::startsWith($photoURL, 'https://')) {
|
if (Str::startsWith($photoURL, 'https://')) {
|
||||||
$media = new Media();
|
$media = new Media;
|
||||||
$media->path = $photoURL;
|
$media->path = $photoURL;
|
||||||
$media->type = 'image';
|
$media->type = 'image';
|
||||||
$media->save();
|
$media->save();
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class PlaceService
|
||||||
$data['latitude'] = $matches[0][0];
|
$data['latitude'] = $matches[0][0];
|
||||||
$data['longitude'] = $matches[0][1];
|
$data['longitude'] = $matches[0][1];
|
||||||
}
|
}
|
||||||
$place = new Place();
|
$place = new Place;
|
||||||
$place->name = $data['name'];
|
$place->name = $data['name'];
|
||||||
$place->description = $data['description'];
|
$place->description = $data['description'];
|
||||||
$place->latitude = $data['latitude'];
|
$place->latitude = $data['latitude'];
|
||||||
|
|
@ -53,7 +53,7 @@ class PlaceService
|
||||||
if (Arr::has($checkin, 'properties.latitude') === false) {
|
if (Arr::has($checkin, 'properties.latitude') === false) {
|
||||||
throw new \InvalidArgumentException('Missing required longitude/latitude');
|
throw new \InvalidArgumentException('Missing required longitude/latitude');
|
||||||
}
|
}
|
||||||
$place = new Place();
|
$place = new Place;
|
||||||
$place->name = Arr::get($checkin, 'properties.name.0');
|
$place->name = Arr::get($checkin, 'properties.name.0');
|
||||||
$place->external_urls = Arr::get($checkin, 'properties.url.0');
|
$place->external_urls = Arr::get($checkin, 'properties.url.0');
|
||||||
$place->latitude = Arr::get($checkin, 'properties.latitude.0');
|
$place->latitude = Arr::get($checkin, 'properties.latitude.0');
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class TokenService
|
||||||
$config = resolve(Configuration::class);
|
$config = resolve(Configuration::class);
|
||||||
|
|
||||||
$token = $config->builder()
|
$token = $config->builder()
|
||||||
->issuedAt(new DateTimeImmutable())
|
->issuedAt(new DateTimeImmutable)
|
||||||
->withClaim('client_id', $data['client_id'])
|
->withClaim('client_id', $data['client_id'])
|
||||||
->withClaim('me', $data['me'])
|
->withClaim('me', $data['me'])
|
||||||
->withClaim('scope', $data['scope'])
|
->withClaim('scope', $data['scope'])
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class ContactsTableSeeder extends Seeder
|
||||||
'homepage' => 'https://aaronparecki.com',
|
'homepage' => 'https://aaronparecki.com',
|
||||||
'facebook' => '123456',
|
'facebook' => '123456',
|
||||||
]);
|
]);
|
||||||
$fs = new FileSystem();
|
$fs = new FileSystem;
|
||||||
if (! $fs->exists(public_path('assets/profile-images/aaronparecki.com'))) {
|
if (! $fs->exists(public_path('assets/profile-images/aaronparecki.com'))) {
|
||||||
$fs->makeDirectory(public_path('assets/profile-images/aaronparecki.com'));
|
$fs->makeDirectory(public_path('assets/profile-images/aaronparecki.com'));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class LikesTableSeeder extends Seeder
|
||||||
Like::factory(10)->create();
|
Like::factory(10)->create();
|
||||||
|
|
||||||
$now = Carbon::now()->subDays(rand(3, 6));
|
$now = Carbon::now()->subDays(rand(3, 6));
|
||||||
$faker = new Generator();
|
$faker = new Generator;
|
||||||
$faker->addProvider(new \Faker\Provider\en_US\Person($faker));
|
$faker->addProvider(new \Faker\Provider\en_US\Person($faker));
|
||||||
$faker->addProvider(new \Faker\Provider\Lorem($faker));
|
$faker->addProvider(new \Faker\Provider\Lorem($faker));
|
||||||
$faker->addProvider(new \Faker\Provider\Internet($faker));
|
$faker->addProvider(new \Faker\Provider\Internet($faker));
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ class NotesTableSeeder extends Seeder
|
||||||
->update(['updated_at' => $now->toDateTimeString()]);
|
->update(['updated_at' => $now->toDateTimeString()]);
|
||||||
|
|
||||||
$now = Carbon::now()->subHours(5);
|
$now = Carbon::now()->subHours(5);
|
||||||
$noteJustCheckin = new Note();
|
$noteJustCheckin = new Note;
|
||||||
$noteJustCheckin->setCreatedAt($now);
|
$noteJustCheckin->setCreatedAt($now);
|
||||||
$place = Place::find(1);
|
$place = Place::find(1);
|
||||||
$noteJustCheckin->place()->associate($place);
|
$noteJustCheckin->place()->associate($place);
|
||||||
|
|
@ -164,12 +164,12 @@ class NotesTableSeeder extends Seeder
|
||||||
->update(['updated_at' => $now->toDateTimeString()]);
|
->update(['updated_at' => $now->toDateTimeString()]);
|
||||||
|
|
||||||
$now = Carbon::now()->subHours(4);
|
$now = Carbon::now()->subHours(4);
|
||||||
$media = new Media();
|
$media = new Media;
|
||||||
$media->path = 'media/f1bc8faa-1a8f-45b8-a9b1-57282fa73f87.jpg';
|
$media->path = 'media/f1bc8faa-1a8f-45b8-a9b1-57282fa73f87.jpg';
|
||||||
$media->type = 'image';
|
$media->type = 'image';
|
||||||
$media->image_widths = '3648';
|
$media->image_widths = '3648';
|
||||||
$media->save();
|
$media->save();
|
||||||
$noteWithOnlyImage = new Note();
|
$noteWithOnlyImage = new Note;
|
||||||
$noteWithOnlyImage->setCreatedAt($now);
|
$noteWithOnlyImage->setCreatedAt($now);
|
||||||
$noteWithOnlyImage->setUpdatedAt($now);
|
$noteWithOnlyImage->setUpdatedAt($now);
|
||||||
$noteWithOnlyImage->save();
|
$noteWithOnlyImage->save();
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class PlacesTableSeeder extends Seeder
|
||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$place = new Place();
|
$place = new Place;
|
||||||
$place->name = 'The Bridgewater Pub';
|
$place->name = 'The Bridgewater Pub';
|
||||||
$place->description = 'A lovely local pub with a decent selection of cask ales';
|
$place->description = 'A lovely local pub with a decent selection of cask ales';
|
||||||
$place->latitude = 53.4983;
|
$place->latitude = 53.4983;
|
||||||
|
|
|
||||||
1
storage/app/.gitignore
vendored
1
storage/app/.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
*
|
*
|
||||||
|
!private/
|
||||||
!public/
|
!public/
|
||||||
!.gitignore
|
!.gitignore
|
||||||
|
|
|
||||||
2
storage/app/private/.gitignore
vendored
Normal file
2
storage/app/private/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
*
|
||||||
|
!.gitignore
|
||||||
|
|
@ -32,7 +32,7 @@ abstract class DuskTestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
$desiredCapabilities = DesiredCapabilities::chrome();
|
$desiredCapabilities = DesiredCapabilities::chrome();
|
||||||
|
|
||||||
$options = new ChromeOptions();
|
$options = new ChromeOptions;
|
||||||
$options->addArguments([
|
$options->addArguments([
|
||||||
'headless',
|
'headless',
|
||||||
'disable-gpu',
|
'disable-gpu',
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ class LikesTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function likeWithSimpleAuthor(): void
|
public function likeWithSimpleAuthor(): void
|
||||||
{
|
{
|
||||||
$like = new Like();
|
$like = new Like;
|
||||||
$like->url = 'http://example.org/note/id';
|
$like->url = 'http://example.org/note/id';
|
||||||
$like->save();
|
$like->save();
|
||||||
$id = $like->id;
|
$id = $like->id;
|
||||||
|
|
@ -107,7 +107,7 @@ class LikesTest extends TestCase
|
||||||
$this->app->bind(Client::class, function () use ($client) {
|
$this->app->bind(Client::class, function () use ($client) {
|
||||||
return $client;
|
return $client;
|
||||||
});
|
});
|
||||||
$authorship = new Authorship();
|
$authorship = new Authorship;
|
||||||
|
|
||||||
$job->handle($client, $authorship);
|
$job->handle($client, $authorship);
|
||||||
|
|
||||||
|
|
@ -117,7 +117,7 @@ class LikesTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function likeWithHCard(): void
|
public function likeWithHCard(): void
|
||||||
{
|
{
|
||||||
$like = new Like();
|
$like = new Like;
|
||||||
$like->url = 'http://example.org/note/id';
|
$like->url = 'http://example.org/note/id';
|
||||||
$like->save();
|
$like->save();
|
||||||
$id = $like->id;
|
$id = $like->id;
|
||||||
|
|
@ -150,7 +150,7 @@ class LikesTest extends TestCase
|
||||||
$this->app->bind(Client::class, function () use ($client) {
|
$this->app->bind(Client::class, function () use ($client) {
|
||||||
return $client;
|
return $client;
|
||||||
});
|
});
|
||||||
$authorship = new Authorship();
|
$authorship = new Authorship;
|
||||||
|
|
||||||
$job->handle($client, $authorship);
|
$job->handle($client, $authorship);
|
||||||
|
|
||||||
|
|
@ -160,7 +160,7 @@ class LikesTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function likeWithoutMicroformats(): void
|
public function likeWithoutMicroformats(): void
|
||||||
{
|
{
|
||||||
$like = new Like();
|
$like = new Like;
|
||||||
$like->url = 'http://example.org/note/id';
|
$like->url = 'http://example.org/note/id';
|
||||||
$like->save();
|
$like->save();
|
||||||
$id = $like->id;
|
$id = $like->id;
|
||||||
|
|
@ -186,7 +186,7 @@ class LikesTest extends TestCase
|
||||||
$this->app->bind(Client::class, function () use ($client) {
|
$this->app->bind(Client::class, function () use ($client) {
|
||||||
return $client;
|
return $client;
|
||||||
});
|
});
|
||||||
$authorship = new Authorship();
|
$authorship = new Authorship;
|
||||||
|
|
||||||
$job->handle($client, $authorship);
|
$job->handle($client, $authorship);
|
||||||
|
|
||||||
|
|
@ -196,7 +196,7 @@ class LikesTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function likeThatIsATweet(): void
|
public function likeThatIsATweet(): void
|
||||||
{
|
{
|
||||||
$like = new Like();
|
$like = new Like;
|
||||||
$like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200';
|
$like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200';
|
||||||
$like->save();
|
$like->save();
|
||||||
$id = $like->id;
|
$id = $like->id;
|
||||||
|
|
@ -226,7 +226,7 @@ class LikesTest extends TestCase
|
||||||
->willReturn($info);
|
->willReturn($info);
|
||||||
$this->app->instance(Codebird::class, $codebirdMock);
|
$this->app->instance(Codebird::class, $codebirdMock);
|
||||||
|
|
||||||
$authorship = new Authorship();
|
$authorship = new Authorship;
|
||||||
|
|
||||||
$job->handle($client, $authorship);
|
$job->handle($client, $authorship);
|
||||||
|
|
||||||
|
|
@ -236,7 +236,7 @@ class LikesTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function noErrorForFailureToPosseWithBridgy(): void
|
public function noErrorForFailureToPosseWithBridgy(): void
|
||||||
{
|
{
|
||||||
$like = new Like();
|
$like = new Like;
|
||||||
$like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200';
|
$like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200';
|
||||||
$like->save();
|
$like->save();
|
||||||
$id = $like->id;
|
$id = $like->id;
|
||||||
|
|
@ -264,7 +264,7 @@ class LikesTest extends TestCase
|
||||||
->willReturn($info);
|
->willReturn($info);
|
||||||
$this->app->instance(Codebird::class, $codebirdMock);
|
$this->app->instance(Codebird::class, $codebirdMock);
|
||||||
|
|
||||||
$authorship = new Authorship();
|
$authorship = new Authorship;
|
||||||
|
|
||||||
$job->handle($client, $authorship);
|
$job->handle($client, $authorship);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,7 @@ class MicropubControllerTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function micropubClientApiRequestCreatesNewNoteWithExistingPlaceInLocationData(): void
|
public function micropubClientApiRequestCreatesNewNoteWithExistingPlaceInLocationData(): void
|
||||||
{
|
{
|
||||||
$place = new Place();
|
$place = new Place;
|
||||||
$place->name = 'Test Place';
|
$place->name = 'Test Place';
|
||||||
$place->latitude = 1.23;
|
$place->latitude = 1.23;
|
||||||
$place->longitude = 4.56;
|
$place->longitude = 4.56;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Support\Facades\Queue;
|
use Illuminate\Support\Facades\Queue;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\TestToken;
|
use Tests\TestToken;
|
||||||
|
|
||||||
|
|
@ -22,9 +23,7 @@ class MicropubMediaTest extends TestCase
|
||||||
public function emptyResponseForLastUploadWhenNoneFound(): void
|
public function emptyResponseForLastUploadWhenNoneFound(): void
|
||||||
{
|
{
|
||||||
// Make sure there’s no media
|
// Make sure there’s no media
|
||||||
Media::all()->each(function ($media) {
|
$this->assertCount(0, Media::all());
|
||||||
$media->delete();
|
|
||||||
});
|
|
||||||
|
|
||||||
$response = $this->get(
|
$response = $this->get(
|
||||||
'/api/media?q=last',
|
'/api/media?q=last',
|
||||||
|
|
@ -82,10 +81,8 @@ class MicropubMediaTest extends TestCase
|
||||||
public function clientCanListLastUpload(): void
|
public function clientCanListLastUpload(): void
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
Storage::fake('s3');
|
|
||||||
$file = __DIR__ . '/../aaron.png';
|
$file = __DIR__ . '/../aaron.png';
|
||||||
$token = $this->getToken();
|
$token = $this->getToken();
|
||||||
config(['filesystems.disks.s3.url' => 'https://s3.example.com']);
|
|
||||||
|
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
'/api/media',
|
'/api/media',
|
||||||
|
|
@ -95,12 +92,8 @@ class MicropubMediaTest extends TestCase
|
||||||
['HTTP_Authorization' => 'Bearer ' . $token]
|
['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);
|
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||||
$filename = substr($path, 7);
|
$filename = Str::chopStart($path, '/media/');
|
||||||
|
|
||||||
$lastUploadResponse = $this->get(
|
$lastUploadResponse = $this->get(
|
||||||
'/api/media?q=last',
|
'/api/media?q=last',
|
||||||
|
|
@ -109,14 +102,14 @@ class MicropubMediaTest extends TestCase
|
||||||
$lastUploadResponse->assertJson(['url' => $response->headers->get('Location')]);
|
$lastUploadResponse->assertJson(['url' => $response->headers->get('Location')]);
|
||||||
|
|
||||||
// now remove file
|
// now remove file
|
||||||
unlink(storage_path('app/') . $filename);
|
unlink(storage_path('app/media/') . $filename);
|
||||||
|
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function clientCanSourceUploads(): void
|
public function clientCanSourceUploads(): void
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
Storage::fake('s3');
|
|
||||||
$file = __DIR__ . '/../aaron.png';
|
$file = __DIR__ . '/../aaron.png';
|
||||||
$token = $this->getToken();
|
$token = $this->getToken();
|
||||||
|
|
||||||
|
|
@ -129,7 +122,7 @@ class MicropubMediaTest extends TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||||
$filename = substr($path, 7);
|
$filename = Str::chopStart($path, '/media/');
|
||||||
|
|
||||||
$sourceUploadResponse = $this->get(
|
$sourceUploadResponse = $this->get(
|
||||||
'/api/media?q=source',
|
'/api/media?q=source',
|
||||||
|
|
@ -141,14 +134,14 @@ class MicropubMediaTest extends TestCase
|
||||||
]]]);
|
]]]);
|
||||||
|
|
||||||
// now remove file
|
// now remove file
|
||||||
unlink(storage_path('app/') . $filename);
|
unlink(storage_path('app/media/') . $filename);
|
||||||
|
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function clientCanSourceUploadsWithLimit(): void
|
public function clientCanSourceUploadsWithLimit(): void
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
Storage::fake('s3');
|
|
||||||
$file = __DIR__ . '/../aaron.png';
|
$file = __DIR__ . '/../aaron.png';
|
||||||
$token = $this->getToken();
|
$token = $this->getToken();
|
||||||
|
|
||||||
|
|
@ -161,7 +154,7 @@ class MicropubMediaTest extends TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||||
$filename = substr($path, 7);
|
$filename = Str::chopStart($path, '/media/');
|
||||||
|
|
||||||
$sourceUploadResponse = $this->get(
|
$sourceUploadResponse = $this->get(
|
||||||
'/api/media?q=source&limit=1',
|
'/api/media?q=source&limit=1',
|
||||||
|
|
@ -175,7 +168,8 @@ class MicropubMediaTest extends TestCase
|
||||||
$this->assertCount(1, json_decode($sourceUploadResponse->getContent(), true)['items']);
|
$this->assertCount(1, json_decode($sourceUploadResponse->getContent(), true)['items']);
|
||||||
|
|
||||||
// now remove file
|
// now remove file
|
||||||
unlink(storage_path('app/') . $filename);
|
unlink(storage_path('app/media/') . $filename);
|
||||||
|
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
@ -256,7 +250,6 @@ class MicropubMediaTest extends TestCase
|
||||||
public function mediaEndpointUploadFile(): void
|
public function mediaEndpointUploadFile(): void
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
Storage::fake('s3');
|
|
||||||
$file = __DIR__ . '/../aaron.png';
|
$file = __DIR__ . '/../aaron.png';
|
||||||
|
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
|
|
@ -268,18 +261,18 @@ class MicropubMediaTest extends TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||||
$filename = substr($path, 7);
|
$filename = Str::chopStart($path, '/media/');
|
||||||
Queue::assertPushed(ProcessMedia::class);
|
Queue::assertPushed(ProcessMedia::class);
|
||||||
Storage::disk('local')->assertExists($filename);
|
Storage::disk('local')->assertExists($path);
|
||||||
// now remove file
|
// now remove file
|
||||||
unlink(storage_path('app/') . $filename);
|
unlink(storage_path('app/media/') . $filename);
|
||||||
|
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function mediaEndpointUploadAudioFile(): void
|
public function mediaEndpointUploadAudioFile(): void
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
Storage::fake('s3');
|
|
||||||
$file = __DIR__ . '/../audio.mp3';
|
$file = __DIR__ . '/../audio.mp3';
|
||||||
|
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
|
|
@ -291,18 +284,18 @@ class MicropubMediaTest extends TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||||
$filename = substr($path, 7);
|
$filename = Str::chopStart($path, '/media/');
|
||||||
Queue::assertPushed(ProcessMedia::class);
|
Queue::assertPushed(ProcessMedia::class);
|
||||||
Storage::disk('local')->assertExists($filename);
|
Storage::disk('local')->assertExists($path);
|
||||||
// now remove file
|
// now remove file
|
||||||
unlink(storage_path('app/') . $filename);
|
unlink(storage_path('app/media/') . $filename);
|
||||||
|
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function mediaEndpointUploadVideoFile(): void
|
public function mediaEndpointUploadVideoFile(): void
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
Storage::fake('s3');
|
|
||||||
$file = __DIR__ . '/../video.ogv';
|
$file = __DIR__ . '/../video.ogv';
|
||||||
|
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
|
|
@ -314,18 +307,18 @@ class MicropubMediaTest extends TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||||
$filename = substr($path, 7);
|
$filename = Str::chopStart($path, '/media/');
|
||||||
Queue::assertPushed(ProcessMedia::class);
|
Queue::assertPushed(ProcessMedia::class);
|
||||||
Storage::disk('local')->assertExists($filename);
|
Storage::disk('local')->assertExists($path);
|
||||||
// now remove file
|
// now remove file
|
||||||
unlink(storage_path('app/') . $filename);
|
unlink(storage_path('app/media/') . $filename);
|
||||||
|
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function mediaEndpointUploadDocumentFile(): void
|
public function mediaEndpointUploadDocumentFile(): void
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
Storage::fake('s3');
|
|
||||||
|
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
'/api/media',
|
'/api/media',
|
||||||
|
|
@ -336,11 +329,12 @@ class MicropubMediaTest extends TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||||
$filename = substr($path, 7);
|
$filename = Str::chopStart($path, '/media/');
|
||||||
Queue::assertPushed(ProcessMedia::class);
|
Queue::assertPushed(ProcessMedia::class);
|
||||||
Storage::disk('local')->assertExists($filename);
|
Storage::disk('local')->assertExists($path);
|
||||||
// now remove file
|
// now remove file
|
||||||
unlink(storage_path('app/') . $filename);
|
unlink(storage_path('app/media/') . $filename);
|
||||||
|
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class ParseCachedWebMentionsTest extends TestCase
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
$fs = new FileSystem();
|
$fs = new FileSystem;
|
||||||
if ($fs->exists(storage_path() . '/HTML/https')) {
|
if ($fs->exists(storage_path() . '/HTML/https')) {
|
||||||
$fs->deleteDirectory(storage_path() . '/HTML/https');
|
$fs->deleteDirectory(storage_path() . '/HTML/https');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class TokenServiceTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function tokenserviceCreatesAndValidatesTokens(): void
|
public function tokenserviceCreatesAndValidatesTokens(): void
|
||||||
{
|
{
|
||||||
$tokenService = new TokenService();
|
$tokenService = new TokenService;
|
||||||
$data = [
|
$data = [
|
||||||
'me' => 'https://example.org',
|
'me' => 'https://example.org',
|
||||||
'client_id' => 'https://quill.p3k.io',
|
'client_id' => 'https://quill.p3k.io',
|
||||||
|
|
@ -55,7 +55,7 @@ class TokenServiceTest extends TestCase
|
||||||
$config = resolve(Configuration::class);
|
$config = resolve(Configuration::class);
|
||||||
|
|
||||||
$token = $config->builder()
|
$token = $config->builder()
|
||||||
->issuedAt(new DateTimeImmutable())
|
->issuedAt(new DateTimeImmutable)
|
||||||
->withClaim('client_id', $data['client_id'])
|
->withClaim('client_id', $data['client_id'])
|
||||||
->withClaim('me', $data['me'])
|
->withClaim('me', $data['me'])
|
||||||
->withClaim('scope', $data['scope'])
|
->withClaim('scope', $data['scope'])
|
||||||
|
|
@ -63,7 +63,7 @@ class TokenServiceTest extends TestCase
|
||||||
->getToken($config->signer(), InMemory::plainText(random_bytes(32)))
|
->getToken($config->signer(), InMemory::plainText(random_bytes(32)))
|
||||||
->toString();
|
->toString();
|
||||||
|
|
||||||
$service = new TokenService();
|
$service = new TokenService;
|
||||||
$service->validateToken($token);
|
$service->validateToken($token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,13 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
use CreatesApplication;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ trait TestToken
|
||||||
$config = $this->app->make(Configuration::class);
|
$config = $this->app->make(Configuration::class);
|
||||||
|
|
||||||
return $config->builder()
|
return $config->builder()
|
||||||
->issuedAt(new DateTimeImmutable())
|
->issuedAt(new DateTimeImmutable)
|
||||||
->withClaim('client_id', 'https://quill.p3k.io')
|
->withClaim('client_id', 'https://quill.p3k.io')
|
||||||
->withClaim('me', 'http://jonnybarnes.localhost')
|
->withClaim('me', 'http://jonnybarnes.localhost')
|
||||||
->withClaim('scope', ['create', 'update'])
|
->withClaim('scope', ['create', 'update'])
|
||||||
|
|
@ -25,7 +25,7 @@ trait TestToken
|
||||||
$config = $this->app->make(Configuration::class);
|
$config = $this->app->make(Configuration::class);
|
||||||
|
|
||||||
return $config->builder()
|
return $config->builder()
|
||||||
->issuedAt(new DateTimeImmutable())
|
->issuedAt(new DateTimeImmutable)
|
||||||
->withClaim('client_id', 'https://quill.p3k.io')
|
->withClaim('client_id', 'https://quill.p3k.io')
|
||||||
->withClaim('me', 'https://jonnybarnes.localhost')
|
->withClaim('me', 'https://jonnybarnes.localhost')
|
||||||
->withClaim('scope', 'view')
|
->withClaim('scope', 'view')
|
||||||
|
|
@ -38,7 +38,7 @@ trait TestToken
|
||||||
$config = $this->app->make(Configuration::class);
|
$config = $this->app->make(Configuration::class);
|
||||||
|
|
||||||
return $config->builder()
|
return $config->builder()
|
||||||
->issuedAt(new DateTimeImmutable())
|
->issuedAt(new DateTimeImmutable)
|
||||||
->withClaim('client_id', 'https://quill.p3k.io')
|
->withClaim('client_id', 'https://quill.p3k.io')
|
||||||
->withClaim('me', 'https://jonnybarnes.localhost')
|
->withClaim('me', 'https://jonnybarnes.localhost')
|
||||||
->getToken($config->signer(), $config->signingKey())
|
->getToken($config->signer(), $config->signingKey())
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class ArticlesTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function titleSlugIsGeneratedAutomatically(): void
|
public function titleSlugIsGeneratedAutomatically(): void
|
||||||
{
|
{
|
||||||
$article = new Article();
|
$article = new Article;
|
||||||
$article->title = 'My Title';
|
$article->title = 'My Title';
|
||||||
$article->main = 'Content';
|
$article->main = 'Content';
|
||||||
$article->save();
|
$article->save();
|
||||||
|
|
@ -27,7 +27,7 @@ class ArticlesTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function markdownContentIsConverted(): void
|
public function markdownContentIsConverted(): void
|
||||||
{
|
{
|
||||||
$article = new Article();
|
$article = new Article;
|
||||||
$article->main = 'Some *markdown*';
|
$article->main = 'Some *markdown*';
|
||||||
|
|
||||||
$this->assertEquals('<p>Some <em>markdown</em></p>' . PHP_EOL, $article->html);
|
$this->assertEquals('<p>Some <em>markdown</em></p>' . PHP_EOL, $article->html);
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class BookmarksTest extends TestCase
|
||||||
$handler = HandlerStack::create($mock);
|
$handler = HandlerStack::create($mock);
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
$url = (new BookmarkService())->getArchiveLink('https://example.org');
|
$url = (new BookmarkService)->getArchiveLink('https://example.org');
|
||||||
$this->assertEquals('/web/1234/example.org', $url);
|
$this->assertEquals('/web/1234/example.org', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ class BookmarksTest extends TestCase
|
||||||
$handler = HandlerStack::create($mock);
|
$handler = HandlerStack::create($mock);
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
(new BookmarkService())->getArchiveLink('https://example.org');
|
(new BookmarkService)->getArchiveLink('https://example.org');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
@ -63,6 +63,6 @@ class BookmarksTest extends TestCase
|
||||||
$handler = HandlerStack::create($mock);
|
$handler = HandlerStack::create($mock);
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
(new BookmarkService())->getArchiveLink('https://example.org');
|
(new BookmarkService)->getArchiveLink('https://example.org');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class DownloadWebMentionJobTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
$fs = new FileSystem();
|
$fs = new FileSystem;
|
||||||
if ($fs->exists(storage_path() . '/HTML/https')) {
|
if ($fs->exists(storage_path() . '/HTML/https')) {
|
||||||
$fs->deleteDirectory(storage_path() . '/HTML/https');
|
$fs->deleteDirectory(storage_path() . '/HTML/https');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class ProcessBookmarkJobTest extends TestCase
|
||||||
$bookmark = Bookmark::factory()->create();
|
$bookmark = Bookmark::factory()->create();
|
||||||
$service = $this->createMock(BookmarkService::class);
|
$service = $this->createMock(BookmarkService::class);
|
||||||
$service->method('getArchiveLink')
|
$service->method('getArchiveLink')
|
||||||
->will($this->throwException(new InternetArchiveException()));
|
->will($this->throwException(new InternetArchiveException));
|
||||||
$this->app->instance(BookmarkService::class, $service);
|
$this->app->instance(BookmarkService::class, $service);
|
||||||
|
|
||||||
$job = new ProcessBookmark($bookmark);
|
$job = new ProcessBookmark($bookmark);
|
||||||
|
|
|
||||||
|
|
@ -14,38 +14,48 @@ class ProcessMediaJobTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function nonMediaFilesAreNotSaved(): void
|
public function nonMediaFilesAreNotSaved(): void
|
||||||
{
|
{
|
||||||
Storage::fake('s3');
|
|
||||||
$manager = app()->make(ImageManager::class);
|
$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 = new ProcessMedia('file.txt');
|
||||||
$job->handle($manager);
|
$job->handle($manager);
|
||||||
|
|
||||||
$this->assertFalse(file_exists(storage_path('app') . '/file.txt'));
|
$this->assertFileDoesNotExist(storage_path('app/media/') . 'file.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function smallImagesAreNotResized(): void
|
public function smallImagesAreNotResized(): void
|
||||||
{
|
{
|
||||||
Storage::fake('s3');
|
|
||||||
$manager = app()->make(ImageManager::class);
|
$manager = app()->make(ImageManager::class);
|
||||||
Storage::disk('local')->put('aaron.png', file_get_contents(__DIR__ . '/../../aaron.png'));
|
Storage::disk('local')->put('media/aaron.png', file_get_contents(__DIR__ . '/../../aaron.png'));
|
||||||
$job = new ProcessMedia('aaron.png');
|
$job = new ProcessMedia('aaron.png');
|
||||||
$job->handle($manager);
|
$job->handle($manager);
|
||||||
|
|
||||||
$this->assertFalse(file_exists(storage_path('app') . '/aaron.png'));
|
$this->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 */
|
/** @test */
|
||||||
public function largeImagesHaveSmallerImagesCreated(): void
|
public function largeImagesHaveSmallerImagesCreated(): void
|
||||||
{
|
{
|
||||||
$manager = app()->make(ImageManager::class);
|
$manager = app()->make(ImageManager::class);
|
||||||
Storage::disk('local')->put('test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));
|
Storage::disk('local')->put('media/test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));
|
||||||
Storage::fake('s3');
|
|
||||||
$job = new ProcessMedia('test-image.jpg');
|
$job = new ProcessMedia('test-image.jpg');
|
||||||
$job->handle($manager);
|
$job->handle($manager);
|
||||||
|
|
||||||
Storage::disk('s3')->assertExists('media/test-image-small.jpg');
|
Storage::disk('local')->assertExists('public/media/test-image.jpg');
|
||||||
Storage::disk('s3')->assertExists('media/test-image-medium.jpg');
|
Storage::disk('local')->assertExists('public/media/test-image-small.jpg');
|
||||||
$this->assertFalse(file_exists(storage_path('app') . '/test-image.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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class ProcessWebMentionJobTest extends TestCase
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
$fs = new FileSystem();
|
$fs = new FileSystem;
|
||||||
if ($fs->exists(storage_path() . '/HTML/https')) {
|
if ($fs->exists(storage_path() . '/HTML/https')) {
|
||||||
$fs->deleteDirectory(storage_path() . '/HTML/https');
|
$fs->deleteDirectory(storage_path() . '/HTML/https');
|
||||||
}
|
}
|
||||||
|
|
@ -37,7 +37,7 @@ class ProcessWebMentionJobTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(RemoteContentNotFoundException::class);
|
$this->expectException(RemoteContentNotFoundException::class);
|
||||||
|
|
||||||
$parser = new Parser();
|
$parser = new Parser;
|
||||||
$mock = new MockHandler([
|
$mock = new MockHandler([
|
||||||
new Response(404),
|
new Response(404),
|
||||||
]);
|
]);
|
||||||
|
|
@ -56,7 +56,7 @@ class ProcessWebMentionJobTest extends TestCase
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
|
|
||||||
$parser = new Parser();
|
$parser = new Parser;
|
||||||
|
|
||||||
$html = <<<'HTML'
|
$html = <<<'HTML'
|
||||||
<div class="h-entry">
|
<div class="h-entry">
|
||||||
|
|
@ -88,7 +88,7 @@ class ProcessWebMentionJobTest extends TestCase
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
|
|
||||||
$parser = new Parser();
|
$parser = new Parser;
|
||||||
$note = Note::factory()->create();
|
$note = Note::factory()->create();
|
||||||
$source = 'https://aaronpk.localhost/reply/1';
|
$source = 'https://aaronpk.localhost/reply/1';
|
||||||
WebMention::factory()->create([
|
WebMention::factory()->create([
|
||||||
|
|
@ -123,7 +123,7 @@ class ProcessWebMentionJobTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function webmentionReplyGetsDeletedWhenReplyToValueChanges(): void
|
public function webmentionReplyGetsDeletedWhenReplyToValueChanges(): void
|
||||||
{
|
{
|
||||||
$parser = new Parser();
|
$parser = new Parser;
|
||||||
|
|
||||||
$html = <<<'HTML'
|
$html = <<<'HTML'
|
||||||
<div class="h-entry">
|
<div class="h-entry">
|
||||||
|
|
@ -139,7 +139,7 @@ class ProcessWebMentionJobTest extends TestCase
|
||||||
|
|
||||||
$note = Note::factory()->create();
|
$note = Note::factory()->create();
|
||||||
$source = 'https://example.org/reply/1';
|
$source = 'https://example.org/reply/1';
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$webmention->source = $source;
|
$webmention->source = $source;
|
||||||
$webmention->target = config('app.url') . '/notes/E';
|
$webmention->target = config('app.url') . '/notes/E';
|
||||||
$webmention->type = 'in-reply-to';
|
$webmention->type = 'in-reply-to';
|
||||||
|
|
@ -160,7 +160,7 @@ class ProcessWebMentionJobTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function webmentionLikeGetsDeletedWhenLikeOfValueChanges(): void
|
public function webmentionLikeGetsDeletedWhenLikeOfValueChanges(): void
|
||||||
{
|
{
|
||||||
$parser = new Parser();
|
$parser = new Parser;
|
||||||
|
|
||||||
$html = <<<'HTML'
|
$html = <<<'HTML'
|
||||||
<div class="h-entry">
|
<div class="h-entry">
|
||||||
|
|
@ -176,7 +176,7 @@ class ProcessWebMentionJobTest extends TestCase
|
||||||
|
|
||||||
$note = Note::factory()->create();
|
$note = Note::factory()->create();
|
||||||
$source = 'https://example.org/reply/1';
|
$source = 'https://example.org/reply/1';
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$webmention->source = $source;
|
$webmention->source = $source;
|
||||||
$webmention->target = config('app.url') . '/notes/E';
|
$webmention->target = config('app.url') . '/notes/E';
|
||||||
$webmention->type = 'like-of';
|
$webmention->type = 'like-of';
|
||||||
|
|
@ -197,7 +197,7 @@ class ProcessWebMentionJobTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function webmentionRepostGetsDeletedWhenRepostOfValueChanges(): void
|
public function webmentionRepostGetsDeletedWhenRepostOfValueChanges(): void
|
||||||
{
|
{
|
||||||
$parser = new Parser();
|
$parser = new Parser;
|
||||||
|
|
||||||
$html = <<<'HTML'
|
$html = <<<'HTML'
|
||||||
<div class="h-entry">
|
<div class="h-entry">
|
||||||
|
|
@ -213,7 +213,7 @@ class ProcessWebMentionJobTest extends TestCase
|
||||||
|
|
||||||
$note = Note::factory()->create();
|
$note = Note::factory()->create();
|
||||||
$source = 'https://example.org/reply/1';
|
$source = 'https://example.org/reply/1';
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$webmention->source = $source;
|
$webmention->source = $source;
|
||||||
$webmention->target = config('app.url') . '/notes/E';
|
$webmention->target = config('app.url') . '/notes/E';
|
||||||
$webmention->type = 'repost-of';
|
$webmention->type = 'repost-of';
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class SaveProfileImageJobTest extends TestCase
|
||||||
$mf = ['items' => []];
|
$mf = ['items' => []];
|
||||||
$authorship = $this->createMock(Authorship::class);
|
$authorship = $this->createMock(Authorship::class);
|
||||||
$authorship->method('findAuthor')
|
$authorship->method('findAuthor')
|
||||||
->will($this->throwException(new AuthorshipParserException()));
|
->will($this->throwException(new AuthorshipParserException));
|
||||||
$job = new SaveProfileImage($mf);
|
$job = new SaveProfileImage($mf);
|
||||||
|
|
||||||
$this->assertNull($job->handle($authorship));
|
$this->assertNull($job->handle($authorship));
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class SendWebMentionJobTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function discoverWebmentionEndpointOnOwnDomain(): void
|
public function discoverWebmentionEndpointOnOwnDomain(): void
|
||||||
{
|
{
|
||||||
$note = new Note();
|
$note = new Note;
|
||||||
$job = new SendWebMentions($note);
|
$job = new SendWebMentions($note);
|
||||||
$this->assertNull($job->discoverWebmentionEndpoint(config('app.url')));
|
$this->assertNull($job->discoverWebmentionEndpoint(config('app.url')));
|
||||||
$this->assertNull($job->discoverWebmentionEndpoint('/notes/tagged/test'));
|
$this->assertNull($job->discoverWebmentionEndpoint('/notes/tagged/test'));
|
||||||
|
|
@ -34,7 +34,7 @@ class SendWebMentionJobTest extends TestCase
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
|
||||||
$job = new SendWebMentions(new Note());
|
$job = new SendWebMentions(new Note);
|
||||||
$this->assertEquals($url, $job->discoverWebmentionEndpoint('https://example.org'));
|
$this->assertEquals($url, $job->discoverWebmentionEndpoint('https://example.org'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ class SendWebMentionJobTest extends TestCase
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
|
||||||
$job = new SendWebMentions(new Note());
|
$job = new SendWebMentions(new Note);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://example.org/webmention',
|
'https://example.org/webmention',
|
||||||
$job->discoverWebmentionEndpoint('https://example.org')
|
$job->discoverWebmentionEndpoint('https://example.org')
|
||||||
|
|
@ -67,7 +67,7 @@ class SendWebMentionJobTest extends TestCase
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
|
||||||
$job = new SendWebMentions(new Note());
|
$job = new SendWebMentions(new Note);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://example.org/webmention',
|
'https://example.org/webmention',
|
||||||
$job->discoverWebmentionEndpoint('https://example.org')
|
$job->discoverWebmentionEndpoint('https://example.org')
|
||||||
|
|
@ -77,7 +77,7 @@ class SendWebMentionJobTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function ensureEmptyNoteDoesNotTriggerAnyActions(): void
|
public function ensureEmptyNoteDoesNotTriggerAnyActions(): void
|
||||||
{
|
{
|
||||||
$job = new SendWebMentions(new Note());
|
$job = new SendWebMentions(new Note);
|
||||||
$this->assertNull($job->handle());
|
$this->assertNull($job->handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,7 +86,7 @@ class SendWebMentionJobTest extends TestCase
|
||||||
{
|
{
|
||||||
$uri = '/blog/post';
|
$uri = '/blog/post';
|
||||||
$base = 'https://example.org/';
|
$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));
|
$this->assertEquals('https://example.org/blog/post', $job->resolveUri($uri, $base));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,7 +102,7 @@ class SendWebMentionJobTest extends TestCase
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
|
||||||
$note = new Note();
|
$note = new Note;
|
||||||
$note->note = 'Hi [Aaron](https://aaronparecki.com)';
|
$note->note = 'Hi [Aaron](https://aaronparecki.com)';
|
||||||
$note->save();
|
$note->save();
|
||||||
$job = new SendWebMentions($note);
|
$job = new SendWebMentions($note);
|
||||||
|
|
@ -121,7 +121,7 @@ class SendWebMentionJobTest extends TestCase
|
||||||
$client = new Client(['handler' => $handler]);
|
$client = new Client(['handler' => $handler]);
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
|
||||||
$job = new SendWebMentions(new Note());
|
$job = new SendWebMentions(new Note);
|
||||||
$this->assertNull($job->discoverWebmentionEndpoint('https://example.org'));
|
$this->assertNull($job->discoverWebmentionEndpoint('https://example.org'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class LikesTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function weCanSetTheAuthorUrl(): void
|
public function weCanSetTheAuthorUrl(): void
|
||||||
{
|
{
|
||||||
$like = new Like();
|
$like = new Like;
|
||||||
$like->author_url = 'https://joe.bloggs/';
|
$like->author_url = 'https://joe.bloggs/';
|
||||||
$this->assertEquals('https://joe.bloggs', $like->author_url);
|
$this->assertEquals('https://joe.bloggs', $like->author_url);
|
||||||
}
|
}
|
||||||
|
|
@ -23,7 +23,7 @@ class LikesTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function weDoNotModifyPlainTextContent(): void
|
public function weDoNotModifyPlainTextContent(): void
|
||||||
{
|
{
|
||||||
$like = new Like();
|
$like = new Like;
|
||||||
$like->url = 'https://example.org/post/123';
|
$like->url = 'https://example.org/post/123';
|
||||||
$like->content = 'some plaintext content';
|
$like->content = 'some plaintext content';
|
||||||
$like->save();
|
$like->save();
|
||||||
|
|
@ -34,7 +34,7 @@ class LikesTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function weCanHandleBlankContent(): void
|
public function weCanHandleBlankContent(): void
|
||||||
{
|
{
|
||||||
$like = new Like();
|
$like = new Like;
|
||||||
$like->url = 'https://example.org/post/123';
|
$like->url = 'https://example.org/post/123';
|
||||||
$like->content = null;
|
$like->content = null;
|
||||||
$like->save();
|
$like->save();
|
||||||
|
|
@ -57,7 +57,7 @@ class LikesTest extends TestCase
|
||||||
<p>Hello</p>
|
<p>Hello</p>
|
||||||
<img />
|
<img />
|
||||||
HTML;
|
HTML;
|
||||||
$like = new Like();
|
$like = new Like;
|
||||||
$like->url = 'https://example.org/post/123';
|
$like->url = 'https://example.org/post/123';
|
||||||
$like->content = $htmlEvil;
|
$like->content = $htmlEvil;
|
||||||
$like->save();
|
$like->save();
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class MediaTest extends TestCase
|
||||||
public function absoluteUrlsAreReturnedUnmodified(): void
|
public function absoluteUrlsAreReturnedUnmodified(): void
|
||||||
{
|
{
|
||||||
$absoluteUrl = 'https://instagram-cdn.com/image/uuid';
|
$absoluteUrl = 'https://instagram-cdn.com/image/uuid';
|
||||||
$media = new Media();
|
$media = new Media;
|
||||||
$media->path = $absoluteUrl;
|
$media->path = $absoluteUrl;
|
||||||
|
|
||||||
$this->assertEquals($absoluteUrl, $media->url);
|
$this->assertEquals($absoluteUrl, $media->url);
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ class NotesTest extends TestCase
|
||||||
'twitter' => null,
|
'twitter' => null,
|
||||||
'facebook' => 123456,
|
'facebook' => 123456,
|
||||||
]);
|
]);
|
||||||
$fileSystem = new Filesystem();
|
$fileSystem = new Filesystem;
|
||||||
$fileSystem->ensureDirectoryExists(public_path('/assets/profile-images/aaronparecki.com'));
|
$fileSystem->ensureDirectoryExists(public_path('/assets/profile-images/aaronparecki.com'));
|
||||||
if (! $fileSystem->exists(public_path('/assets/profile-images/aaronparecki.com/image'))) {
|
if (! $fileSystem->exists(public_path('/assets/profile-images/aaronparecki.com/image'))) {
|
||||||
$fileSystem->copy('./tests/aaron.png', 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);
|
$this->app->instance(Client::class, $client);
|
||||||
|
|
||||||
$note = new Note();
|
$note = new Note;
|
||||||
$address = $note->reverseGeoCode(51.50084, -0.14264);
|
$address = $note->reverseGeoCode(51.50084, -0.14264);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
|
@ -226,7 +226,7 @@ class NotesTest extends TestCase
|
||||||
|
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
|
||||||
$note = new Note();
|
$note = new Note;
|
||||||
$address = $note->reverseGeoCode(51.02, 0.91);
|
$address = $note->reverseGeoCode(51.02, 0.91);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
|
@ -253,7 +253,7 @@ class NotesTest extends TestCase
|
||||||
|
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
|
||||||
$note = new Note();
|
$note = new Note;
|
||||||
$address = $note->reverseGeoCode(53.466277988406, -2.2304474827445);
|
$address = $note->reverseGeoCode(53.466277988406, -2.2304474827445);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
|
@ -280,7 +280,7 @@ class NotesTest extends TestCase
|
||||||
|
|
||||||
$this->app->instance(Client::class, $client);
|
$this->app->instance(Client::class, $client);
|
||||||
|
|
||||||
$note = new Note();
|
$note = new Note;
|
||||||
$address = $note->reverseGeoCode(51.1, 0.61);
|
$address = $note->reverseGeoCode(51.1, 0.61);
|
||||||
|
|
||||||
$this->assertEquals('<span class="p-region">Kent</span>, <span class="p-country-name">UK</span>', $address);
|
$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);
|
$this->app->instance(Client::class, $client);
|
||||||
|
|
||||||
$note = new Note();
|
$note = new Note;
|
||||||
$address = $note->reverseGeoCode(54.3, 9.4);
|
$address = $note->reverseGeoCode(54.3, 9.4);
|
||||||
|
|
||||||
$this->assertEquals('<span class="p-country-name">Ireland</span>', $address);
|
$this->assertEquals('<span class="p-country-name">Ireland</span>', $address);
|
||||||
|
|
@ -323,7 +323,7 @@ class NotesTest extends TestCase
|
||||||
$note->media()->save($media);
|
$note->media()->save($media);
|
||||||
|
|
||||||
$expected = 'A nice image
|
$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);
|
$this->assertEquals($expected, $note->content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -340,7 +340,7 @@ class NotesTest extends TestCase
|
||||||
$note->media()->save($media);
|
$note->media()->save($media);
|
||||||
|
|
||||||
$expected = 'A nice video
|
$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);
|
$this->assertEquals($expected, $note->content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -357,7 +357,7 @@ class NotesTest extends TestCase
|
||||||
$note->media()->save($media);
|
$note->media()->save($media);
|
||||||
|
|
||||||
$expected = 'Some nice audio
|
$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);
|
$this->assertEquals($expected, $note->content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -368,7 +368,7 @@ class NotesTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function provideTextForBlankContent(): void
|
public function provideTextForBlankContent(): void
|
||||||
{
|
{
|
||||||
$note = new Note();
|
$note = new Note;
|
||||||
|
|
||||||
$this->assertEquals('A blank note', $note->content);
|
$this->assertEquals('A blank note', $note->content);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,13 +71,13 @@ class PlacesTest extends TestCase
|
||||||
{
|
{
|
||||||
Place::factory(10)->create();
|
Place::factory(10)->create();
|
||||||
|
|
||||||
$place = new Place();
|
$place = new Place;
|
||||||
$place->name = 'Temp Place';
|
$place->name = 'Temp Place';
|
||||||
$place->latitude = 37.422009;
|
$place->latitude = 37.422009;
|
||||||
$place->longitude = -122.084047;
|
$place->longitude = -122.084047;
|
||||||
$place->external_urls = 'https://www.openstreetmap.org/way/1234';
|
$place->external_urls = 'https://www.openstreetmap.org/way/1234';
|
||||||
$place->save();
|
$place->save();
|
||||||
$service = new PlaceService();
|
$service = new PlaceService;
|
||||||
$ret = $service->createPlaceFromCheckin([
|
$ret = $service->createPlaceFromCheckin([
|
||||||
'properties' => [
|
'properties' => [
|
||||||
'url' => ['https://www.openstreetmap.org/way/1234'],
|
'url' => ['https://www.openstreetmap.org/way/1234'],
|
||||||
|
|
@ -92,7 +92,7 @@ class PlacesTest extends TestCase
|
||||||
$this->expectException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
$this->expectExceptionMessage('Missing required name');
|
$this->expectExceptionMessage('Missing required name');
|
||||||
|
|
||||||
$service = new PlaceService();
|
$service = new PlaceService;
|
||||||
$service->createPlaceFromCheckin(['foo' => 'bar']);
|
$service->createPlaceFromCheckin(['foo' => 'bar']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,7 +102,7 @@ class PlacesTest extends TestCase
|
||||||
$this->expectException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
$this->expectExceptionMessage('Missing required longitude/latitude');
|
$this->expectExceptionMessage('Missing required longitude/latitude');
|
||||||
|
|
||||||
$service = new PlaceService();
|
$service = new PlaceService;
|
||||||
$service->createPlaceFromCheckin(['properties' => ['name' => 'bar']]);
|
$service->createPlaceFromCheckin(['properties' => ['name' => 'bar']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class WebMentionTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function publishedAttributeUsesUpdatedAtWhenNoRelevantMf2Data(): void
|
public function publishedAttributeUsesUpdatedAtWhenNoRelevantMf2Data(): void
|
||||||
{
|
{
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$updated_at = Carbon::now();
|
$updated_at = Carbon::now();
|
||||||
$webmention->updated_at = $updated_at;
|
$webmention->updated_at = $updated_at;
|
||||||
$this->assertEquals($updated_at->toDayDateTimeString(), $webmention->published);
|
$this->assertEquals($updated_at->toDayDateTimeString(), $webmention->published);
|
||||||
|
|
@ -39,7 +39,7 @@ class WebMentionTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function publishedAttributeUsesUpdatedAtWhenErrorParsingMf2Data(): void
|
public function publishedAttributeUsesUpdatedAtWhenErrorParsingMf2Data(): void
|
||||||
{
|
{
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$updated_at = Carbon::now();
|
$updated_at = Carbon::now();
|
||||||
$webmention->updated_at = $updated_at;
|
$webmention->updated_at = $updated_at;
|
||||||
$webmention->mf2 = json_encode([
|
$webmention->mf2 = json_encode([
|
||||||
|
|
@ -57,7 +57,7 @@ class WebMentionTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function createPhotoLinkDoesNothingWithGenericUrlAndNoLocallySavedImage(): void
|
public function createPhotoLinkDoesNothingWithGenericUrlAndNoLocallySavedImage(): void
|
||||||
{
|
{
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$homepage = 'https://example.org/profile.png';
|
$homepage = 'https://example.org/profile.png';
|
||||||
$expected = 'https://example.org/profile.png';
|
$expected = 'https://example.org/profile.png';
|
||||||
$this->assertEquals($expected, $webmention->createPhotoLink($homepage));
|
$this->assertEquals($expected, $webmention->createPhotoLink($homepage));
|
||||||
|
|
@ -66,7 +66,7 @@ class WebMentionTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function createPhotoLinkReturnsLocallySavedImageUrlIfItExists(): void
|
public function createPhotoLinkReturnsLocallySavedImageUrlIfItExists(): void
|
||||||
{
|
{
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$homepage = 'https://aaronparecki.com/profile.png';
|
$homepage = 'https://aaronparecki.com/profile.png';
|
||||||
$expected = '/assets/profile-images/aaronparecki.com/image';
|
$expected = '/assets/profile-images/aaronparecki.com/image';
|
||||||
$this->assertEquals($expected, $webmention->createPhotoLink($homepage));
|
$this->assertEquals($expected, $webmention->createPhotoLink($homepage));
|
||||||
|
|
@ -75,7 +75,7 @@ class WebMentionTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function createPhotoLinkDealsWithSpecialCaseOfDirectTwitterPhotoLinks(): void
|
public function createPhotoLinkDealsWithSpecialCaseOfDirectTwitterPhotoLinks(): void
|
||||||
{
|
{
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$twitterProfileImage = 'http://pbs.twimg.com/1234';
|
$twitterProfileImage = 'http://pbs.twimg.com/1234';
|
||||||
$expected = 'https://pbs.twimg.com/1234';
|
$expected = 'https://pbs.twimg.com/1234';
|
||||||
$this->assertEquals($expected, $webmention->createPhotoLink($twitterProfileImage));
|
$this->assertEquals($expected, $webmention->createPhotoLink($twitterProfileImage));
|
||||||
|
|
@ -84,7 +84,7 @@ class WebMentionTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function createPhotoLinkReturnsCachedTwitterPhotoLinks(): void
|
public function createPhotoLinkReturnsCachedTwitterPhotoLinks(): void
|
||||||
{
|
{
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$twitterURL = 'https://twitter.com/example';
|
$twitterURL = 'https://twitter.com/example';
|
||||||
$expected = 'https://pbs.twimg.com/static_profile_link.jpg';
|
$expected = 'https://pbs.twimg.com/static_profile_link.jpg';
|
||||||
Cache::put($twitterURL, $expected, 1);
|
Cache::put($twitterURL, $expected, 1);
|
||||||
|
|
@ -111,7 +111,7 @@ class WebMentionTest extends TestCase
|
||||||
->once()
|
->once()
|
||||||
->andReturn(true);
|
->andReturn(true);
|
||||||
|
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$twitterURL = 'https://twitter.com/example';
|
$twitterURL = 'https://twitter.com/example';
|
||||||
$expected = 'https://pbs.twimg.com/static_profile_link.jpg';
|
$expected = 'https://pbs.twimg.com/static_profile_link.jpg';
|
||||||
$this->assertEquals($expected, $webmention->createPhotoLink($twitterURL));
|
$this->assertEquals($expected, $webmention->createPhotoLink($twitterURL));
|
||||||
|
|
@ -120,14 +120,14 @@ class WebMentionTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function getReplyAttributeDefaultsToNull(): void
|
public function getReplyAttributeDefaultsToNull(): void
|
||||||
{
|
{
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$this->assertNull($webmention->reply);
|
$this->assertNull($webmention->reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function getReplyAttributeWithMf2WithoutHtmlReturnsNull(): void
|
public function getReplyAttributeWithMf2WithoutHtmlReturnsNull(): void
|
||||||
{
|
{
|
||||||
$webmention = new WebMention();
|
$webmention = new WebMention;
|
||||||
$webmention->mf2 = json_encode(['no_html' => 'found_here']);
|
$webmention->mf2 = json_encode(['no_html' => 'found_here']);
|
||||||
$this->assertNull($webmention->reply);
|
$this->assertNull($webmention->reply);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue