CaiWuXiTong/tests/Feature/Installation/BootstrapInstallationTest.php

81 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature\Installation;
use App\Utilities\Installer;
use Database\Seeds\Permissions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Notification;
use Tests\CreatesApplication;
class BootstrapInstallationTest extends BaseTestCase
{
use CreatesApplication;
use RefreshDatabase;
public function test_fresh_bootstrap_administrator_can_open_wizard_dashboard_and_database_settings(): void
{
$this->artisan('db:seed', [
'--class' => Permissions::class,
'--force' => true,
])->assertSuccessful();
config([
'mail.from.address' => 'test@example.com',
'mail.from.name' => 'CaiWuXiTong Test',
]);
Notification::fake();
$company = Installer::createCompany(
'本地引导环境',
'local-bootstrap@caiwu.test',
'zh-CN'
);
Installer::createUser(
'local-bootstrap@caiwu.test',
'temporary-test-secret',
'zh-CN',
$company->id
);
$user = user_model_class()::where('email', 'local-bootstrap@caiwu.test')->firstOrFail();
$role = $user->roles()->where('name', 'super_admin')->firstOrFail();
$this->assertTrue($role->hasPermission('read-admin-panel'));
$this->assertTrue($role->hasPermission('create-common-companies'));
$this->assertTrue($role->hasPermission('read-common-companies'));
$this->assertTrue($role->hasPermission('read-common-dashboards'));
$this->assertFalse($role->hasPermission('read-client-portal'));
$this->assertTrue($user->companies()->whereKey($company->id)->exists());
$this->assertTrue($user->can('read-admin-panel'));
$this->assertTrue($user->can('read-common-companies'));
$this->assertTrue($user->hasPermission('read-admin-panel'));
$this->assertTrue($user->hasPermission('read-common-companies'));
$company->makeCurrent();
app('url')->defaults(['company_id' => $company->id]);
config([
'debugbar.enabled' => false,
'system_database.mode' => 'bootstrap',
'upstreams.stored_configuration.enabled' => false,
]);
foreach (array_keys(config('firewall.middleware', [])) as $middleware) {
config(["firewall.middleware.{$middleware}.enabled" => false]);
}
foreach ([
route('wizard.edit'),
route('dashboard'),
route('system-settings.databases.index'),
] as $url) {
$response = $this->actingAs($user)->get($url);
$this->assertNotSame(
403,
$response->getStatusCode(),
$url . ' 不应返回 403:' . mb_substr(strip_tags($response->getContent()), 0, 500)
);
}
}
}