diff --git a/src/GuardEvaluator.php b/src/GuardEvaluator.php index 2f5a65d..db4c44b 100644 --- a/src/GuardEvaluator.php +++ b/src/GuardEvaluator.php @@ -17,7 +17,7 @@ public function __construct(ExpressionLanguage $expressionLanguage) protected function registerCustomFunctions() { - $customFunctions = config('workflow.custom_functions', []); + $customFunctions = config('workflow-process.custom_functions', []); foreach ($customFunctions as $name => $definition) { if (is_string($definition) && class_exists($definition)) { diff --git a/tests/Feature/GuardFunctions/AuthenticatedTest.php b/tests/Feature/GuardFunctions/AuthenticatedTest.php new file mode 100644 index 0000000..f7d710a --- /dev/null +++ b/tests/Feature/GuardFunctions/AuthenticatedTest.php @@ -0,0 +1,56 @@ +compile(); + expect($compiled)->toBe('authenticated("web")'); +}); + +test('compile returns authenticated("custom") when a custom guard is provided', function () { + $guardFunction = new Authenticated; + $compiled = $guardFunction->compile('custom'); + expect($compiled)->toBe('authenticated("custom")'); +}); + +test('evaluate returns true when the default guard is authenticated', function () { + $guardFunction = new Authenticated; + + // Create a mock for the default "web" guard that returns true for check(). + $guardMock = Mockery::mock(); + $guardMock->shouldReceive('check')->once()->andReturn(true); + + // Expect the default guard to be used. + Auth::shouldReceive('guard') + ->once() + ->with('web') + ->andReturn($guardMock); + + $result = $guardFunction->evaluate([]); + expect($result)->toBeTrue(); +}); + +test('evaluate returns false when the custom guard is not authenticated', function () { + $guardFunction = new Authenticated; + + // Create a mock for the "custom" guard that returns false for check(). + $guardMock = Mockery::mock(); + $guardMock->shouldReceive('check')->once()->andReturn(false); + + // Expect the custom guard to be used. + Auth::shouldReceive('guard') + ->once() + ->with('custom') + ->andReturn($guardMock); + + $result = $guardFunction->evaluate([], 'custom'); + expect($result)->toBeFalse(); +}); diff --git a/tests/GuardEvaluatorTest.php b/tests/GuardEvaluatorTest.php index 64fd5a3..6f3259b 100644 --- a/tests/GuardEvaluatorTest.php +++ b/tests/GuardEvaluatorTest.php @@ -7,7 +7,7 @@ it('evaluates a custom closure guard function correctly', function () { // Set a test configuration for custom guard functions. // Here we define a function named "checkFlag" that returns the value of a 'flag' variable. - config()->set('workflow.custom_functions', [ + config()->set('workflow-process.custom_functions', [ 'checkFlag' => [ 'compiler' => function () { // The compiler returns a placeholder expression. @@ -35,7 +35,7 @@ it('evaluates a custom guard function defined as a class correctly', function () { // Set the configuration so that the custom function points to our evaluator class. - config()->set('workflow.custom_functions', [ + config()->set('workflow-process.custom_functions', [ 'checkFlag' => CheckFlagGuardFunction::class, ]);