-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
224 additions
and
117 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace CodebarAg\LaravelAuth\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
|
||
class InstallTestsCommand extends Command | ||
{ | ||
public $signature = 'auth:install-tests'; | ||
|
||
public $description = 'Install the auth tests'; | ||
|
||
public function handle(): int | ||
{ | ||
$this->comment('Publishing Auth Tests...'); | ||
|
||
File::copyDirectory(__DIR__ . '/../../stubs/tests/', base_path('tests')); | ||
|
||
if(file_exists(base_path('phpunit.xml'))){ | ||
$this->replaceInFile('<testsuites>', '<testsuites> | ||
<testsuite name="Auth"> | ||
<directory>tests/Auth</directory> | ||
</testsuite>', base_path('phpunit.xml') | ||
); | ||
} | ||
|
||
if(file_exists(base_path('phpunit.xml.dist'))){ | ||
$this->replaceInFile('<testsuites>', '<testsuites> | ||
<testsuite name="Auth"> | ||
<directory>tests/Auth</directory> | ||
</testsuite>', base_path('phpunit.xml.dist') | ||
); | ||
} | ||
|
||
if(file_exists(base_path('tests/Pest.php'))){ | ||
$this->replaceInFile(')->in(\'Feature\');', | ||
')->in(\'Feature\', \'Auth\');', | ||
base_path('tests/Pest.php') | ||
); | ||
} | ||
|
||
|
||
|
||
$this->comment('All done'); | ||
|
||
return self::SUCCESS; | ||
} | ||
|
||
/** | ||
* Replace a given string within a given file. | ||
* | ||
* @param string $search | ||
* @param string $replace | ||
* @param string $path | ||
* @return void | ||
*/ | ||
protected function replaceInFile($search, $replace, $path) | ||
{ | ||
file_put_contents($path, str_replace($search, $replace, file_get_contents($path))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Controllers\Employees; | ||
|
||
use App\Models\User; | ||
|
||
it('unauthorized auth.login', function () { | ||
$this->get(route('auth.login')) | ||
->assertOk(); | ||
})->group('auth', 'login'); | ||
|
||
it('authorized auth.login', function () { | ||
$user = User::factory()->create([ | ||
'email_verified_at' => null, | ||
]); | ||
|
||
$this->actingAs($user) | ||
->get(route('auth.login')) | ||
->assertRedirect(); | ||
})->group('auth', 'login'); | ||
|
||
test('authorized customer.auth.login.store', function () { | ||
$user = User::factory()->create([ | ||
'email_verified_at' => null, | ||
]); | ||
|
||
$this->actingAs($user) | ||
->post(route('auth.login.store'), [ | ||
'email' => $user->email, | ||
'password' => 'password', | ||
]) | ||
->assertRedirect(); | ||
})->group('auth', 'login'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
use App\Models\User; | ||
use function Pest\Laravel\assertAuthenticated; | ||
use function Pest\Laravel\assertGuest; | ||
|
||
test('unauthorized auth.logout', function () { | ||
$this->post(route('auth.logout')) | ||
->assertRedirect(); | ||
})->group('auth', 'logout'); | ||
|
||
test('authorized auth.logout', function () { | ||
$user = User::factory()->create([ | ||
'email_verified_at' => null, | ||
]); | ||
|
||
Auth::login($user); | ||
|
||
assertAuthenticated(null, $user); | ||
|
||
$this->post(route('auth.logout')) | ||
->assertRedirect(); | ||
|
||
assertGuest(null, $user); | ||
})->group('auth', 'logout'); |
46 changes: 46 additions & 0 deletions
46
stubs/tests/Auth/Feature/RequestPasswordControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
use App\Models\User; | ||
use CodebarAg\LaravelAuth\Notifications\ResetPasswordNotification; | ||
use Illuminate\Support\Facades\Notification; | ||
|
||
test('unauthorized auth.request-password.index', function () { | ||
$response = $this->get(route('auth.request-password')); | ||
$response->assertOk(); | ||
})->group('auth', 'request-password'); | ||
|
||
test('authorized auth.request-password.index', function () { | ||
$user = User::factory()->create([ | ||
'email_verified_at' => null, | ||
]); | ||
|
||
$this->actingAs($user) | ||
->get(route('auth.request-password')) | ||
->assertRedirect(); | ||
})->group('auth', 'request-password'); | ||
|
||
test('unauthorized auth.request-password.store', function () { | ||
Notification::fake(); | ||
|
||
$user = User::factory()->create(); | ||
|
||
$this->post(route('auth.request-password.store'), [ | ||
'email' => $user->email, | ||
]) | ||
->assertSessionDoesntHaveErrors() | ||
->assertRedirect(); | ||
|
||
Notification::assertSentTo($user, ResetPasswordNotification::class); | ||
})->group('auth', 'request-password'); | ||
|
||
test('authorized auth.request-password.store', function () { | ||
$user = User::factory()->create([ | ||
'email_verified_at' => null, | ||
]); | ||
|
||
$this->actingAs($user) | ||
->post(route('auth.request-password.store'), [ | ||
'email' => $user->email, | ||
]) | ||
->assertRedirect(); | ||
})->group('auth', 'request-password'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
use App\Models\User; | ||
use Illuminate\Routing\Middleware\ValidateSignature; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Str; | ||
|
||
test('unauthorized auth.reset-password.store with valid token', function () { | ||
$user = User::factory()->create([ | ||
'email_verified_at' => null, | ||
]); | ||
|
||
$this->actingAs($user) | ||
->post(route('auth.request-password.store'), [ | ||
'email' => $user->email, | ||
]); | ||
|
||
$entry = DB::table(config('laravel-auth.password_reset_table'))->get()->first(); | ||
|
||
$this->withoutMiddleware([ValidateSignature::class]); | ||
|
||
$password = Str::random(); | ||
|
||
$response = $this->post(route('auth.reset-password.store'), [ | ||
'token' => $entry->token, | ||
'email' => $user->email, | ||
'password' => $password, | ||
'password_confirmation' => $password, | ||
]); | ||
|
||
$response->assertSessionDoesntHaveErrors(); | ||
$response->assertRedirect(); | ||
})->group('auth', 'reset-password'); | ||
|
||
test('authorized reset-password.store', function () { | ||
$token = Str::random(); | ||
|
||
$user = User::factory()->create([ | ||
'email_verified_at' => null, | ||
]); | ||
|
||
$this->actingAs($user) | ||
->post(route('auth.reset-password.store', $token)) | ||
->assertRedirect(); | ||
})->group('auth', 'reset-password'); |
2 changes: 1 addition & 1 deletion
2
tests/Fixtures/FixtureUser.php → stubs/tests/Auth/Fixtures/FixtureUser.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.