From d43fc5af87744c203d5000a408813a7405b6311a Mon Sep 17 00:00:00 2001 From: freek Date: Fri, 31 Jan 2020 11:09:47 +0100 Subject: [PATCH] add guard config option + fix tests --- ...teOldUnconfirmedSubscribersCommandTest.php | 2 +- Http/Middleware/AuthenticateTest.php | 52 +++++++++++++++++++ TestCase.php | 4 +- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 Http/Middleware/AuthenticateTest.php diff --git a/Commands/DeleteOldUnconfirmedSubscribersCommandTest.php b/Commands/DeleteOldUnconfirmedSubscribersCommandTest.php index 7fa97b3..a7e9a43 100644 --- a/Commands/DeleteOldUnconfirmedSubscribersCommandTest.php +++ b/Commands/DeleteOldUnconfirmedSubscribersCommandTest.php @@ -17,7 +17,7 @@ public function setUp(): void { parent::setUp(); - TestTime::freeze(); + TestTime::freeze('Y-m-d H:i:s', '2019-01-01 00:00:00'); $this->emailList = factory(EmailList::class)->create(['requires_confirmation' => true]); } diff --git a/Http/Middleware/AuthenticateTest.php b/Http/Middleware/AuthenticateTest.php new file mode 100644 index 0000000..81394bf --- /dev/null +++ b/Http/Middleware/AuthenticateTest.php @@ -0,0 +1,52 @@ +name('login'); + + $this->withExceptionHandling(); + } + + /** @test */ + public function it_can_use_the_default_guard() + { + $this->get(route('mailcoach.campaigns'))->assertRedirect(route('login')); + } + + /** @test */ + public function the_default_behaviour_works() + { + $this->authenticate(); + + $this->get(route('mailcoach.campaigns'))->assertSuccessful(); + } + + /** @test */ + public function it_will_fail_when_authentication_with_a_wrong_guard() + { + config()->set('mailcoach.guard', 'api'); + + $this->authenticate('web'); + + $this->get(route('mailcoach.campaigns'))->assertRedirect(route('login')); + } + + /** @test */ + public function it_can_authenticate_using_the_guard_specified_in_the_config_file() + { + config()->set('mailcoach.guard', 'api'); + + $this->authenticate('api'); + + $this->get(route('mailcoach.campaigns'))->assertSuccessful(); + } +} diff --git a/TestCase.php b/TestCase.php index 088329d..ae32258 100644 --- a/TestCase.php +++ b/TestCase.php @@ -75,11 +75,11 @@ protected function simulateUnsubscribes(Collection $sends) }); } - public function authenticate() + public function authenticate(string $guard = null) { $user = factory(User::class)->create(); - $this->actingAs($user); + $this->actingAs($user, $guard); } public function assertMatchesHtmlSnapshotWithoutWhitespace(string $content)