CaiWuXiTong/tests/Feature/FeatureTestCase.php
chenxi fcfc401eff fix: 财务系统仅允许钉钉账号登录 (#1068)
登录页仅保留钉钉入口;停用密码、找回密码、重置密码和邀请注册登录;旧密码会话立即失效。
2026-11-11 11:02:49 +08:00

79 lines
1.8 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Auth\DingTalkIdentity;
use App\Models\Common\Company;
use Faker\Factory as Faker;
use Illuminate\Support\Str;
use Tests\TestCase;
abstract class FeatureTestCase extends TestCase
{
protected $faker;
protected $user;
protected $company;
protected function setUp(): void
{
parent::setUp();
$this->withoutExceptionHandling();
$this->faker = Faker::create();
$this->user = user_model_class()::first();
$this->company = $this->user->companies()->first();
// Disable debugbar
config(['debugbar.enabled', false]);
}
/**
* Empty for default user.
*
* @param User|null $user
* @param Company|null $company
* @return FeatureTestCase
*/
public function loginAs($user = null, Company $company = null)
{
if (!$user) {
$user = $this->user;
}
if ($company) {
$company->makeCurrent();
}
app('url')->defaults(['company_id' => company_id()]);
$identity = DingTalkIdentity::query()->firstOrCreate(
['user_id' => $user->id],
[
'union_id' => 'test-session-'.Str::random(16),
'dingtalk_user_id' => 'test-ding-user-'.$user->id,
]
);
$this->actingAs($user);
return $this->withSession([
'dingtalk_identity_id' => $identity->id,
'dingtalk_roster_checked_at' => now()->timestamp,
]);
}
public function assertFlashLevel($excepted)
{
$flash['level'] = null;
if ($flashMessage = session('flash_notification')) {
$flash = $flashMessage->first();
}
$this->assertEquals($excepted, $flash['level'], json_encode($flash));
}
}