Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Return 404 if a custom script or style is not found #375

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Http/Controllers/ScriptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class ScriptController extends Controller
public function __invoke(Request $request)
{
return response(
file_get_contents(LaRecipe::allScripts()[$request->script]),
200, ['Content-Type' => 'application/javascript']
file_get_contents(LaRecipe::allScripts()[$request->script] ?? abort(404)),
200,
['Content-Type' => 'application/javascript']
);
}
}
5 changes: 3 additions & 2 deletions src/Http/Controllers/StyleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class StyleController extends Controller
public function __invoke(Request $request)
{
return response(
file_get_contents(LaRecipe::allStyles()[$request->style]),
200, ['Content-Type' => 'text/css']
file_get_contents(LaRecipe::allStyles()[$request->style] ?? abort(404)),
200,
['Content-Type' => 'text/css']
);
}
}
27 changes: 27 additions & 0 deletions tests/Feature/CustomScriptsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace BinaryTorch\LaRecipe\Tests\Feature;

use BinaryTorch\LaRecipe\LaRecipe;
use BinaryTorch\LaRecipe\Tests\TestCase;

class CustomScriptsTest extends TestCase
{
/** @test */
public function a_script_not_found_returns_404()
{
$this->get('/docs/scripts/not-found')
->assertNotFound();
}

/** @test */
public function a_script_is_returned()
{
LaRecipe::script('custom-script', __DIR__ . '/../theme/resources/js/custom.js');

$this->get('/docs/scripts/custom-script')
->assertOk()
->assertHeader('Content-Type', 'application/javascript')
->assertSee('Custom JS');
}
}
27 changes: 27 additions & 0 deletions tests/Feature/CustomStylesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace BinaryTorch\LaRecipe\Tests\Feature;

use BinaryTorch\LaRecipe\LaRecipe;
use BinaryTorch\LaRecipe\Tests\TestCase;

class CustomStylesTest extends TestCase
{
/** @test */
public function a_style_not_found_returns_404()
{
$this->get('/docs/styles/not-found')
->assertNotFound();
}

/** @test */
public function a_style_is_returned()
{
LaRecipe::style('custom-style', __DIR__ . '/../theme/resources/css/custom.css');

$this->get('/docs/styles/custom-style')
->assertOk()
->assertHeader('Content-Type', 'text/css; charset=UTF-8')
->assertSee('Custom CSS');
}
}
1 change: 1 addition & 0 deletions tests/theme/resources/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** Custom CSS **/
1 change: 1 addition & 0 deletions tests/theme/resources/js/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Custom JS