1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-03-15 12:19:39 +01:00
LinkAce/tests/Models/LinkCreateTest.php
Kovah 113b30120d
Update to Laravel 8, refactor tests to use new factory classes
Also updates all other needed packages.
2020-11-08 20:10:42 +01:00

67 lines
1.6 KiB
PHP

<?php
namespace Tests\Models;
use App\Helper\HtmlMeta;
use App\Helper\LinkIconMapper;
use App\Models\User;
use App\Repositories\LinkRepository;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class LinkCreateTest extends TestCase
{
use DatabaseMigrations;
use DatabaseTransactions;
/** @var User */
private $user;
public function setUp(): void
{
parent::setUp();
$testHtml = '<!DOCTYPE html><head><title>Google</title></head></html>';
Http::fake([
'*' => Http::response($testHtml, 200),
]);
$this->user = User::factory()->create();
}
public function testValidLinkCreation(): void
{
$this->be($this->user);
$url = 'https://google.com/';
$meta = HtmlMeta::getFromUrl($url);
$originalData = [
'url' => $url,
'title' => $meta['title'],
'description' => $meta['description'],
'is_private' => false,
];
$link = LinkRepository::create($originalData);
$automatedData = [
'id' => $link->id,
'icon' => LinkIconMapper::mapLink($url),
'user_id' => auth()->user()->id,
'status' => 1,
'created_at' => $link->created_at,
'updated_at' => $link->updated_at,
'deleted_at' => null,
];
$assertedData = array_merge($automatedData, $originalData);
$this->assertDatabaseHas('links', $assertedData);
}
}