44
55use PHPUnit \Framework \Attributes \Test ;
66use Yajra \DataTables \Html \Builder ;
7+ use Yajra \DataTables \Html \Enums \LayoutPosition ;
78use Yajra \DataTables \Html \Layout ;
89
910class LayoutTest extends TestCase
@@ -36,16 +37,16 @@ public function it_can_set_positions(): void
3637 $ layout ->bottom ('test ' , 1 );
3738 $ this ->assertEquals ('test ' , $ layout ->get ('bottom1 ' ));
3839
39- $ layout ->top ('test ' , 1 , ' Start ' );
40+ $ layout ->top ('test ' , 1 , LayoutPosition:: Start);
4041 $ this ->assertEquals ('test ' , $ layout ->get ('top1Start ' ));
4142
42- $ layout ->bottom ('test ' , 1 , ' Start ' );
43+ $ layout ->bottom ('test ' , 1 , LayoutPosition:: Start);
4344 $ this ->assertEquals ('test ' , $ layout ->get ('bottom1Start ' ));
4445
45- $ layout ->top ('test ' , 1 , ' End ' );
46+ $ layout ->top ('test ' , 1 , LayoutPosition:: End);
4647 $ this ->assertEquals ('test ' , $ layout ->get ('top1End ' ));
4748
48- $ layout ->bottom ('test ' , 1 , ' End ' );
49+ $ layout ->bottom ('test ' , 1 , LayoutPosition:: End);
4950 $ this ->assertEquals ('test ' , $ layout ->get ('bottom1End ' ));
5051 }
5152
@@ -62,10 +63,10 @@ public function it_can_be_used_in_builder(): void
6263 $ layout ->bottomEnd ('test ' );
6364 $ layout ->top ('test ' , 1 );
6465 $ layout ->bottom ('test ' , 1 );
65- $ layout ->top ('test ' , 1 , ' Start ' );
66- $ layout ->bottom ('test ' , 1 , ' Start ' );
67- $ layout ->top ('test ' , 1 , ' End ' );
68- $ layout ->bottom ('test ' , 1 , ' End ' );
66+ $ layout ->top ('test ' , 1 , LayoutPosition:: Start);
67+ $ layout ->bottom ('test ' , 1 , LayoutPosition:: Start);
68+ $ layout ->top ('test ' , 1 , LayoutPosition:: End);
69+ $ layout ->bottom ('test ' , 1 , LayoutPosition:: End);
6970 });
7071
7172 $ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
@@ -127,4 +128,55 @@ public function it_can_accept_array_as_parameter_in_builder(): void
127128 $ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
128129 $ this ->assertArrayHasKey ('top ' , $ builder ->getAttributes ()['layout ' ]);
129130 }
131+
132+ #[Test]
133+ public function it_can_accept_callable_as_parameter_in_builder (): void
134+ {
135+ $ builder = resolve (Builder::class);
136+ $ builder ->layout (fn (Layout $ layout ) => $ layout ->top ('test ' ));
137+
138+ $ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
139+ $ this ->assertArrayHasKey ('top ' , $ builder ->getAttributes ()['layout ' ]);
140+ }
141+
142+ #[Test]
143+ public function it_can_accept_js_selector_for_layout_content (): void
144+ {
145+ $ builder = resolve (Builder::class);
146+ $ builder ->layout (fn (Layout $ layout ) => $ layout ->topView ('#test ' ));
147+
148+ $ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
149+ $ this ->assertArrayHasKey ('top ' , $ builder ->getAttributes ()['layout ' ]);
150+ $ this ->assertEquals ("function() { return $('#test').html(); } " , $ builder ->getAttributes ()['layout ' ]['top ' ]);
151+
152+ $ builder ->layout (fn (Layout $ layout ) => $ layout ->bottomView ('#test ' ));
153+ $ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
154+ $ this ->assertArrayHasKey ('bottom ' , $ builder ->getAttributes ()['layout ' ]);
155+ $ this ->assertEquals ("function() { return $('#test').html(); } " , $ builder ->getAttributes ()['layout ' ]['bottom ' ]);
156+
157+ $ builder ->layout (fn (Layout $ layout ) => $ layout ->topStartView ('#test ' ));
158+ $ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
159+ $ this ->assertArrayHasKey ('topStart ' , $ builder ->getAttributes ()['layout ' ]);
160+ $ this ->assertEquals ("function() { return $('#test').html(); } " ,
161+ $ builder ->getAttributes ()['layout ' ]['topStart ' ]);
162+
163+ $ builder ->layout (fn (Layout $ layout ) => $ layout ->topEndView ('#test ' ));
164+ $ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
165+ $ this ->assertArrayHasKey ('topEnd ' , $ builder ->getAttributes ()['layout ' ]);
166+ $ this ->assertEquals ("function() { return $('#test').html(); } " , $ builder ->getAttributes ()['layout ' ]['topEnd ' ]);
167+
168+ $ builder ->layout (fn (Layout $ layout ) => $ layout ->bottomStartView ('#test ' ));
169+ $ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
170+ $ this ->assertArrayHasKey ('bottomStart ' , $ builder ->getAttributes ()['layout ' ]);
171+ $ this ->assertEquals ("function() { return $('#test').html(); } " ,
172+ $ builder ->getAttributes ()['layout ' ]['bottomStart ' ]);
173+
174+ $ builder ->layout (fn (Layout $ layout ) => $ layout ->bottomEndView ('#test ' ));
175+ $ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
176+ $ this ->assertArrayHasKey ('bottomEnd ' , $ builder ->getAttributes ()['layout ' ]);
177+ $ this ->assertEquals (
178+ "function() { return $('#test').html(); } " ,
179+ $ builder ->getAttributes ()['layout ' ]['bottomEnd ' ]
180+ );
181+ }
130182}
0 commit comments