1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 16:14:02 +00:00
tenancy/tests/ReidentificationTest.php
Samuel Štancl 3bb2759fe2
[3.x] DB users (#382)
* Initial draft

* Apply fixes from StyleCI

* Use CI on master branch too

* Pass correct argument to queued DB creators/deleters

* Apply fixes from StyleCI

* Remove new interface from MySQLDBManager

* Make phpunit run

* Apply fixes from StyleCI

* Fix static property

* Default databaseName

* Use database transactions for creating users & granting permissions

* Apply fixes from StyleCI

* Get old tests to pass

* Apply fixes from StyleCI

* Add tests for PermissionControlledMySQLDatabaseManager

* Apply fixes from StyleCI

* Write test for extra config, fix bug with extra config

* Apply fixes from StyleCI
2020-05-03 18:12:27 +02:00

61 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Tests;
use Stancl\Tenancy\Tenant;
class ReidentificationTest extends TestCase
{
public $autoCreateTenant = true;
public $autoInitTenancy = false;
/**
* These tests are run when a tenant is identified after another tenant has already been identified.
*/
/** @test */
public function storage_facade_roots_are_correct()
{
$originals = [];
foreach (config('tenancy.filesystem.disks') as $disk) {
$originals[$disk] = config("filesystems.disks.{$disk}.root");
}
tenancy()->init('test.localhost');
Tenant::new()->withDomains(['second.localhost'])->save();
tenancy()->init('second.localhost');
foreach (config('tenancy.filesystem.disks') as $disk) {
$suffix = config('tenancy.filesystem.suffix_base') . tenant('id');
$current_path_prefix = \Storage::disk($disk)->getAdapter()->getPathPrefix();
if ($override = config("tenancy.filesystem.root_override.{$disk}")) {
$correct_path_prefix = str_replace('%storage_path%', storage_path(), $override);
} else {
if ($base = $originals[$disk]) {
$correct_path_prefix = $base . "/$suffix/";
} else {
$correct_path_prefix = "$suffix/";
}
}
$this->assertSame($correct_path_prefix, $current_path_prefix);
}
}
/** @test */
public function storage_path_is_correct()
{
$original = storage_path();
tenancy()->init('test.localhost');
Tenant::new()->withDomains(['second.localhost'])->save();
tenancy()->init('second.localhost');
$suffix = config('tenancy.filesystem.suffix_base') . tenant('id');
$this->assertSame($original . "/$suffix", storage_path());
}
}