From e81f40e1b988d52b5f69729252908141b6bd20a6 Mon Sep 17 00:00:00 2001 From: Enea Barbetta Date: Sun, 10 Jan 2021 15:41:23 +0100 Subject: [PATCH] Added a @notImpersonating blade directive --- src/ImpersonateServiceProvider.php | 8 ++++++++ tests/BladeDirectivesTest.php | 23 +++++++++++++++++++++++ tests/Stubs/views/impersonate.blade.php | 6 +++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/ImpersonateServiceProvider.php b/src/ImpersonateServiceProvider.php index 0082015..86b2a62 100644 --- a/src/ImpersonateServiceProvider.php +++ b/src/ImpersonateServiceProvider.php @@ -80,6 +80,14 @@ protected function registerBladeDirectives() return ''; }); + $bladeCompiler->directive('notImpersonating', function () { + return ""; + }); + + $bladeCompiler->directive('endNotImpersonating', function () { + return ''; + }); + $bladeCompiler->directive('canImpersonate', function ($guard = null) { return ""; }); diff --git a/tests/BladeDirectivesTest.php b/tests/BladeDirectivesTest.php index 0570b66..9b14bcd 100644 --- a/tests/BladeDirectivesTest.php +++ b/tests/BladeDirectivesTest.php @@ -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(); + } + /** @test */ public function it_displays_can_be_impersonated_content_directive() { diff --git a/tests/Stubs/views/impersonate.blade.php b/tests/Stubs/views/impersonate.blade.php index d445ed0..53cf248 100644 --- a/tests/Stubs/views/impersonate.blade.php +++ b/tests/Stubs/views/impersonate.blade.php @@ -6,4 +6,8 @@ @canImpersonate Impersonate this user -@endCanImpersonate \ No newline at end of file +@endCanImpersonate + +@notImpersonating +Not impersonating this user +@endNotImpersonating \ No newline at end of file