Skip to content

Commit

Permalink
Merge branch 'main' into fortifyOut
Browse files Browse the repository at this point in the history
  • Loading branch information
tnylea committed May 11, 2024
2 parents e215726 + 671e210 commit 34423ee
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 85 deletions.
90 changes: 46 additions & 44 deletions resources/views/pages/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public $social_providers = [];
public function rules()
{
{
$nameValidationRules = [];
if(config('devdojo.auth.settings.registration_include_name_field')){
$nameValidationRules = ['name' => 'required'];
Expand Down Expand Up @@ -94,52 +94,54 @@ public function register()
?>

<x-auth::layouts.app title="{{ config('devdojo.auth.language.register.page_title') }}">
<div>
<x-auth::layouts.app title="{{ config('devdojo.auth.language.register.page_title') }}">

@volt('auth.register')
<x-auth::elements.container>
@volt('auth.register')
<x-auth::elements.container>

<x-auth::elements.heading
:text="($language->register->headline ?? 'No Heading')"
:description="($language->register->subheadline ?? 'No Description')"
:show_subheadline="($language->register->show_subheadline ?? false)" />

<form wire:submit="register" class="mt-5 space-y-5">

@if($showNameField)
<x-auth::elements.input label="Name" type="text" wire:model="name" autofocus="true" required />
@endif

@if($showEmailField)
@php
$autofocusEmail = ($showNameField) ? false : true;
@endphp
<x-auth::elements.input label="Email Address" type="email" wire:model="email" :autofocus="$autofocusEmail" required />
@endif

@if($showPasswordField)
<x-auth::elements.input label="Password" type="password" wire:model="password" id="password" required />
@endif

<x-auth::elements.button rounded="md" submit="true">Continue</x-auth::elements.button>
</form>

<div class="mt-3 space-x-0.5 text-sm leading-5 text-left" style="color:{{ config('devdojo.auth.appearance.color.text') }}">
<span class="opacity-[47%]">Already have an account?</span>
<x-auth::elements.text-link href="{{ route('auth.login') }}">Sign in</x-auth::elements.text-link>
</div>

@if(count($this->social_providers))
<x-auth::elements.separator class="my-7">or</x-auto::elements.separator>
<div class="relative space-y-2 w-full">
@foreach($this->social_providers as $slug => $provider)
<x-auth::elements.social-button :$slug :$provider />
@endforeach
<x-auth::elements.heading
:text="($language->register->headline ?? 'No Heading')"
:description="($language->register->subheadline ?? 'No Description')"
:show_subheadline="($language->register->show_subheadline ?? false)" />

<form wire:submit="register" class="mt-5 space-y-5">

@if($showNameField)
<x-auth::elements.input label="Name" type="text" wire:model="name" autofocus="true" required />
@endif

@if($showEmailField)
@php
$autofocusEmail = ($showNameField) ? false : true;
@endphp
<x-auth::elements.input label="Email Address" type="email" wire:model="email" :autofocus="$autofocusEmail" required />
@endif

@if($showPasswordField)
<x-auth::elements.input label="Password" type="password" wire:model="password" id="password" required />
@endif

<x-auth::elements.button rounded="md" submit="true">Continue</x-auth::elements.button>
</form>

<div class="mt-3 space-x-0.5 text-sm leading-5 text-left" style="color:{{ config('devdojo.auth.appearance.color.text') }}">
<span class="opacity-[47%]">Already have an account?</span>
<x-auth::elements.text-link href="{{ route('auth.login') }}">Sign in</x-auth::elements.text-link>
</div>
@endif

@if(count($this->social_providers))
<x-auth::elements.separator class="my-7">or</x-auto::elements.separator>
<div class="relative space-y-2 w-full">
@foreach($this->social_providers as $slug => $provider)
<x-auth::elements.social-button :$slug :$provider />
@endforeach
</div>
@endif


</x-auth::elements.container>
@endvolt
</x-auth::elements.container>
@endvolt

</x-auth::layouts.app>
</x-auth::layouts.app>
</div>
85 changes: 85 additions & 0 deletions tests/Feature/AuthenticationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

beforeEach(function () {
// Ensure each test starts with a clean slate
User::query()->delete();
});

it('validates email and password fields', function () {
Livewire::test('auth.register')
->set('email', 'invalid-email')
->set('password', '123')
->call('register')
->assertHasErrors(['email' => 'email', 'password' => 'min']);
});

it('registers a new user and logs in', function () {
$this->withoutExceptionHandling();
$this->mock(Registered::class);
config()->set('devdojo.auth.settings.registration_include_name_field', true);

Livewire::test('auth.register')
->set('email', '[email protected]')
->set('password', 'secret1234')
->set('name', 'John Doe')
->call('register')
->assertHasNoErrors()
->assertRedirect('/');

$this->assertTrue(Auth::check());
$this->assertEquals('[email protected]', Auth::user()->email);
$this->assertEquals('John Doe', Auth::user()->name);
});

it('conditionally displays name and password fields based on configuration', function () {
config()->set('devdojo.auth.settings.registration_include_name_field', true);
config()->set('devdojo.auth.settings.registration_show_password_same_screen', true);

Livewire::test('auth.register')
->assertSet('showNameField', true)
->assertSet('showPasswordField', true)
->assertSeeHtml('wire:model="name"')
->assertSeeHtml('wire:model="password"')
->assertDontSeeHtml('wire:model="password_confirmation"');
});

it('checks for required fields and validation errors', function () {
Livewire::test('auth.register')
->set('email', 'not-an-email')
->call('register')
->assertHasErrors(['email' => 'email']);

Livewire::test('auth.register')
->set('password', 'short')
->call('register')
->assertHasErrors(['password' => 'min']);
});

it('renders social login buttons if providers are available', function () {
config()->set('devdojo.auth.providers', [
'google' => [
'name' => 'Google',
'active' => true,
'label' => 'Google'
],
'facebook' => [
'name' => 'Facebook',
'active' => true,
'label' => 'Facebook'
],
'twitter' => [
'name' => 'Twitter',
'active' => false,
'label' => 'Twitter'
]
]);

Livewire::test('auth.register')
->assertSee('Google')
->assertSee('Facebook')
->assertDontSee('Twitter');
});
40 changes: 0 additions & 40 deletions tests/Feature/AuthenticationWIP.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

uses(
Tests\TestCase::class
Tests\TestCase::class,
// Illuminate\Foundation\Testing\RefreshDatabase::class,
)->in('Feature');

Expand Down

0 comments on commit 34423ee

Please sign in to comment.