1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 21:34:04 +00:00

First TenantAssetTest

This commit is contained in:
Samuel Štancl 2019-02-08 23:25:50 +01:00
parent 22fc843ce3
commit 9ec4fd931a
2 changed files with 13 additions and 3 deletions

View file

@ -14,7 +14,7 @@ class TenantAssetsController extends Controller
public function asset($path) public function asset($path)
{ {
try { try {
return response()->file(storage_path('app/public/' . $path)); return response()->file(storage_path("app/public/$path"));
} catch (\Throwable $th) { } catch (\Throwable $th) {
abort(404); abort(404);
} }

View file

@ -7,9 +7,19 @@ class TenantAssetTest extends TestCase
/** @test */ /** @test */
public function asset_can_be_accessed_using_the_url_returned_by_the_tenant_asset_helper() public function asset_can_be_accessed_using_the_url_returned_by_the_tenant_asset_helper()
{ {
$this->markTestIncomplete();
$filename = 'testfile' . $this->randomString(10); $filename = 'testfile' . $this->randomString(10);
\Storage::disk('public')->put($filename, 'bar'); \Storage::disk('public')->put($filename, 'bar');
$this->get(tenant_asset($filename))->assertSee('bar'); $path = storage_path("app/public/$filename");
// response()->file() returns BinaryFileResponse whose content is
// inaccessible via getContent, so ->assertSee() can't be used
$this->get(tenant_asset($filename))->assertSuccessful();
$this->assertFileExists($path);
$f = fopen($path, 'r');
$content = fread($f, filesize($path));
fclose($f);
$this->assertSame('bar', $content);
} }
} }