Upload beautify
This commit is contained in:
56
tests/Feature/ContentRouterControllerTest.php
Normal file
56
tests/Feature/ContentRouterControllerTest.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\ContentRouterController;
|
||||
use App\Models\Artwork;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('handles model-bound artwork parameter without 404 fallback', function () {
|
||||
$artwork = Artwork::factory()->create([
|
||||
'slug' => 'bound-model-artwork',
|
||||
'is_public' => true,
|
||||
'is_approved' => true,
|
||||
'published_at' => now()->subMinute(),
|
||||
]);
|
||||
|
||||
$request = Request::create('/photography/abstract/bound-model-artwork', 'GET');
|
||||
|
||||
$response = app(ContentRouterController::class)->handle(
|
||||
$request,
|
||||
'photography',
|
||||
'abstract',
|
||||
$artwork
|
||||
);
|
||||
|
||||
expect($response)->toBeInstanceOf(View::class);
|
||||
expect($response->name())->toBe('artworks.show');
|
||||
expect($response->getData()['artwork']->id)->toBe($artwork->id);
|
||||
});
|
||||
|
||||
it('binds routed artwork model and renders published artwork page', function () {
|
||||
$artwork = Artwork::factory()->create([
|
||||
'title' => 'Routed Binding Artwork',
|
||||
'slug' => 'routed-binding-artwork',
|
||||
'is_public' => true,
|
||||
'is_approved' => true,
|
||||
'published_at' => now()->subMinute(),
|
||||
]);
|
||||
|
||||
$url = route('artworks.show', [
|
||||
'contentTypeSlug' => 'photography',
|
||||
'categoryPath' => 'abstract',
|
||||
'artwork' => $artwork->slug,
|
||||
]);
|
||||
|
||||
$matchedRoute = app('router')->getRoutes()->match(Request::create($url, 'GET'));
|
||||
app('router')->substituteBindings($matchedRoute);
|
||||
expect($matchedRoute->parameter('artwork'))->toBeInstanceOf(Artwork::class);
|
||||
expect($matchedRoute->parameter('artwork')->id)->toBe($artwork->id);
|
||||
|
||||
$this->get($url)
|
||||
->assertOk()
|
||||
->assertSee('Routed Binding Artwork');
|
||||
});
|
||||
Reference in New Issue
Block a user