Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a @notImpersonating blade directive #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/ImpersonateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ protected function registerBladeDirectives()
return '<?php endif; ?>';
});

$bladeCompiler->directive('notImpersonating', function () {
return "<?php if (!is_impersonating()) : ?>";
});

$bladeCompiler->directive('endNotImpersonating', function () {
return '<?php endif; ?>';
});

$bladeCompiler->directive('canImpersonate', function ($guard = null) {
return "<?php if (can_impersonate({$guard})) : ?>";
});
Expand Down
23 changes: 23 additions & 0 deletions tests/BladeDirectivesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ public function it_not_displays_impersonating_content_directive()
$this->logout();
}

/** @test */
public function it_displays_not_impersonating_content_directive() {
$this->actingAs($this->user);
$this->makeView();
$this->assertStringContainsString('Not impersonating this user', $this->view);
$this->logout();

$this->actingAs($this->admin);
$this->makeView();
$this->assertStringContainsString('Not impersonating this user', $this->view);
$this->logout();
}

/** @test */
public function it_not_displays_not_impersonating_content_directive() {
$this->actingAs($this->admin);
$this->admin->impersonate($this->user);
$this->makeView();
$this->assertStringNotContainsString('Not impersonating this user', $this->view);
$this->admin->leaveImpersonation();
$this->logout();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other tests don't call ->impersonate and ->leaveImpersonation, so I wonder if it would make sense to add another assertion to ensure that after leaving impersonation the Not Impersonating message re-appears?


/** @test */
public function it_displays_can_be_impersonated_content_directive()
{
Expand Down
6 changes: 5 additions & 1 deletion tests/Stubs/views/impersonate.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

@canImpersonate
<a href="{{ route('impersonate', 2) }}">Impersonate this user</a>
@endCanImpersonate
@endCanImpersonate

@notImpersonating
Not impersonating this user
@endNotImpersonating