@@ -161,4 +161,61 @@ public function send(Authenticatable $user, string $code, array $options = []):
161161 expect ($ skipAgain )->toBeFalse ();
162162});
163163
164+ it ('returns only channels enabled by both client and config ' , function () {
165+ $ user = new MFATestFakeUser (2001 , 'user@example.com ' );
166+ $ mfa = app (MFA ::class);
167+
168+ // Initially, no channels should be enabled by client
169+ $ enabledChannels = $ mfa ->getEnabledChannels ($ user );
170+ expect ($ enabledChannels )->toBeEmpty ();
171+
172+ // Enable email method for the user
173+ $ mfa ->enableMethod ($ user , 'email ' );
174+
175+ // Now email should be in enabled channels (if config allows it)
176+ $ enabledChannels = $ mfa ->getEnabledChannels ($ user );
177+ expect ($ enabledChannels )->toHaveKey ('email ' );
178+ expect ($ enabledChannels ['email ' ])->toBeInstanceOf (MfaChannel::class);
179+
180+ // Enable SMS method for the user
181+ $ mfa ->enableMethod ($ user , 'sms ' );
182+
183+ // Now both email and sms should be in enabled channels (if config allows them)
184+ $ enabledChannels = $ mfa ->getEnabledChannels ($ user );
185+ expect ($ enabledChannels )->toHaveKeys (['email ' , 'sms ' ]);
186+ expect ($ enabledChannels ['email ' ])->toBeInstanceOf (MfaChannel::class);
187+ expect ($ enabledChannels ['sms ' ])->toBeInstanceOf (MfaChannel::class);
188+
189+ // Disable email method for the user
190+ $ mfa ->disableMethod ($ user , 'email ' );
191+
192+ // Now only sms should be in enabled channels
193+ $ enabledChannels = $ mfa ->getEnabledChannels ($ user );
194+ expect ($ enabledChannels )->not ->toHaveKey ('email ' );
195+ expect ($ enabledChannels )->toHaveKey ('sms ' );
196+ expect ($ enabledChannels ['sms ' ])->toBeInstanceOf (MfaChannel::class);
197+ });
198+
199+ it ('excludes channels disabled in config even if enabled by client ' , function () {
200+ $ user = new MFATestFakeUser (2002 , 'user@example.com ' );
201+
202+ // Create MFA instance with custom config where email is disabled
203+ $ config = config ('mfa ' );
204+ $ config ['email ' ]['enabled ' ] = false ;
205+ $ mfa = new MFA ($ config );
206+
207+ // Enable email method for the user
208+ $ mfa ->enableMethod ($ user , 'email ' );
209+
210+ // Email should not be in enabled channels because it's disabled in config
211+ $ enabledChannels = $ mfa ->getEnabledChannels ($ user );
212+ expect ($ enabledChannels )->not ->toHaveKey ('email ' );
213+
214+ // But SMS should still be there if enabled in config and by client
215+ $ mfa ->enableMethod ($ user , 'sms ' );
216+ $ enabledChannels = $ mfa ->getEnabledChannels ($ user );
217+ expect ($ enabledChannels )->toHaveKey ('sms ' );
218+ expect ($ enabledChannels )->not ->toHaveKey ('email ' );
219+ });
220+
164221
0 commit comments