-
Notifications
You must be signed in to change notification settings - Fork 1
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
18 changed files
with
454 additions
and
30 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
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
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
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
28 changes: 28 additions & 0 deletions
28
tests/Unit/Controllers/Service/Auth/ForgotPasswordControllerTest.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,28 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Controllers\Service\Auth; | ||
|
||
use App\Http\Controllers\Service\Auth\ForgotPasswordController; | ||
use Illuminate\Contracts\Auth\PasswordBroker; | ||
use Illuminate\Contracts\View\View; | ||
use Tests\TestCase; | ||
|
||
class ForgotPasswordControllerTest extends TestCase | ||
{ | ||
|
||
public function testBroker() | ||
{ | ||
$fpc = new ForgotPasswordController(); | ||
$reflection = new \ReflectionClass($fpc); | ||
$method = $reflection->getMethod("broker"); | ||
$method->setAccessible(true); | ||
$result = $method->invoke($fpc); | ||
$this->assertInstanceOf(PasswordBroker::class, $result); | ||
} | ||
public function testShowLinkRequestForm() | ||
{ | ||
$fpc = new ForgotPasswordController(); | ||
$result = $fpc->showLinkRequestForm(); | ||
$this->assertInstanceOf(View::class, $result); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
tests/Unit/Controllers/Service/Auth/LoginControllerTest.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,80 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Controllers\Service\Auth; | ||
|
||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Auth; | ||
use Tests\TestCase; | ||
|
||
class LoginControllerTest extends TestCase | ||
{ | ||
public function testLoginGood() | ||
{ | ||
// Called in middleware | ||
Auth::shouldReceive("guard->check")->once()->andReturn(false); | ||
// Called in controller | ||
Auth::shouldReceive("guard->attempt")->once()->andReturn(true); | ||
|
||
/** | ||
* @var RedirectResponse $response | ||
*/ | ||
$response = $this->post( | ||
route('admin.login'), | ||
[ | ||
'email' => '[email protected]', | ||
'password' => 'bdbdbd', | ||
] | ||
); | ||
$this->assertEquals(302, $response->status()); | ||
$a = route('admin.dashboard'); | ||
$b = $response->getTargetUrl(); | ||
$this->assertEquals(route('admin.dashboard'), $response->getTargetUrl()); | ||
} | ||
|
||
public function testLoginInvalidForm() | ||
{ | ||
// Called in middleware | ||
Auth::shouldReceive("guard->check")->once()->andReturn(false); | ||
|
||
/** | ||
* @var RedirectResponse $response | ||
*/ | ||
$response = $this->post( | ||
route('admin.login'), | ||
[ | ||
'fu' => 'bar' | ||
] | ||
); | ||
$this->assertEquals(302, $response->status()); | ||
$a = route('admin.dashboard'); | ||
$b = $response->getTargetUrl(); | ||
$this->assertEquals(route('admin.dashboard'), $response->getTargetUrl()); | ||
} | ||
|
||
public function testLoginFail() | ||
{ | ||
// Called in middleware | ||
Auth::shouldReceive("guard->check")->once()->andReturn(false); | ||
// Called in controller | ||
Auth::shouldReceive("guard->attempt")->once()->andReturn(false); | ||
|
||
/** | ||
* @var RedirectResponse $response | ||
*/ | ||
$response = $this->post( | ||
route('admin.login'), | ||
[ | ||
'email' => '[email protected]', | ||
'password' => 'draconia', | ||
] | ||
); | ||
$this->assertEquals(302, $response->status()); | ||
$a = route('admin.dashboard'); | ||
$b = $response->getTargetUrl(); | ||
$this->assertEquals(route('admin.dashboard'), $response->getTargetUrl()); | ||
} | ||
|
||
// public function testLoginTooManyLogins() | ||
// { | ||
// } | ||
} |
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 | ||
|
||
namespace Tests\Unit\Controllers\Service\Auth; | ||
|
||
use App\Http\Controllers\API\Auth\LoginRequest; | ||
use Tests\TestCase; | ||
|
||
class LoginRequestTest extends TestCase | ||
{ | ||
public function testAuthorize() | ||
{ | ||
$lr = new LoginRequest(); | ||
$this->assertTrue($lr->authorize()); | ||
} | ||
|
||
public function testRules() | ||
{ | ||
$lr = new LoginRequest(); | ||
$rules = $lr->rules(); | ||
$this->assertArrayHasKey('username', $rules); | ||
$this->assertArrayHasKey('password', $rules); | ||
$this->assertEquals("required|email", $rules["username"]); | ||
$this->assertEquals("required", $rules["password"]); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/Unit/Controllers/Service/DashboardControllerTest.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,21 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Controllers\Service; | ||
|
||
use App\Http\Controllers\Service\DashboardController; | ||
use Illuminate\View\View; | ||
use Tests\TestCase; | ||
|
||
class DashboardControllerTest extends TestCase | ||
{ | ||
public function testDashboard() | ||
{ | ||
// TODO I can't find App\Http\Controllers\Service\DashboardController in the routes | ||
// is it actually used? | ||
// $response = $this->get(route('????'))->assertStatus(200); | ||
|
||
$dc = new DashboardController(); | ||
$response = $dc->index(); | ||
$this->assertInstanceOf(View::class, $response); | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Controllers\Service; | ||
|
||
use Tests\TestCase; | ||
|
||
class VersionControllerTest extends TestCase | ||
{ | ||
public function testVersion() | ||
{ | ||
$response = $this->get(route('version'))->assertStatus(200); | ||
$json = $response->json(); | ||
$this->assertArrayHasKey("Service/API", $json); | ||
} | ||
} |
Oops, something went wrong.