|
2 | 2 |
|
3 | 3 | namespace Tests; |
4 | 4 |
|
5 | | -use Illuminate\Support\Facades\Hash; |
6 | | -use Illuminate\Support\Facades\Artisan; |
7 | | -use Illuminate\Support\Facades\Notification; |
8 | | -use Illuminate\Auth\Notifications\ResetPassword; |
9 | | - |
10 | 5 | class MakeUserTest extends TestCase |
11 | 6 | { |
12 | 7 | /** @test */ |
13 | | - public function it_requires_a_valid_email_address() |
14 | | - { |
15 | | - Artisan::call('make:user', ['email' => 'invalidemail']); |
16 | | - |
17 | | - $this->assertFalse(User::where('email', 'invalidemail')->exists()); |
18 | | - } |
19 | | - |
20 | | - /** @test */ |
21 | | - public function it_requires_a_unique_email_address() |
22 | | - { |
23 | | - User:: create([ 'name' => 'Adam Wathan', 'email' => '[email protected]', 'password' => '']); |
24 | | - |
25 | | - $exitCode = Artisan:: call( 'make:user', [ 'email' => '[email protected]']); |
26 | | - |
27 | | - $this->assertContains('The user was not created', Artisan::output()); |
28 | | - $this-> assertEquals( 1, User:: where( 'email', '[email protected]')-> count()); |
29 | | - } |
30 | | - |
31 | | - /** @test */ |
32 | | - public function it_hashes_the_password_when_specified() |
33 | | - { |
34 | | - Artisan:: call( 'make:user', [ 'email' => '[email protected]', '--password' => 'secret']); |
35 | | - |
36 | | - tap(User::first(), function ($user) { |
37 | | - $this->assertTrue(Hash::check('secret', $user->password)); |
38 | | - }); |
39 | | - } |
40 | | - |
41 | | - /** @test */ |
42 | | - public function it_sends_the_password_reset_email_when_generating_a_password() |
43 | | - { |
44 | | - Notification::fake(); |
45 | | - |
46 | | - Artisan:: call( 'make:user', [ 'email' => '[email protected]', '--name' => 'Michael Dyrynda']); |
47 | | - |
48 | | - Notification::assertSentTo(User::first(), ResetPassword::class); |
49 | | - |
50 | | - tap([ 'email' => '[email protected]', 'name' => 'Michael Dyrynda'], function ( $credentials) { |
51 | | - $this->assertTrue(User::where($credentials)->exists()); |
52 | | - $this->assertEquals(1, User::where($credentials)->count()); |
53 | | - }); |
54 | | - } |
55 | | - |
56 | | - /** @test */ |
57 | | - public function it_does_not_send_the_password_reset_email_when_the_password_is_specified() |
58 | | - { |
59 | | - Notification::fake(); |
60 | | - |
61 | | - Artisan:: call( 'make:user', [ 'email' => '[email protected]', '--password' => 'secret']); |
62 | | - |
63 | | - Notification::assertNotSentTo(User::first(), ResetPassword::class); |
64 | | - |
65 | | - tap([ 'email' => '[email protected]'], function ( $credentials) { |
66 | | - $this->assertTrue(User::where($credentials)->exists()); |
67 | | - $this->assertEquals(1, User::where($credentials)->count()); |
68 | | - }); |
69 | | - } |
70 | | - |
71 | | - /** @test */ |
72 | | - public function it_sends_the_password_reset_email_when_flagged_to_do_so() |
73 | | - { |
74 | | - Notification::fake(); |
75 | | - |
76 | | - Artisan:: call( 'make:user', [ 'email' => '[email protected]', '--password' => 'secret', '--send-reset' => true]); |
77 | | - |
78 | | - Notification::assertSentTo(User::first(), ResetPassword::class); |
79 | | - } |
80 | | - |
81 | | - /** @test */ |
82 | | - public function it_fills_additional_fields_when_specified() |
| 8 | + public function it_creates_a_new_user() |
83 | 9 | { |
84 | | - Artisan::call( 'make:user', ['email' => '[email protected]', '--password' => 'secret', '--fields' => 'admin:true']); |
85 | | - |
86 | | - $this->assertTrue(User::where([ |
87 | | - |
88 | | - 'admin' => true, |
89 | | - ])->exists()); |
| 10 | + $this->artisan('make:user') |
| 11 | + ->expectsQuestion("What is the new user's email address?", '[email protected]') |
| 12 | + ->expectsQuestion("What is the new user's name?", 'Test User') |
| 13 | + ->expectsQuestion("What is the new user's password? (blank generates a random one)", '') |
| 14 | + ->expectsQuestion('Do you want to send a password reset email?', 'no') |
| 15 | + ->expectsQuestion('Do you have any custom user fields to add? Field=Value (blank continues)', ''); |
90 | 16 | } |
91 | 17 |
|
92 | 18 | /** @test */ |
93 | | - public function it_handles_null_field_values_correctly() |
| 19 | + public function it_creates_a_new_user_with_additional_fields() |
94 | 20 | { |
95 | | - Artisan:: call( 'make:user', [ 'email' => '[email protected]', '--fields' => 'force_filled:null']); |
96 | | - |
97 | | - tap(User::first(), function ($user) { |
98 | | - $this->assertNull($user->force_filled); |
99 | | - }); |
100 | | - } |
101 | | - |
102 | | - /** @test */ |
103 | | - public function it_force_filles_guarded_properties_when_instructed() |
104 | | - { |
105 | | - Artisan::call('make:user', [ |
106 | | - |
107 | | - '--password' => 'secret', |
108 | | - '--force' => true, |
109 | | - '--fields' => 'admin:false,force_filled:string field', |
110 | | - ]); |
111 | | - |
112 | | - tap(User::first(), function ($user) { |
113 | | - $this->assertFalse($user->admin); |
114 | | - $this->assertEquals('string field', $user->force_filled); |
115 | | - }); |
| 21 | + $this->artisan('make:user') |
| 22 | + -> expectsQuestion( "What is the new user's email address?", '[email protected]') |
| 23 | + ->expectsQuestion("What is the new user's name?", 'Test User') |
| 24 | + ->expectsQuestion("What is the new user's password? (blank generates a random one)", '') |
| 25 | + ->expectsQuestion('Do you want to send a password reset email?', 'no') |
| 26 | + ->expectsQuestion('Do you have any custom user fields to add? Field=Value (blank continues)', 'field=value') |
| 27 | + ->expectsQuestion('Do you have any custom user fields to add? Field=Value (blank continues)', ''); |
116 | 28 | } |
117 | 29 | } |
0 commit comments