mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:34:03 +00:00
Write test for specifying headers in TenantAssetController, fix error introduced in previous commit
This commit is contained in:
parent
a39da042af
commit
cc2d555e3e
2 changed files with 27 additions and 2 deletions
|
|
@ -16,7 +16,6 @@ class TenantAssetController implements HasMiddleware // todo@docs this was renam
|
|||
{
|
||||
/**
|
||||
* Used for adding custom headers to the response.
|
||||
* todo@tests add a test for this
|
||||
*
|
||||
* @var (Closure(Request): array)|null
|
||||
*/
|
||||
|
|
@ -33,7 +32,7 @@ class TenantAssetController implements HasMiddleware // todo@docs this was renam
|
|||
{
|
||||
return [
|
||||
new Middleware(array_merge(
|
||||
tenancy()->defaultMiddleware(),
|
||||
[tenancy()->defaultMiddleware()],
|
||||
static::$middleware,
|
||||
)),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Illuminate\Contracts\Http\Kernel;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
|
@ -14,6 +15,7 @@ use Stancl\Tenancy\Middleware\InitializeTenancyByPath;
|
|||
use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData;
|
||||
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Bootstrappers\UrlGeneratorBootstrapper;
|
||||
use Stancl\Tenancy\Controllers\TenantAssetController;
|
||||
use Stancl\Tenancy\Overrides\TenancyUrlGenerator;
|
||||
|
||||
beforeEach(function () {
|
||||
|
|
@ -114,6 +116,30 @@ test('asset helper works correctly with path identification', function (bool $ke
|
|||
'route-level identification' => false,
|
||||
]);
|
||||
|
||||
test('TenantAssetController headers are configurable', function () {
|
||||
TenantAssetController::$headers = function (Request $request) {
|
||||
return ['X-Foo' => 'Bar'];
|
||||
};
|
||||
|
||||
$tenant = Tenant::create();
|
||||
tenancy()->initialize($tenant);
|
||||
$tenant->createDomain('foo.localhost');
|
||||
|
||||
$filename = 'testfile' . pest()->randomString(10);
|
||||
Storage::disk('public')->put($filename, 'bar');
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
|
||||
$response = pest()->get("http://foo.localhost/tenancy/assets/$filename", [
|
||||
'X-Tenant' => $tenant->id,
|
||||
]);
|
||||
|
||||
$response->assertSuccessful();
|
||||
$response->assertHeader('X-Foo', 'Bar');
|
||||
|
||||
TenantAssetController::$headers = null; // reset static property
|
||||
});
|
||||
|
||||
test('global asset helper returns the same url regardless of tenancy initialization', function () {
|
||||
$original = global_asset('foobar');
|
||||
expect(global_asset('foobar'))->toBe(asset('foobar'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue