medialibrary-helper/tests/TestCase.php

63 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2023-03-07 15:31:24 +01:00
<?php
namespace Zoomyboy\MedialibraryHelper\Tests;
use Illuminate\Http\File;
use Illuminate\Support\Facades\Gate;
2024-01-03 11:10:59 +01:00
use Orchestra\Testbench\Concerns\WithWorkbench;
2023-03-07 15:31:24 +01:00
use Orchestra\Testbench\TestCase as BaseTestCase;
2024-01-03 11:10:59 +01:00
use Workbench\App\Models\Post;
2024-01-03 13:07:03 +01:00
use Workbench\App\Models\User;
2023-03-07 15:31:24 +01:00
class TestCase extends BaseTestCase
{
2024-01-03 11:10:59 +01:00
use WithWorkbench;
2023-03-07 15:31:24 +01:00
/**
2023-03-07 23:11:35 +01:00
* Generate a pdf file with a filename and get path.
2023-03-07 15:31:24 +01:00
*/
protected function pdfFile(?string $filename = null): File
{
return $this->getFile('pdf.pdf', $filename ?: 'pdf.pdf');
}
2023-03-08 00:58:15 +01:00
protected function jpgFile(?string $filename = null): File
{
return $this->getFile('jpg.jpg', $filename ?: 'jpg.jpg');
}
2024-07-13 19:38:51 +02:00
protected function pngFile(?string $filename = null): File
{
return $this->getFile('png.png', $filename ?: 'png.png');
}
2023-03-07 15:31:24 +01:00
protected function getFile(string $location, string $as): File
{
2024-01-02 01:28:49 +01:00
$path = __DIR__ . '/stubs/' . $location;
$to = sys_get_temp_dir() . '/' . $as;
2023-03-07 15:31:24 +01:00
copy($path, $to);
return new File($to);
}
protected function registerModel(): static
{
app()->extend('media-library-helpers', fn ($p) => $p->put('post', Post::class));
return $this;
}
protected function newPost(): Post
{
return Post::create(['title' => 'Lorem', 'content' => 'aafff']);
}
protected function auth(array $policies = []): self
{
2024-01-03 13:42:29 +01:00
$this->be(User::factory()->policies($policies)->create());
2023-03-07 15:31:24 +01:00
return $this;
}
}