Server IP : 66.29.132.124 / Your IP : 18.119.142.113 Web Server : LiteSpeed System : Linux business141.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : wavevlvu ( 1524) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/wavevlvu/book24.ng/vendor/laravel/ui/tests/AuthBackend/ |
Upload File : |
<?php namespace Laravel\Ui\Tests\AuthBackend; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\Request; use Illuminate\Routing\Pipeline; use Illuminate\Support\Facades\Auth; use Illuminate\Testing\TestResponse; use Illuminate\Validation\ValidationException; use Orchestra\Testbench\Factories\UserFactory; use Orchestra\Testbench\TestCase; class AuthenticatesUsersTest extends TestCase { use AuthenticatesUsers; protected function tearDown(): void { Auth::logout(); parent::tearDown(); } /** * Define database migrations. * * @return void */ protected function defineDatabaseMigrations() { $this->loadLaravelMigrations(); } /** @test */ public function it_can_authenticate_a_user() { $user = UserFactory::new()->create(); $request = Request::create('/login', 'POST', [ 'email' => $user->email, 'password' => 'password', ], [], [], [ 'HTTP_ACCEPT' => 'application/json', ]); $response = $this->handleRequestUsing($request, function ($request) { return $this->login($request); })->assertStatus(204); } /** @test */ public function it_cant_authenticate_a_user_with_invalid_password() { $user = UserFactory::new()->create(); $request = Request::create('/login', 'POST', [ 'email' => $user->email, 'password' => 'invalid-password', ], [], [], [ 'HTTP_ACCEPT' => 'application/json', ]); $response = $this->handleRequestUsing($request, function ($request) { return $this->login($request); })->assertUnprocessable(); $this->assertInstanceOf(ValidationException::class, $response->exception); $this->assertSame([ 'email' => [ 'These credentials do not match our records.', ], ], $response->exception->errors()); } /** @test */ public function it_cant_authenticate_unknown_credential() { $request = Request::create('/login', 'POST', [ 'email' => 'taylor@laravel.com', 'password' => 'password', ], [], [], [ 'HTTP_ACCEPT' => 'application/json', ]); $response = $this->handleRequestUsing($request, function ($request) { return $this->login($request); })->assertUnprocessable(); $this->assertInstanceOf(ValidationException::class, $response->exception); $this->assertSame([ 'email' => [ 'These credentials do not match our records.', ], ], $response->exception->errors()); } /** * Handle Request using the following pipeline. * * @param \Illuminate\Http\Request $request * @param callable $callback * @return \Illuminate\Testing\TestResponse */ protected function handleRequestUsing(Request $request, callable $callback) { return new TestResponse( (new Pipeline($this->app)) ->send($request) ->through([ \Illuminate\Session\Middleware\StartSession::class, ]) ->then($callback) ); } }