Skip to content

Commit 436869a

Browse files
committed
test: test configurable discovery paths functionality
1 parent a727f1c commit 436869a

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

src/Models/GlobalBlockConfig.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ protected static function discoverGlobalBlocks(): array
8989
$globalBlocks = [];
9090
$appPath = app_path();
9191

92-
$discoveryPaths = config('page-builder-plugin.global_blocks_discovery_paths', [
93-
'app/Filament/*/Blocks/Globals',
94-
]);
92+
$discoveryPaths = config('page-builder-plugin.global_blocks_discovery_paths', []);
9593

9694
$globalsDirectories = [];
9795

tests/Models/GlobalBlockConfigTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,61 @@
5959

6060
expect($config->getConfigValue('title'))->toBeNull();
6161
});
62+
63+
it('returns empty array when no discovery paths configured', function () {
64+
config(['page-builder-plugin.global_blocks_discovery_paths' => []]);
65+
66+
$method = new ReflectionMethod(GlobalBlockConfig::class, 'discoverGlobalBlocks');
67+
$method->setAccessible(true);
68+
69+
$blocks = $method->invoke(new GlobalBlockConfig());
70+
71+
expect($blocks)->toBe([]);
72+
});
73+
74+
it('processes glob patterns correctly', function () {
75+
config(['page-builder-plugin.global_blocks_discovery_paths' => ['tests/non-existent/*/path']]);
76+
77+
$method = new ReflectionMethod(GlobalBlockConfig::class, 'discoverGlobalBlocks');
78+
$method->setAccessible(true);
79+
80+
$blocks = $method->invoke(new GlobalBlockConfig());
81+
82+
expect($blocks)->toBe([]);
83+
});
84+
85+
it('processes direct paths correctly', function () {
86+
config(['page-builder-plugin.global_blocks_discovery_paths' => ['tests/non-existent/direct/path']]);
87+
88+
$method = new ReflectionMethod(GlobalBlockConfig::class, 'discoverGlobalBlocks');
89+
$method->setAccessible(true);
90+
91+
$blocks = $method->invoke(new GlobalBlockConfig());
92+
93+
expect($blocks)->toBe([]);
94+
});
95+
96+
it('handles mixed path types in configuration', function () {
97+
config(['page-builder-plugin.global_blocks_discovery_paths' => [
98+
'non/existent/direct/path',
99+
'non/existent/*/glob/path'
100+
]]);
101+
102+
$method = new ReflectionMethod(GlobalBlockConfig::class, 'discoverGlobalBlocks');
103+
$method->setAccessible(true);
104+
105+
$blocks = $method->invoke(new GlobalBlockConfig());
106+
107+
expect($blocks)->toBe([]);
108+
});
109+
110+
it('correctly identifies glob patterns by checking for asterisk', function () {
111+
config(['page-builder-plugin.global_blocks_discovery_paths' => ['test/path/without/asterisk']]);
112+
113+
$method = new ReflectionMethod(GlobalBlockConfig::class, 'discoverGlobalBlocks');
114+
$method->setAccessible(true);
115+
116+
$blocks = $method->invoke(new GlobalBlockConfig());
117+
118+
expect($blocks)->toBe([]);
119+
});

0 commit comments

Comments
 (0)