Skip to content
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
6 changes: 4 additions & 2 deletions src/Concerns/HasFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ public function inGroup(...$groups): bool
$group = strtolower($group);
}

return !! FeatureGroup::active()
return $this
->groups()
->active()
->whereIn('name', $groups)
->count();
->count() > 0;
}

public function leaveGroup(...$groups): self
Expand Down
14 changes: 11 additions & 3 deletions tests/Unit/BladeDirectivesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,23 @@
});

it('hides feature to user that dont have feature', function(): void {
Feature::create([
'name' => 'Test',
]);

$view = $this->actingAs($this->user)->blade("@feature('test') active feature @endfeature");

$view->assertSee('');
$view->assertDontSee('active feature');
});

it('hides feature to user that not in feature group', function(): void {
FeatureGroup::create([
'name' => 'Test Group',
]);

$view = $this->actingAs($this->user)->blade("@featuregroup('test group') active feature @endfeaturegroup");

$view->assertSee('');
$view->assertDontSee('active feature');
});

it('hides feature to user when feature group dont have feature', function(): void {
Expand All @@ -81,5 +89,5 @@

$view = $this->actingAs($this->user)->blade("@groupfeature('test') active feature @endgroupfeature");

$view->assertSee('');
$view->assertDontSee('active feature');
});
4 changes: 4 additions & 0 deletions tests/Unit/FeatureGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
'password' => Hash::make('password')
]);

expect($user)
->inGroup($this->group->name)
->toBeFalse();

$user->joinGroup($this->group->name);

expect($user)
Expand Down