|
2 | 2 |
|
3 | 3 | namespace Tests\Console\Commands; |
4 | 4 |
|
| 5 | +use Illuminate\Database\Schema\Blueprint; |
5 | 6 | use Illuminate\Filesystem\Filesystem; |
| 7 | +use Illuminate\Support\Facades\Schema; |
6 | 8 | use PHPUnit\Framework\Attributes\Test; |
7 | 9 | use Statamic\Facades\User; |
| 10 | +use Tests\Auth\Eloquent\User as EloquentUser; |
8 | 11 | use Tests\TestCase; |
9 | 12 |
|
10 | 13 | class MakeUserTest extends TestCase |
@@ -37,6 +40,30 @@ public function it_can_make_a_user() |
37 | 40 | $this->assertEquals('jason@tellmewhatyouchasin.com', $user->email()); |
38 | 41 | } |
39 | 42 |
|
| 43 | + #[Test] |
| 44 | + public function it_can_make_an_eloquent_user_non_interactively() |
| 45 | + { |
| 46 | + config([ |
| 47 | + 'auth.providers.users.model' => EloquentUser::class, |
| 48 | + 'statamic.users.repository' => 'eloquent', |
| 49 | + ]); |
| 50 | + |
| 51 | + $this->loadMigrationsFrom(__DIR__.'/../../Auth/Eloquent/__migrations__'); |
| 52 | + |
| 53 | + Schema::table('users', fn (Blueprint $table) => $table->string('name')->nullable()->change()); |
| 54 | + |
| 55 | + collect(['role', 'group'])->each(fn ($type) => Schema::create("{$type}_user", function (Blueprint $table) use ($type) { |
| 56 | + $table->id(); |
| 57 | + $table->foreignId('user_id'); |
| 58 | + $table->string("{$type}_id"); |
| 59 | + })); |
| 60 | + |
| 61 | + $this->artisan('statamic:make:user', ['email' => 'jason@tellmewhatyouchasin.com']) |
| 62 | + ->expectsOutputToContain('User created successfully.'); |
| 63 | + |
| 64 | + $this->assertEquals('jason@tellmewhatyouchasin.com', User::all()->first()->email()); |
| 65 | + } |
| 66 | + |
40 | 67 | #[Test] |
41 | 68 | public function it_can_make_a_super_user_interactively() |
42 | 69 | { |
@@ -145,4 +172,40 @@ public function if_password_option_is_passed_it_will_not_prompt_for_password() |
145 | 172 | $this->assertNotEmpty($user->password()); |
146 | 173 | $this->assertTrue(password_verify($password, $user->password())); |
147 | 174 | } |
| 175 | + |
| 176 | + #[Test] |
| 177 | + public function it_can_make_a_user_with_name_option() |
| 178 | + { |
| 179 | + $this->artisan('statamic:make:user', ['email' => 'jason@tellmewhatyouchasin.com', '--name' => 'Jason']) |
| 180 | + ->expectsOutputToContain('User created successfully.'); |
| 181 | + |
| 182 | + $this->assertEquals('Jason', User::all()->first()->get('name')); |
| 183 | + } |
| 184 | + |
| 185 | + #[Test] |
| 186 | + public function it_can_make_a_user_with_first_and_last_name_options() |
| 187 | + { |
| 188 | + $this->artisan('statamic:make:user', [ |
| 189 | + 'email' => 'jason@tellmewhatyouchasin.com', |
| 190 | + '--first-name' => 'Jason', |
| 191 | + '--last-name' => 'Varga', |
| 192 | + ])->expectsOutputToContain('User created successfully.'); |
| 193 | + |
| 194 | + $user = User::all()->first(); |
| 195 | + |
| 196 | + $this->assertEquals('Jason', $user->get('first_name')); |
| 197 | + $this->assertEquals('Varga', $user->get('last_name')); |
| 198 | + } |
| 199 | + |
| 200 | + #[Test] |
| 201 | + public function if_name_option_is_passed_it_will_not_prompt_for_name() |
| 202 | + { |
| 203 | + $this->artisan('statamic:make:user', ['--name' => 'Duncan']) |
| 204 | + ->expectsQuestion('Email', 'duncan@likesteatime.com') |
| 205 | + ->expectsQuestion('Password', 'PacManMoonwalk#84') |
| 206 | + ->expectsQuestion('Super user?', false) |
| 207 | + ->assertExitCode(0); |
| 208 | + |
| 209 | + $this->assertEquals('Duncan', User::all()->first()->get('name')); |
| 210 | + } |
148 | 211 | } |
0 commit comments