Skip to content

Commit

Permalink
add guard config option + fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jan 31, 2020
1 parent f8b80f1 commit d43fc5a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Commands/DeleteOldUnconfirmedSubscribersCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
52 changes: 52 additions & 0 deletions Http/Middleware/AuthenticateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Spatie\Mailcoach\Tests\Http\Middleware;

use Illuminate\Support\Facades\Route;
use Spatie\Mailcoach\Tests\TestCase;

class AuthenticateTest extends TestCase
{
public function setUp(): void
{
parent::setUp();

Route::get('login')->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();
}
}
4 changes: 2 additions & 2 deletions TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d43fc5a

Please sign in to comment.