phpvms/tests/RegistrationTest.php

40 lines
1.0 KiB
PHP
Raw Normal View History

<?php
namespace Tests;
2018-02-21 12:33:09 +08:00
use App\Models\Enums\UserState;
use App\Models\User;
use App\Notifications\Messages\AdminUserRegistered;
2022-02-05 04:03:05 +08:00
use App\Services\UserService;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Notification;
class RegistrationTest extends TestCase
{
/**
* A basic test example.
*
* @throws \Exception
2018-08-27 02:51:47 +08:00
*
* @return void
*/
public function testRegistration()
{
$admin = $this->createAdminUser(['name' => 'testRegistration Admin']);
2022-02-05 04:03:05 +08:00
/** @var UserService $userSvc */
$userSvc = app(UserService::class);
$this->updateSetting('pilots.auto_accept', true);
$attrs = User::factory()->make()->makeVisible(['api_key', 'name', 'email'])->toArray();
$attrs['password'] = Hash::make('secret');
$user = $userSvc->createUser($attrs);
2017-12-31 10:40:32 +08:00
$this->assertEquals(UserState::ACTIVE, $user->state);
Notification::assertSentTo([$admin], AdminUserRegistered::class);
Notification::assertNotSentTo([$user], AdminUserRegistered::class);
}
}