1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-03-15 12:19:39 +01:00
LinkAce/tests/Models/LinkCreateTest.php

67 lines
1.6 KiB
PHP
Raw Normal View History

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
use App\Helper\HtmlMeta;
2019-03-22 21:01:55 +01:00
use App\Helper\LinkIconMapper;
use App\Models\User;
use App\Repositories\LinkRepository;
2019-03-22 21:01:55 +01:00
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
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;
public function setUp(): void
2019-03-22 21:01:55 +01:00
{
parent::setUp();
$testHtml = '<!DOCTYPE html><head><title>Google</title></head></html>';
Http::fake([
'*' => Http::response($testHtml, 200),
]);
2019-03-22 21:01:55 +01:00
$this->user = User::factory()->create();
2019-03-22 21:01:55 +01:00
}
public function testValidLinkCreation(): void
2019-03-22 21:01:55 +01:00
{
$this->be($this->user);
2019-03-22 21:01:55 +01:00
$url = 'https://google.com/';
$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,
'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
}
}