4
4
5
5
use PHPUnit \Framework \Attributes \Test ;
6
6
use Yajra \DataTables \Html \Builder ;
7
+ use Yajra \DataTables \Html \Enums \LayoutPosition ;
7
8
use Yajra \DataTables \Html \Layout ;
8
9
9
10
class LayoutTest extends TestCase
@@ -36,16 +37,16 @@ public function it_can_set_positions(): void
36
37
$ layout ->bottom ('test ' , 1 );
37
38
$ this ->assertEquals ('test ' , $ layout ->get ('bottom1 ' ));
38
39
39
- $ layout ->top ('test ' , 1 , ' Start ' );
40
+ $ layout ->top ('test ' , 1 , LayoutPosition:: Start);
40
41
$ this ->assertEquals ('test ' , $ layout ->get ('top1Start ' ));
41
42
42
- $ layout ->bottom ('test ' , 1 , ' Start ' );
43
+ $ layout ->bottom ('test ' , 1 , LayoutPosition:: Start);
43
44
$ this ->assertEquals ('test ' , $ layout ->get ('bottom1Start ' ));
44
45
45
- $ layout ->top ('test ' , 1 , ' End ' );
46
+ $ layout ->top ('test ' , 1 , LayoutPosition:: End);
46
47
$ this ->assertEquals ('test ' , $ layout ->get ('top1End ' ));
47
48
48
- $ layout ->bottom ('test ' , 1 , ' End ' );
49
+ $ layout ->bottom ('test ' , 1 , LayoutPosition:: End);
49
50
$ this ->assertEquals ('test ' , $ layout ->get ('bottom1End ' ));
50
51
}
51
52
@@ -62,10 +63,10 @@ public function it_can_be_used_in_builder(): void
62
63
$ layout ->bottomEnd ('test ' );
63
64
$ layout ->top ('test ' , 1 );
64
65
$ 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);
69
70
});
70
71
71
72
$ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
@@ -127,4 +128,55 @@ public function it_can_accept_array_as_parameter_in_builder(): void
127
128
$ this ->assertArrayHasKey ('layout ' , $ builder ->getAttributes ());
128
129
$ this ->assertArrayHasKey ('top ' , $ builder ->getAttributes ()['layout ' ]);
129
130
}
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
+ }
130
182
}
0 commit comments