Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/Concerns/HasFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ protected function getAllGroups(array $groups): Collection

public function groupHasFeature(string $featureName): bool
{
return $this->groups->features->contains('name', $featureName);
return $this->hasFeatureThroughGroup(
feature: $featureName,
);
}

protected function featureExists(string $featureName): bool
Expand Down
142 changes: 142 additions & 0 deletions tests/BladeDirectivesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

declare(strict_types=1);

namespace JustSteveKing\Laravel\FeatureFlags\Tests;

use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
use JustSteveKing\Laravel\FeatureFlags\Models\FeatureGroup;
use JustSteveKing\Laravel\FeatureFlags\Tests\Stubs\User;
use JustSteveKing\Laravel\FeatureFlags\Models\Feature;
use Illuminate\Support\Facades\Hash;

class BladeDirectivesTest extends TestCase
{
use InteractsWithViews;

/**
* @test
*/
public function it_shows_feature_to_user_that_have_feature()
{
$user = User::create([
'name' => 'test user',
'email' => 'test@user.com',
'password' => Hash::make('password')
]);

$feature = Feature::create([
'name' => 'test'
]);

$user->giveFeature($feature->name);

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

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

/**
* @test
*/
public function it_shows_feature_to_user_in_feature_group()
{
$user = User::create([
'name' => 'test user',
'email' => 'test@user.com',
'password' => Hash::make('password')
]);

$group = FeatureGroup::create([
'name' => 'Test Group',
]);

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

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

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

/**
* @test
*/
public function it_shows_feature_to_user_when_feature_group_has_feature()
{
$user = User::create([
'name' => 'test user',
'email' => 'test@user.com',
'password' => Hash::make('password')
]);

$feature = Feature::create([
'name' => 'test'
]);

$group = FeatureGroup::create([
'name' => 'Test Group',
]);

$group->addFeature($feature);

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

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

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

/**
* @test
*/
public function it_hides_feature_to_user_that_dont_have_feature()
{
$user = User::create([
'name' => 'test user',
'email' => 'test@user.com',
'password' => Hash::make('password')
]);

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

$view->assertSee('');
}

/**
* @test
*/
public function it_hides_feature_to_user_not_in_feature_group()
{
$user = User::create([
'name' => 'test user',
'email' => 'test@user.com',
'password' => Hash::make('password')
]);

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

$view->assertSee('');
}

/**
* @test
*/
public function it_hides_feature_to_user_when_feature_group_dont_have_feature()
{
$user = User::create([
'name' => 'test user',
'email' => 'test@user.com',
'password' => Hash::make('password')
]);

$group = FeatureGroup::create([
'name' => 'Test Group',
]);

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

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

$view->assertSee('');
}
}