1+ <?php
2+
3+ use Filament \Panel ;
4+ use Redberry \PageBuilderPlugin \GlobalBlocksPlugin ;
5+ use Redberry \PageBuilderPlugin \Resources \GlobalBlockConfigResource ;
6+
7+ it ('can be instantiated ' , function () {
8+ $ plugin = GlobalBlocksPlugin::make ();
9+
10+ expect ($ plugin )->toBeInstanceOf (GlobalBlocksPlugin::class);
11+ });
12+
13+ it ('has correct plugin ID ' , function () {
14+ $ plugin = GlobalBlocksPlugin::make ();
15+
16+ expect ($ plugin ->getId ())->toBe ('page-builder-global-blocks ' );
17+ });
18+
19+ it ('can configure enable global blocks ' , function () {
20+ $ plugin = GlobalBlocksPlugin::make ()
21+ ->enableGlobalBlocks (false );
22+
23+ expect ($ plugin )->toBeInstanceOf (GlobalBlocksPlugin::class);
24+ });
25+
26+ it ('can configure custom resource ' , function () {
27+ $ customResourceClass = 'App \\Filament \\Resources \\CustomGlobalBlocksResource ' ;
28+
29+ $ plugin = GlobalBlocksPlugin::make ()
30+ ->resource ($ customResourceClass );
31+
32+ expect ($ plugin )->toBeInstanceOf (GlobalBlocksPlugin::class);
33+ });
34+
35+ it ('registers resource when enabled ' , function () {
36+ $ panel = Panel::make ();
37+
38+ $ plugin = GlobalBlocksPlugin::make ()
39+ ->enableGlobalBlocks (true );
40+
41+ $ plugin ->register ($ panel );
42+
43+ expect ($ panel ->getResources ())->toContain (GlobalBlockConfigResource::class);
44+ });
45+
46+ it ('does not register resource when disabled ' , function () {
47+ $ panel = Panel::make ();
48+
49+ $ plugin = GlobalBlocksPlugin::make ()
50+ ->enableGlobalBlocks (false );
51+
52+ $ plugin ->register ($ panel );
53+
54+ expect ($ panel ->getResources ())->not ->toContain (GlobalBlockConfigResource::class);
55+ });
56+
57+ it ('registers custom resource when specified ' , function () {
58+ $ customResourceClass = GlobalBlockConfigResource::class; // Using existing class for test
59+ $ panel = Panel::make ();
60+
61+ $ plugin = GlobalBlocksPlugin::make ()
62+ ->resource ($ customResourceClass );
63+
64+ $ plugin ->register ($ panel );
65+
66+ expect ($ panel ->getResources ())->toContain ($ customResourceClass );
67+ });
68+
69+ it ('handles non-existent resource class gracefully ' , function () {
70+ $ panel = Panel::make ();
71+
72+ $ plugin = GlobalBlocksPlugin::make ()
73+ ->resource ('NonExistentResourceClass ' );
74+
75+ $ plugin ->register ($ panel );
76+
77+ expect ($ panel ->getResources ())->toBeEmpty ();
78+ });
0 commit comments