From 7d669662519af4502e369723db4b49644f44aefe Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Mon, 30 Sep 2024 15:40:37 +0100 Subject: [PATCH] [1.x] Add a new `@featureany` directive (#122) * Blade: Add new featureany directive * Tests/Blade: Add tests for new featureany directive --- src/PennantServiceProvider.php | 4 ++++ tests/Feature/FeatureDirectiveTest.php | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/PennantServiceProvider.php b/src/PennantServiceProvider.php index 7796578..b454f2a 100644 --- a/src/PennantServiceProvider.php +++ b/src/PennantServiceProvider.php @@ -43,6 +43,10 @@ public function boot() return Feature::active($feature); }); + + $blade->if('featureany', function ($features) { + return Feature::someAreActive($features); + }); }); $this->listenForEvents(); diff --git a/tests/Feature/FeatureDirectiveTest.php b/tests/Feature/FeatureDirectiveTest.php index 4511951..bc255b9 100644 --- a/tests/Feature/FeatureDirectiveTest.php +++ b/tests/Feature/FeatureDirectiveTest.php @@ -76,4 +76,27 @@ public function test_it_checks_features_against_default_scope_by_default() $output = trim(Blade::render($blade)); $this->assertSame('foo is 888', $output); } + + public function test_it_renders_any_active_features() + { + $blade = <<<'BLADE' + @featureany(['foo', 'bar']) + foo or bar is active + @else + foo and bar are inactive + @endfeatureany + BLADE; + + $output = trim(Blade::render($blade)); + $this->assertSame('foo and bar are inactive', $output); + + Feature::activate('foo'); + $output = trim(Blade::render($blade)); + $this->assertSame('foo or bar is active', $output); + + Feature::deactivate('foo'); + Feature::activate('bar'); + $output = trim(Blade::render($blade)); + $this->assertSame('foo or bar is active', $output); + } }