@@ -23,9 +23,11 @@ public function test_importing_one_user()
23
23
->shouldReceive ('getLdapDiscoveryAttribute ' )->once ()->andReturn ('mail ' )
24
24
->shouldReceive ('getEloquentUsernameAttribute ' )->once ()->andReturn ('email ' );
25
25
26
- $ r = $ this ->artisan ('adldap:import ' , ['user ' => 'jdoe ' , '--no-interaction ' ]);
26
+ $ this ->artisan ('adldap:import ' , ['user ' => 'jdoe ' , '--no-interaction ' => true ])
27
+ ->expectsOutput ("Found user 'John Doe'. " )
28
+ ->expectsOutput ("Successfully imported / synchronized 1 user(s). " )
29
+ ->assertExitCode (0 );
27
30
28
- $ this ->assertEquals (0 , $ r );
29
31
$ this ->
assertDatabaseHas (
'users ' , [
'email ' =>
'[email protected] ' ]);
30
32
}
31
33
@@ -55,13 +57,37 @@ public function test_importing_multiple_users()
55
57
->shouldReceive ('getLdapDiscoveryAttribute ' )->twice ()->andReturn ('mail ' )
56
58
->shouldReceive ('getEloquentUsernameAttribute ' )->twice ()->andReturn ('email ' );
57
59
58
- $ r = $ this ->artisan ('adldap:import ' , ['--no-interaction ' ]);
60
+ $ this ->artisan ('adldap:import ' , ['--no-interaction ' => true ])
61
+ ->expectsOutput ("Found 2 user(s). " )
62
+ ->expectsOutput ("Successfully imported / synchronized 2 user(s). " )
63
+ ->assertExitCode (0 );
59
64
60
- $ this ->assertEquals (0 , $ r );
61
65
$ this ->
assertDatabaseHas (
'users ' , [
'email ' =>
'[email protected] ' ]);
62
66
$ this ->
assertDatabaseHas (
'users ' , [
'email ' =>
'[email protected] ' ]);
63
67
}
64
68
69
+ public function test_questions_asked_with_interaction ()
70
+ {
71
+ $ b = m::mock (Builder::class);
72
+
73
+ $ u = $ this ->makeLdapUser ();
74
+
75
+ $ b ->shouldReceive ('findOrFail ' )->once ()->with ('jdoe ' )->andReturn ($ u );
76
+
77
+ Resolver::shouldReceive ('query ' )->once ()->andReturn ($ b )
78
+ ->shouldReceive ('getLdapDiscoveryAttribute ' )->once ()->andReturn ('mail ' )
79
+ ->shouldReceive ('getEloquentUsernameAttribute ' )->once ()->andReturn ('email ' );
80
+
81
+ $ this ->artisan ('adldap:import ' , ['user ' => 'jdoe ' ])
82
+ ->expectsOutput ("Found user 'John Doe'. " )
83
+ ->expectsQuestion ('Would you like to display the user(s) to be imported / synchronized? ' , 'no ' )
84
+ ->expectsQuestion ('Would you like these users to be imported / synchronized? ' , 'yes ' )
85
+ ->expectsOutput ("Successfully imported / synchronized 1 user(s). " )
86
+ ->assertExitCode (0 );
87
+
88
+ $ this ->
assertDatabaseHas (
'users ' , [
'email ' =>
'[email protected] ' ]);
89
+ }
90
+
65
91
public function test_model_will_be_restored_when_ldap_account_is_active ()
66
92
{
67
93
$ model = TestUser::create ([
@@ -93,9 +119,11 @@ public function test_model_will_be_restored_when_ldap_account_is_active()
93
119
->shouldReceive ('getLdapDiscoveryAttribute ' )->once ()->andReturn ('mail ' )
94
120
->shouldReceive ('getEloquentUsernameAttribute ' )->once ()->andReturn ('email ' );
95
121
96
- $ r = $ this ->artisan ('adldap:import ' , ['--restore ' => true , '--no-interaction ' => true ]);
122
+ $ this ->artisan ('adldap:import ' , ['--restore ' => true , '--no-interaction ' => true ])
123
+ ->expectsOutput ("Found user 'John Doe'. " )
124
+ ->expectsOutput ("Successfully imported / synchronized 1 user(s). " )
125
+ ->assertExitCode (0 );
97
126
98
- $ this ->assertEquals (0 , $ r );
99
127
$ this ->assertFalse ($ model ->fresh ()->trashed ());
100
128
}
101
129
@@ -128,27 +156,30 @@ public function test_model_will_be_soft_deleted_when_ldap_account_is_disabled()
128
156
->shouldReceive ('getLdapDiscoveryAttribute ' )->once ()->andReturn ('mail ' )
129
157
->shouldReceive ('getEloquentUsernameAttribute ' )->once ()->andReturn ('email ' );
130
158
131
- $ r = $ this ->artisan ('adldap:import ' , ['--delete ' => true , '--no-interaction ' => true ]);
132
-
133
- $ this ->assertEquals (0 , $ r );
159
+ $ this ->artisan ('adldap:import ' , ['--delete ' => true , '--no-interaction ' => true ])
160
+ ->expectsOutput ("Found user 'John Doe'. " )
161
+ ->expectsOutput ("Successfully imported / synchronized 1 user(s). " )
162
+ ->assertExitCode (0 );
163
+
134
164
$ this ->assertTrue ($ model ->fresh ()->trashed ());
135
165
}
136
166
167
+ /**
168
+ * @expectedException \RuntimeException
169
+ */
137
170
public function test_filter_option_applies_to_ldap_query ()
138
171
{
139
172
$ f = '(samaccountname=jdoe) ' ;
140
173
141
174
$ b = m::mock (Builder::class);
142
175
143
176
$ b
144
- ->shouldReceive ('rawFilter ' )->once ()->with ($ f )->andReturn ( $ b )
145
- ->shouldReceive ('paginate ' )->once ()->andReturn ( $ b )
177
+ ->shouldReceive ('rawFilter ' )->once ()->with ($ f )->andReturnSelf ( )
178
+ ->shouldReceive ('paginate ' )->once ()->andReturnSelf ( )
146
179
->shouldReceive ('getResults ' )->once ()->andReturn ([]);
147
180
148
181
Resolver::shouldReceive ('query ' )->once ()->andReturn ($ b );
149
182
150
- $ r = $ this ->artisan ('adldap:import ' , ['--filter ' => $ f , '--no-interaction ' => true ]);
151
-
152
- $ this ->assertEquals (0 , $ r );
183
+ $ this ->artisan ('adldap:import ' , ['--filter ' => $ f , '--no-interaction ' => true ]);
153
184
}
154
185
}
0 commit comments