33namespace Code16 \Sharp \Utils \Testing ;
44
55use Closure ;
6+ use Code16 \Sharp \Filters \GlobalFilters \GlobalFilters ;
67use Code16 \Sharp \Http \Context \SharpBreadcrumb ;
78use Code16 \Sharp \Utils \Entities \SharpEntityManager ;
89use Code16 \Sharp \Utils \Links \BreadcrumbBuilder ;
910use Code16 \Sharp \Utils \Testing \Dashboard \PendingDashboard ;
1011use Code16 \Sharp \Utils \Testing \EntityList \PendingEntityList ;
1112use Code16 \Sharp \Utils \Testing \Form \PendingForm ;
1213use Code16 \Sharp \Utils \Testing \Show \PendingShow ;
14+ use Illuminate \Support \Facades \URL ;
1315
1416trait SharpAssertions
1517{
1618 use GeneratesCurrentPageUrl;
17- use GeneratesGlobalFilterUrl;
1819
1920 private BreadcrumbBuilder $ breadcrumbBuilder ;
21+ private ?string $ globalFilter = null ;
22+
23+ public function setUpSharpAssertions (): void
24+ {
25+ URL ::defaults (['globalFilter ' => $ this ->globalFilter ?: GlobalFilters::$ defaultKey ]);
26+ }
2027
2128 public function sharpList (string $ entityClassNameOrKey ): PendingEntityList
2229 {
@@ -38,6 +45,16 @@ public function sharpDashboard(string $entityClassNameOrKey): PendingDashboard
3845 return new PendingDashboard ($ this , $ entityClassNameOrKey );
3946 }
4047
48+ public function withSharpGlobalFilterValues (array |string $ globalFilterValues ): self
49+ {
50+ $ this ->globalFilter = collect ((array ) $ globalFilterValues )
51+ ->implode (GlobalFilters::$ valuesUrlSeparator );
52+
53+ URL ::defaults (['globalFilter ' => $ this ->globalFilter ?: GlobalFilters::$ defaultKey ]);
54+
55+ return $ this ;
56+ }
57+
4158 /**
4259 * @deprecated use withSharpBreadcrumb() instead
4360 */
@@ -69,8 +86,6 @@ public function withSharpBreadcrumb(Closure $callback): self
6986
7087 public function deleteFromSharpShow (string $ entityClassNameOrKey , mixed $ instanceId )
7188 {
72- $ this ->setGlobalFilterUrlDefault ();
73-
7489 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
7590
7691 return $ this
@@ -88,8 +103,6 @@ public function deleteFromSharpShow(string $entityClassNameOrKey, mixed $instanc
88103
89104 public function deleteFromSharpList (string $ entityClassNameOrKey , mixed $ instanceId )
90105 {
91- $ this ->setGlobalFilterUrlDefault ();
92-
93106 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
94107
95108 return $ this
@@ -110,8 +123,6 @@ public function deleteFromSharpList(string $entityClassNameOrKey, mixed $instanc
110123
111124 public function getSharpForm (string $ entityClassNameOrKey , mixed $ instanceId = null )
112125 {
113- $ this ->setGlobalFilterUrlDefault ();
114-
115126 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
116127
117128 return $ this
@@ -139,8 +150,6 @@ public function getSharpForm(string $entityClassNameOrKey, mixed $instanceId = n
139150
140151 public function getSharpSingleForm (string $ entityClassNameOrKey )
141152 {
142- $ this ->setGlobalFilterUrlDefault ();
143-
144153 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
145154
146155 return $ this
@@ -158,8 +167,6 @@ public function getSharpSingleForm(string $entityClassNameOrKey)
158167
159168 public function updateSharpForm (string $ entityClassNameOrKey , $ instanceId , array $ data )
160169 {
161- $ this ->setGlobalFilterUrlDefault ();
162-
163170 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
164171
165172 return $ this
@@ -178,8 +185,6 @@ public function updateSharpForm(string $entityClassNameOrKey, $instanceId, array
178185
179186 public function updateSharpSingleForm (string $ entityClassNameOrKey , array $ data )
180187 {
181- $ this ->setGlobalFilterUrlDefault ();
182-
183188 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
184189
185190 return $ this
@@ -197,8 +202,6 @@ public function updateSharpSingleForm(string $entityClassNameOrKey, array $data)
197202
198203 public function getSharpShow (string $ entityClassNameOrKey , $ instanceId )
199204 {
200- $ this ->setGlobalFilterUrlDefault ();
201-
202205 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
203206
204207 return $ this
@@ -217,8 +220,6 @@ public function getSharpShow(string $entityClassNameOrKey, $instanceId)
217220
218221 public function storeSharpForm (string $ entityClassNameOrKey , array $ data )
219222 {
220- $ this ->setGlobalFilterUrlDefault ();
221-
222223 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
223224
224225 return $ this
@@ -242,8 +243,6 @@ public function callSharpInstanceCommandFromList(
242243 array $ data = [],
243244 ?string $ commandStep = null
244245 ) {
245- $ this ->setGlobalFilterUrlDefault ();
246-
247246 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
248247
249248 $ commandKey = class_exists ($ commandKeyOrClassName )
@@ -273,8 +272,6 @@ public function callSharpInstanceCommandFromShow(
273272 array $ data = [],
274273 ?string $ commandStep = null
275274 ) {
276- $ this ->setGlobalFilterUrlDefault ();
277-
278275 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
279276
280277 $ commandKey = class_exists ($ commandKeyOrClassName )
@@ -303,8 +300,6 @@ public function callSharpEntityCommandFromList(
303300 array $ data = [],
304301 ?string $ commandStep = null
305302 ) {
306- $ this ->setGlobalFilterUrlDefault ();
307-
308303 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
309304
310305 $ commandKey = class_exists ($ commandKeyOrClassName )
0 commit comments