jonnybarnes.uk/tests/Feature/ParseCachedWebMentionsTest.php
Jonny Barnes c96ba5e82a Fixing tests
Most were a case of adding void return statement to setUp and tearDown,
also needed to add 6th `null` param to indieauth method. Its for
code_verifier, issue created to work out what I should actually be doing
with that.
2019-03-17 14:06:18 +00:00

58 lines
2.4 KiB
PHP

<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Models\WebMention;
use Illuminate\FileSystem\FileSystem;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ParseCachedWebMentionsTest extends TestCase
{
use DatabaseTransactions;
protected function setUp(): void
{
parent::setUp();
mkdir(storage_path('HTML') . '/https/aaronpk.localhost/reply', 0777, true);
mkdir(storage_path('HTML') . '/http/tantek.com', 0777, true);
copy(__DIR__.'/../aaron.html', storage_path('HTML') . '/https/aaronpk.localhost/reply/1');
copy(__DIR__.'/../tantek.html', storage_path('HTML') . '/http/tantek.com/index.html');
}
public function test_parsing_html()
{
$this->assertFileExists(storage_path('HTML') . '/https/aaronpk.localhost/reply/1');
$this->assertFileExists(storage_path('HTML') . '/http/tantek.com/index.html');
$htmlAaron = file_get_contents(storage_path('HTML') . '/https/aaronpk.localhost/reply/1');
$htmlAaron = str_replace('href="/notes', 'href="' . config('app.url') . '/notes', $htmlAaron);
$htmlAaron = str_replace('datetime=""', 'dateime="' . carbon()->now()->toIso8601String() . '"', $htmlAaron);
file_put_contents(storage_path('HTML') . '/https/aaronpk.localhost/reply/1', $htmlAaron);
$htmlTantek = file_get_contents(storage_path('HTML') . '/http/tantek.com/index.html');
$htmlTantek = str_replace('href="/notes', 'href="' . config('app.url') . '/notes', $htmlTantek);
$htmlTantek = str_replace('datetime=""', 'dateime="' . carbon()->now()->toIso8601String() . '"', $htmlTantek);
file_put_contents(storage_path('HTML') . '/http/tantek.com/index.html', $htmlTantek);
Artisan::call('webmentions:parsecached');
$webmentionAaron = WebMention::find(1);
$webmentionTantek = WebMention::find(2);
$this->assertTrue($webmentionAaron->updated_at->gt($webmentionAaron->created_at));
$this->assertTrue($webmentionTantek->updated_at->gt($webmentionTantek->created_at));
}
protected function tearDown(): void
{
$fs = new FileSystem();
if ($fs->exists(storage_path() . '/HTML/https')) {
$fs->deleteDirectory(storage_path() . '/HTML/https');
}
if ($fs->exists(storage_path() . '/HTML/http')) {
$fs->deleteDirectory(storage_path() . '/HTML/http');
}
parent::tearDown();
}
}