Redo Notes a little, improve tests

This commit is contained in:
Jonny Barnes 2021-04-29 20:02:20 +01:00
parent 751f725bfa
commit 0391cf80de
5 changed files with 107 additions and 27 deletions

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Tests\Unit;
use Illuminate\Support\Facades\Cache;
use App\Models\{Media, Note, Tag};
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
@ -334,4 +335,47 @@ class NotesTest extends TestCase
$note->note
);
}
/**
* For now, just reply on a cached object instead of actually querying Twitter.
*
* @test
*/
public function checkInReplyToIsTwitterLink(): void
{
$tempContent = (object) [
'html' => 'something random',
];
Cache::put('933662564587855877', $tempContent);
$note = Note::find(1);
$this->assertSame($tempContent, $note->twitter);
}
/** @test */
public function latitudeCanBeParsedFromPlainLocation(): void
{
$note = Note::find(18);
$this->assertSame(1.23, $note->latitude);
}
/** @test */
public function longitudeCanBeParsedFromPlainLocation(): void
{
$note = Note::find(18);
$this->assertSame(4.56, $note->longitude);
}
/** @test */
public function addressAttributeCanBeRetrievedFromPlainLocation(): void
{
Cache::put('1.23,4.56', '<span class="p-country-name">Antarctica</span>');
$note = Note::find(18);
$this->assertSame('<span class="p-country-name">Antarctica</span>', $note->address);
}
}

View file

@ -22,4 +22,25 @@ class TagsTest extends TestCase
$tag = Tag::find(5); //should be first random tag for bookmarks
$this->assertCount(1, $tag->bookmarks);
}
/**
* @test
* @dataProvider tagsProvider
* @param string $input
* @param string $expected
*/
public function canNormalize(string $input, string $expected): void
{
$this->assertSame($expected, Tag::normalize($input));
}
public function tagsProvider(): array
{
return [
['test', 'test'],
['Test', 'test'],
['Tést', 'test'],
['MultiWord', 'multiword'],
];
}
}