2019-03-22 21:01:55 +01:00
|
|
|
<?php
|
|
|
|
|
2020-06-05 14:19:29 +02:00
|
|
|
namespace Tests\Models;
|
2019-03-22 21:01:55 +01:00
|
|
|
|
2020-04-29 19:14:42 +02:00
|
|
|
use App\Helper\HtmlMeta;
|
2019-03-22 21:01:55 +01:00
|
|
|
use App\Helper\LinkIconMapper;
|
|
|
|
use App\Models\User;
|
2019-07-15 16:12:54 +02:00
|
|
|
use App\Repositories\LinkRepository;
|
2019-03-22 21:01:55 +01:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2020-03-04 15:26:31 +01:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2019-03-22 21:01:55 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class LinkCreateTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseMigrations;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
/** @var User */
|
|
|
|
private $user;
|
|
|
|
|
2019-07-16 19:33:47 +02:00
|
|
|
public function setUp(): void
|
2019-03-22 21:01:55 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-03-04 15:26:31 +01:00
|
|
|
|
|
|
|
$testHtml = '<!DOCTYPE html><head><title>Google</title></head></html>';
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
'*' => Http::response($testHtml, 200),
|
|
|
|
]);
|
2019-03-22 21:01:55 +01:00
|
|
|
|
2020-11-08 20:10:42 +01:00
|
|
|
$this->user = User::factory()->create();
|
2019-03-22 21:01:55 +01:00
|
|
|
}
|
|
|
|
|
2019-07-16 19:33:47 +02:00
|
|
|
public function testValidLinkCreation(): void
|
2019-03-22 21:01:55 +01:00
|
|
|
{
|
2019-07-15 16:12:54 +02:00
|
|
|
$this->be($this->user);
|
|
|
|
|
2019-03-22 21:01:55 +01:00
|
|
|
$url = 'https://google.com/';
|
|
|
|
|
2020-04-29 19:14:42 +02:00
|
|
|
$meta = HtmlMeta::getFromUrl($url);
|
2019-03-22 21:01:55 +01:00
|
|
|
|
2020-06-05 14:19:29 +02:00
|
|
|
$originalData = [
|
2019-03-22 21:01:55 +01:00
|
|
|
'url' => $url,
|
|
|
|
'title' => $meta['title'],
|
|
|
|
'description' => $meta['description'],
|
|
|
|
'is_private' => false,
|
|
|
|
];
|
|
|
|
|
2020-06-05 14:19:29 +02:00
|
|
|
$link = LinkRepository::create($originalData);
|
2019-03-22 21:01:55 +01:00
|
|
|
|
2020-06-05 14:19:29 +02:00
|
|
|
$automatedData = [
|
2019-03-22 21:01:55 +01:00
|
|
|
'id' => $link->id,
|
2019-07-15 16:12:54 +02:00
|
|
|
'icon' => LinkIconMapper::mapLink($url),
|
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'status' => 1,
|
2019-03-22 21:01:55 +01:00
|
|
|
'created_at' => $link->created_at,
|
|
|
|
'updated_at' => $link->updated_at,
|
|
|
|
'deleted_at' => null,
|
|
|
|
];
|
|
|
|
|
2020-06-05 14:19:29 +02:00
|
|
|
$assertedData = array_merge($automatedData, $originalData);
|
2019-03-22 21:01:55 +01:00
|
|
|
|
2020-06-05 14:19:29 +02:00
|
|
|
$this->assertDatabaseHas('links', $assertedData);
|
2019-03-22 21:01:55 +01:00
|
|
|
}
|
|
|
|
}
|