generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f41628c
commit 69e3b9c
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
use Inertia\Testing\AssertableInertia as Assert; | ||
use Modules\User\Models\User; | ||
|
||
beforeEach(function () { | ||
$this->user = User::factory()->create(); | ||
$this->loggedRequest = $this->actingAs($this->user); | ||
}); | ||
|
||
it('can render the dashboard page', function () { | ||
$dashboardUrl = route(config('modular.default-logged-route')); | ||
$response = $this->loggedRequest->get($dashboardUrl); | ||
|
||
$response->assertStatus(200); | ||
|
||
$response->assertInertia( | ||
fn (Assert $page) => $page | ||
->component('Dashboard/DashboardIndex') | ||
->has( | ||
'auth.user', | ||
fn (Assert $page) => $page | ||
->where('id', $this->user->id) | ||
->where('name', $this->user->name) | ||
->etc() | ||
) | ||
->has( | ||
'auth.permissions', | ||
) | ||
->has( | ||
'errors', | ||
) | ||
->has( | ||
'flash', | ||
2, | ||
) | ||
->has( | ||
'ziggy.routes', | ||
) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
use Illuminate\Http\UploadedFile; | ||
use Modules\Support\Traits\EditorImage; | ||
|
||
use function PHPUnit\Framework\assertFileExists; | ||
|
||
uses(EditorImage::class); | ||
|
||
beforeEach(function () { | ||
(new Filesystem)->deleteDirectory(storage_path('editor-files')); | ||
}); | ||
|
||
afterAll(function () { | ||
(new Filesystem)->deleteDirectory(storage_path('editor-files')); | ||
}); | ||
|
||
it('can upload an image to the default editor media file path', function () { | ||
$file = UploadedFile::fake()->image('A nice file.jpg'); | ||
|
||
$result = $this->uploadImage($file, 'original'); | ||
|
||
expect($result)->toHaveKeys(['fileName', 'filePath', 'fileUrl', 'readableName']); | ||
expect($result['readableName'])->toBe('A nice file'); | ||
assertFileExists($result['filePath']); | ||
}); |
24 changes: 24 additions & 0 deletions
24
stubs/tests/Feature/Support/FileNameGeneratorTraitTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
use Illuminate\Http\UploadedFile; | ||
use Modules\Support\Traits\FileNameGenerator; | ||
|
||
beforeEach(function () { | ||
(new Filesystem)->deleteDirectory(storage_path('editor-files')); | ||
}); | ||
|
||
afterAll(function () { | ||
(new Filesystem)->deleteDirectory(storage_path('editor-files')); | ||
}); | ||
|
||
uses(FileNameGenerator::class); | ||
|
||
it('can set the name of a uploaded file', function () { | ||
$file = UploadedFile::fake()->image('A nice file.jpg'); | ||
|
||
$readableName = $this->getReadableName($file); | ||
$fileName = $this->getFileName($file, $readableName, 'original'); | ||
|
||
expect($fileName)->toBe('a-nice-file.jpg'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
use Modules\Support\Traits\UploadFile; | ||
|
||
uses(UploadFile::class); | ||
|
||
beforeEach(function () { | ||
(new Filesystem)->deleteDirectory(storage_path('user-files')); | ||
}); | ||
|
||
afterAll(function () { | ||
(new Filesystem)->deleteDirectory(storage_path('user-files')); | ||
}); | ||
|
||
it('can handle requests without uploads', function () { | ||
$result = $this->uploadFile(''); | ||
|
||
expect($result)->toBe([]); | ||
}); | ||
|
||
it('can handle requests with wrong inputs', function () { | ||
request('file', 'not an uploaded file'); | ||
|
||
$result = $this->uploadFile('file'); | ||
|
||
expect($result)->toBe([]); | ||
}); |