From e3e59cd2b7012469350f432c0a6c4808a45eee3e Mon Sep 17 00:00:00 2001 From: Bobby Iliev Date: Sun, 12 May 2024 01:01:26 +0300 Subject: [PATCH] Add auth providers config tests --- .../pages/auth/setup/providers.blade.php | 93 +++++++++---------- .../pages/auth/two-factor-challenge.blade.php | 72 +++++++------- resources/views/pages/auth/verify.blade.php | 4 +- .../two-factor-authentication/index.blade.php | 8 +- tests/Feature/AuthProvidersTest.php | 24 +++++ 5 files changed, 113 insertions(+), 88 deletions(-) create mode 100644 tests/Feature/AuthProvidersTest.php diff --git a/resources/views/pages/auth/setup/providers.blade.php b/resources/views/pages/auth/setup/providers.blade.php index c04d087..31f1de2 100644 --- a/resources/views/pages/auth/setup/providers.blade.php +++ b/resources/views/pages/auth/setup/providers.blade.php @@ -29,56 +29,55 @@ public function update($slug, $checked){ ?> - +
+ - @volt('auth.setup.providers') -
- - -
- @if(!file_exists(base_path('config/devdojo/auth/providers.php'))) - - @else -
- @foreach($this->providers as $network_slug => $provider) - -
-
-
-
- @if(isset($provider['svg']) && !empty(trim($provider['svg']))) - {!! $provider['svg'] !!} + @volt('auth.setup.providers') +
+ + +
+ @if(!file_exists(base_path('config/devdojo/auth/providers.php'))) + + @else +
+ @foreach($this->providers as $network_slug => $provider) + +
+
+
+
+ @if(isset($provider['svg']) && !empty(trim($provider['svg']))) + {!! $provider['svg'] !!} + @else + + @endif +
+
+

{{ $provider['name'] }}

+ +
+
+
+ @if(isset($provider['client_id']) && !empty(trim($provider['client_id'])) && isset($provider['client_secret']) && !empty(trim($provider['client_secret']))) + + + @else - + + + @endif -
-
-

{{ $provider['name'] }}

- -
+
-
- @if(isset($provider['client_id']) && !empty(trim($provider['client_id'])) && isset($provider['client_secret']) && !empty(trim($provider['client_secret']))) - - - - @else - - - - @endif -
+
- -
- @endforeach -
- @endif -
-
- @endvolt - -
- - + @endforeach +
+ @endif + + + @endvolt +
+ diff --git a/resources/views/pages/auth/two-factor-challenge.blade.php b/resources/views/pages/auth/two-factor-challenge.blade.php index 894cb26..e6a3cf9 100644 --- a/resources/views/pages/auth/two-factor-challenge.blade.php +++ b/resources/views/pages/auth/two-factor-challenge.blade.php @@ -89,47 +89,49 @@ public function submit_recovery_code(){ ?> - - @volt('auth.twofactorchallenge') - - - @if(!$recovery) - - @else - - @endif - -
+
+ + @volt('auth.twofactorchallenge') + @if(!$recovery) -
- -
+ @else -
- -
+ @endif - Continue - +
-
- or you can - @if(!$recovery) - login using a recovery code +
+ +
@else - login using an authentication code +
+ +
@endif -
-
- - @endvolt - + + Continue +
+ +
+ or you can + + @if(!$recovery) + login using a recovery code + @else + login using an authentication code + @endif + +
+
+ @endvolt +
+
diff --git a/resources/views/pages/auth/verify.blade.php b/resources/views/pages/auth/verify.blade.php index 83d0f4d..9379310 100644 --- a/resources/views/pages/auth/verify.blade.php +++ b/resources/views/pages/auth/verify.blade.php @@ -59,7 +59,7 @@ public function resend()

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.

- +
@@ -71,7 +71,7 @@ public function resend() @csrf
- +
@endvolt diff --git a/resources/views/pages/user/two-factor-authentication/index.blade.php b/resources/views/pages/user/two-factor-authentication/index.blade.php index 0b89ba6..2346acd 100644 --- a/resources/views/pages/user/two-factor-authentication/index.blade.php +++ b/resources/views/pages/user/two-factor-authentication/index.blade.php @@ -4,16 +4,16 @@ use Livewire\Volt\Component; name('user.two-factor-authentication'); -//middleware(['auth', 'verified', 'password.confirm']); +//middleware(['auth', 'verified', 'password.confirm']); middleware(['auth', 'verified']); // middleware(['auth']) new class extends Component { public $showingConfirmation = false; - + public function mount(){ - + } } @@ -80,4 +80,4 @@ public function mount(){ @endvolt - \ No newline at end of file + diff --git a/tests/Feature/AuthProvidersTest.php b/tests/Feature/AuthProvidersTest.php new file mode 100644 index 0000000..bd1ed07 --- /dev/null +++ b/tests/Feature/AuthProvidersTest.php @@ -0,0 +1,24 @@ +set('devdojo.auth.providers', [ + 'google' => ['name' => 'Google', 'active' => true], + 'facebook' => ['name' => 'Facebook', 'active' => false], + ]); + + Livewire::test('auth.setup.providers') + ->assertSet('providers.google.active', true) + ->assertSet('providers.facebook.active', false); +}); + +it('updates provider activation correctly and clears config cache', function () { + Livewire::test('auth.setup.providers') + ->call('update', 'google', true) + ->assertSet('providers.google.active', true); + assert(config('devdojo.auth.providers.google.active') === true); + + Livewire::test('auth.setup.providers') + ->call('update', 'google', false) + ->assertSet('providers.google.active', false); + assert(config('devdojo.auth.providers.google.active') === false); +});