Replaces every raw GuzzleHttp\Client usage (Nominatim, web.archive.org, webmention fetch/discover/send, Bridgy syndication, IndieAuth client_id lookup, contact avatar/h-card fetch, profile image download, and the CloudConvert screenshot pipeline) with Illuminate\Support\Facades\Http, and enables Http::preventStrayRequests() globally in tests so any un-faked outbound call now fails loudly instead of silently hitting the network. The CloudConvert retry-until-finished middleware in AppServiceProvider is replaced by a plain polling loop in SaveScreenshot, which also fixes a latent bug where the old middleware decoded a response object instead of its body. Bridgy syndication jobs keep their tries=1/no-retry semantics unchanged to avoid duplicate publishes. Guzzle's PSR-7 helpers (Header, UriResolver, Utils) stay in SendWebMentions since Http has no equivalent for them. Every affected test file's Guzzle MockHandler/HandlerStack boilerplate is replaced with Http::fake()/Http::sequence(). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P8j7cJhCiYDsGUgB7obKNQ
103 lines
3.1 KiB
PHP
103 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Jobs;
|
|
|
|
use App\Jobs\DownloadWebMention;
|
|
use Illuminate\FileSystem\FileSystem;
|
|
use Illuminate\Support\Facades\Http;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Tests\TestCase;
|
|
|
|
class DownloadWebMentionJobTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
$fs = new FileSystem;
|
|
if ($fs->exists(storage_path().'/HTML/https')) {
|
|
$fs->deleteDirectory(storage_path().'/HTML/https');
|
|
}
|
|
parent::tearDown();
|
|
}
|
|
|
|
#[Test]
|
|
public function html_is_saved_by_job(): void
|
|
{
|
|
$this->assertFileDoesNotExist(storage_path('HTML/https'));
|
|
$source = 'https://example.org/reply/1';
|
|
$html = <<<'HTML'
|
|
<div class="h-entry">
|
|
<a class="u-like-of" href=""></a>
|
|
</div>
|
|
HTML;
|
|
$html = str_replace('href=""', 'href="'.config('app.url').'/notes/A"', $html);
|
|
Http::fake([
|
|
'example.org/*' => Http::response($html, 200, ['X-Foo' => 'Bar']),
|
|
]);
|
|
|
|
$job = new DownloadWebMention($source);
|
|
$job->handle();
|
|
|
|
$this->assertFileExists(storage_path('HTML/https'));
|
|
|
|
$job->handle();
|
|
|
|
$this->assertFileDoesNotExist(storage_path('HTML/https/example.org/reply').'/1.'.date('Y-m-d').'.backup');
|
|
}
|
|
|
|
#[Test]
|
|
public function html_and_backup_saved_by_job(): void
|
|
{
|
|
$this->assertFileDoesNotExist(storage_path('HTML/https'));
|
|
$source = 'https://example.org/reply/1';
|
|
$html = <<<'HTML'
|
|
<div class="h-entry">
|
|
<a class="u-like-of" href=""></a>
|
|
</div>
|
|
HTML;
|
|
$html2 = <<<'HTML'
|
|
<div class="h-entry">
|
|
<a class="u-like-of" href=""></a>
|
|
<a class="u-repost-of" href=""></a>
|
|
</div>
|
|
HTML;
|
|
$html = str_replace('href=""', 'href="'.config('app.url').'/notes/A"', $html);
|
|
$html2 = str_replace('href=""', 'href="'.config('app.url').'/notes/A"', $html2);
|
|
Http::fake([
|
|
'example.org/*' => Http::sequence()
|
|
->push($html, 200, ['X-Foo' => 'Bar'])
|
|
->push($html2, 200, ['X-Foo' => 'Bar']),
|
|
]);
|
|
|
|
$job = new DownloadWebMention($source);
|
|
$job->handle();
|
|
|
|
$this->assertFileExists(storage_path('HTML/https'));
|
|
|
|
$job->handle();
|
|
|
|
$this->assertFileExists(storage_path('HTML/https/example.org/reply').'/1.'.date('Y-m-d').'.backup');
|
|
}
|
|
|
|
#[Test]
|
|
public function index_html_file_is_saved_by_job_for_urls_ending_with_slash(): void
|
|
{
|
|
$this->assertFileDoesNotExist(storage_path('HTML/https'));
|
|
$source = 'https://example.org/reply-one/';
|
|
$html = <<<'HTML'
|
|
<div class="h-entry">
|
|
<a class="u-like-of" href=""></a>
|
|
</div>
|
|
HTML;
|
|
$html = str_replace('href=""', 'href="'.config('app.url').'/notes/A"', $html);
|
|
Http::fake([
|
|
'example.org/*' => Http::response($html, 200, ['X-Foo' => 'Bar']),
|
|
]);
|
|
|
|
$job = new DownloadWebMention($source);
|
|
$job->handle();
|
|
|
|
$this->assertFileExists(storage_path('HTML/https/example.org/reply-one/index.html'));
|
|
}
|
|
}
|