Squashed commit of the following: commit 504fb82beea5eff26591e117496d41c88f3737e4 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Fri Jan 25 16:59:05 2019 +0000 Fix coding style issue commit 0ae14f0d90f131d65894abdc36f787032c7c97db Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Fri Jan 25 16:57:26 2019 +0000 html-sanitizer output differs slightly from HTMLPurifier commit c5912312e0c8a41dbd7f7e52489e516d9784bc26 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Fri Jan 25 16:56:54 2019 +0000 Use html-sanitizer instead of HTMLPruifier, consolidate logic into a trait commit 563b5b5ae8e2ef9c5aeb87214acab8fa9b0683ce Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Fri Jan 25 16:56:10 2019 +0000 Add html-sanitizer instead of HTMLPurifier
53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use Tests\TestCase;
|
|
use App\Models\Like;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
class LikesTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function test_setting_author_url()
|
|
{
|
|
$like = new Like();
|
|
$like->author_url = 'https://joe.bloggs/';
|
|
$this->assertEquals('https://joe.bloggs', $like->author_url);
|
|
}
|
|
|
|
public function test_plaintext_like_content()
|
|
{
|
|
$like = new Like();
|
|
$like->url = 'https://example.org/post/123';
|
|
$like->content = 'some plaintext content';
|
|
$like->save();
|
|
|
|
$this->assertEquals('some plaintext content', $like->content);
|
|
}
|
|
|
|
public function test_html_like_content_is_filtered()
|
|
{
|
|
$htmlEvil = <<<HTML
|
|
<div class="h-entry">
|
|
<div class="e-content">
|
|
<p>Hello</p>
|
|
<img src="javascript:evil();" onload="evil();" />
|
|
</div>
|
|
</div>
|
|
HTML;
|
|
$htmlFiltered = <<<HTML
|
|
<p>Hello</p>
|
|
<img />
|
|
HTML;
|
|
$like = new Like();
|
|
$like->url = 'https://example.org/post/123';
|
|
$like->content = $htmlEvil;
|
|
$like->save();
|
|
|
|
// HTMLPurifer will leave the whitespace before the <img> tag
|
|
// trim it, saving whitespace in $htmlFilteres can get removed by text editors
|
|
$this->assertEquals($htmlFiltered, trim($like->content));
|
|
}
|
|
}
|