-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
1 parent
a03d772
commit 9d683b4
Showing
35 changed files
with
964 additions
and
306 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -15,13 +15,15 @@ | |
"email": "[email protected]" | ||
}], | ||
"minimum-stability": "dev", | ||
"require": {}, | ||
"require": { | ||
"tymon/jwt-auth": "1.0.0-rc.3" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^7.4@dev", | ||
"mockery/mockery": "^1.0@dev", | ||
"orchestra/testbench": "^3.8@dev", | ||
"orchestra/database": "^3.8@dev", | ||
"illuminate/support": "^5.8@dev", | ||
"orchestra/testbench": "^3.7@dev", | ||
"orchestra/database": "^3.7@dev", | ||
"illuminate/support": "^5.7@dev", | ||
"fzaninotto/faker": "^1.9@dev" | ||
}, | ||
"autoload": { | ||
|
@@ -31,7 +33,7 @@ | |
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Bitfumes\\Multiauth\\Tests\\":"tests/" | ||
"Bitfumes\\Multiauth\\Tests\\": "tests/" | ||
} | ||
}, | ||
"extra": { | ||
|
@@ -40,5 +42,10 @@ | |
"Bitfumes\\Multiauth\\MultiauthServiceProvider" | ||
] | ||
} | ||
}, | ||
"config": { | ||
"preferred-install": "dist", | ||
"sort-packages": true, | ||
"optimize-autoloader": true | ||
} | ||
} |
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
File renamed without changes.
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,87 @@ | ||
<?php | ||
|
||
namespace Bitfumes\Multiauth\Tests\Feature; | ||
|
||
use Bitfumes\Multiauth\Model\Admin; | ||
use Bitfumes\Multiauth\Tests\TestCase; | ||
use Illuminate\Foundation\Testing\DatabaseMigrations; | ||
|
||
class AdminValidationTest extends TestCase | ||
{ | ||
use DatabaseMigrations; | ||
|
||
public function setup() | ||
{ | ||
parent::setUp(); | ||
$this->withExceptionHandling(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function admin_mode_need_name() | ||
{ | ||
$this->loginSuperAdmin(); | ||
$response = $this->post(route('admin.register'), [ | ||
'email' => '[email protected]', | ||
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
]); | ||
$response->assertSessionHasErrors('name'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function admin_mode_need_email() | ||
{ | ||
$this->loginSuperAdmin(); | ||
$response = $this->post(route('admin.register'), [ | ||
'name' => 'sarthak', | ||
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
]); | ||
$response->assertSessionHasErrors('email'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function admin_mode_need_password_confirmation() | ||
{ | ||
$this->loginSuperAdmin(); | ||
$response = $this->post(route('admin.register'), [ | ||
'name' => 'sarthak', | ||
'email' => '[email protected]', | ||
'password' => 'secret', | ||
'password_confirmation' => 'differentPassword', | ||
]); | ||
$response->assertSessionHasErrors('password'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function admin_mode_need_rules() | ||
{ | ||
$this->loginSuperAdmin(); | ||
$response = $this->post(route('admin.register'), [ | ||
'name' => 'sarthak', | ||
'email' => '[email protected]', | ||
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
]); | ||
$response->assertSessionHasErrors('role_id'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function while_update_admin_mode_need_validation() | ||
{ | ||
$this->loginSuperAdmin(); | ||
$admin = $this->createAdmin(); | ||
$response = $this->patch(route('admin.update', $admin->id), []); | ||
$response->assertSessionHasErrors(['role_id', 'email', 'name']); | ||
} | ||
} |
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,56 @@ | ||
<?php | ||
|
||
namespace Bitfumes\Multiauth\Tests\Feature; | ||
|
||
use Bitfumes\Multiauth\Model\Role; | ||
use Bitfumes\Multiauth\Tests\TestCase; | ||
use Illuminate\Foundation\Testing\DatabaseMigrations; | ||
|
||
class AttachRoleTest extends TestCase | ||
{ | ||
use DatabaseMigrations; | ||
public $super; | ||
public $editorRole; | ||
|
||
public function setup() | ||
{ | ||
parent::setUp(); | ||
$this->super = $this->loginSuperAdmin(); | ||
$this->editorRole = factory(Role::class)->create(['name' => 'editor']); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function a_super_admin_can_attach_roles_to_admin() | ||
{ | ||
$admin = $this->createAdmin(); | ||
$this->get(route('admin.role.create')); | ||
$this->post(route('admin.attach.roles', ['admin' => $admin->id, 'role' => $this->editorRole->id])); | ||
$this->assertEquals($admin->roles()->pluck('name')[0], 'editor'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function a_non_super_admin_can_not_attach__roles_to_admin() | ||
{ | ||
$this->logInAdmin(); | ||
$admin = $this->createAdmin(); | ||
$this->post(route('admin.attach.roles', ['admin' => $admin->id, 'role' => $this->editorRole->id])) | ||
->assertStatus(302) | ||
->assertRedirect('/admin/home'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function a_super_user_can_detach_role_for_an_admin() | ||
{ | ||
$admin = $this->createAdmin(); | ||
$this->post(route('admin.attach.roles', ['admin' => $admin->id, 'role' => $this->editorRole->id])); | ||
$this->assertEquals($admin->roles[0]->id, $this->editorRole->id); | ||
$this->delete(route('admin.attach.roles', ['admin' => $admin->id, 'role' => $this->editorRole->id])); | ||
$this->assertEmpty($admin->fresh()->roles()->count()); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Bitfumes\Multiauth\Tests\Feature; | ||
|
||
use Bitfumes\Multiauth\Tests\TestCase; | ||
use Illuminate\Foundation\Testing\DatabaseMigrations; | ||
|
||
class CommandsTest extends TestCase | ||
{ | ||
use DatabaseMigrations; | ||
|
||
/** @test */ | ||
public function a_seed_command_can_publish_new_super_admin() | ||
{ | ||
$this->artisan('multiauth:seed', ['--role'=>'super']); | ||
$this->assertDatabaseHas('admins', ['email'=>'[email protected]']); | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
namespace Bitfumes\Multiauth\Tests\Feature; | ||
|
||
use Bitfumes\Multiauth\Model\Admin; | ||
use Bitfumes\Multiauth\Tests\TestCase; | ||
use Illuminate\Foundation\Testing\DatabaseMigrations; | ||
|
||
class LoginTest extends TestCase | ||
{ | ||
use DatabaseMigrations; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function a_user_can_see_admin_login_form() | ||
{ | ||
$this->get(route('admin.login'))->assertSee('password'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function a_user_can_login_and_redirected_to_admin_home() | ||
{ | ||
$admin = $this->createAdmin(); | ||
$this->post(route('admin.login'), ['email' => $admin->email, 'password' => 'secret']) | ||
->assertRedirect(route('admin.home')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function logged_in_admin_can_not_see_admin_login_page() | ||
{ | ||
$this->logInAdmin(); | ||
$this->get(route('admin.login'))->assertRedirect(route('admin.home')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
// public function un_authenticated_admin_can_not_see_admin_home_page() | ||
// { | ||
// $this->withExceptionHandling(); | ||
// $this->get('/admin/home')->assertRedirect('/admin'); | ||
// } | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function after_logout_admin_is_redirected_to_admin_login_page() | ||
{ | ||
$this->logInAdmin(); | ||
$this->post(route('admin.logout'))->assertRedirect(route('admin.login')); | ||
} | ||
} |
File renamed without changes.
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,86 @@ | ||
<?php | ||
|
||
namespace Bitfumes\Multiauth\Tests\Feature; | ||
|
||
use Bitfumes\Multiauth\Notifications\AdminResetPasswordNotification; | ||
use Bitfumes\Multiauth\Tests\TestCase; | ||
use Illuminate\Foundation\Testing\DatabaseMigrations; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Notification; | ||
|
||
class ResetPasswordTest extends TestCase | ||
{ | ||
use DatabaseMigrations; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function a_admin_can_see_forgot_password_form() | ||
{ | ||
$this->get(route('admin.password.request'))->assertStatus(200); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function a_password_reset_link_email_can_be_sent() | ||
{ | ||
Notification::fake(); | ||
$admin = $this->createAdmin(); | ||
$this->post(route('admin.password.email'), ['email' => $admin->email]); | ||
Notification::assertSentTo([$admin], AdminResetPasswordNotification::class); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function an_admin_can_see_reset_password_form() | ||
{ | ||
$this->get(route('admin.password.reset', 'anytoken'))->assertStatus(200); | ||
} | ||
|
||
/** @test */ | ||
public function an_admin_can_change_its_password() | ||
{ | ||
Notification::fake(); | ||
$admin = $this->createAdmin(); | ||
$this->post(route('admin.password.email'), ['email' => $admin->email]); | ||
Notification::assertSentTo([$admin], AdminResetPasswordNotification::class, function ($notification) use ($admin) { | ||
$token = $notification->token; | ||
$this->assertTrue(Hash::check('secret', $admin->password)); | ||
$res = $this->post(route('admin.password.request'), [ | ||
'email' => $admin->email, | ||
'password' => 'newpassword', | ||
'password_confirmation' => 'newpassword', | ||
'token' => $token, | ||
]); | ||
|
||
$this->assertTrue(Hash::check('newpassword', $admin->fresh()->password)); | ||
|
||
return true; | ||
}); | ||
} | ||
|
||
/** @test */ | ||
public function admin_can_visit_change_password_page() | ||
{ | ||
$admin = $this->logInAdmin(); | ||
$this->get(route('admin.password.change')) | ||
->assertOk() | ||
->assertSee('Old Password'); | ||
} | ||
|
||
/** @test */ | ||
public function admin_can_change_password_after_login() | ||
{ | ||
$admin = $this->logInAdmin(); | ||
$this->post(route('admin.password.change'), [ | ||
'oldPassword' => 'secret', | ||
'password' => '123456', | ||
'password_confirmation' => '123456' | ||
]) | ||
->assertRedirect(route('admin.home')) | ||
->assertSessionHas('message'); | ||
$this->assertTrue(Hash::check('123456', $admin->fresh()->password)); | ||
} | ||
} |
Oops, something went wrong.