Skip to content

Commit 035cc97

Browse files
committed
test: add format column using closure
1 parent dc7a8fe commit 035cc97

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/Integration/EloquentDataTableTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@ public function it_can_return_formatted_columns()
121121
$this->assertEquals(Carbon::parse($user->created_at)->format('Y-m-d'), $data['created_at_formatted']);
122122
}
123123

124+
/** @test */
125+
public function it_can_return_formatted_column_using_closure()
126+
{
127+
$crawler = $this->call('GET', '/eloquent/formatColumn-closure');
128+
129+
$crawler->assertJson([
130+
'draw' => 0,
131+
'recordsTotal' => 20,
132+
'recordsFiltered' => 20,
133+
]);
134+
135+
$user = User::find(1);
136+
$data = $crawler->json('data')[0];
137+
138+
$this->assertTrue(isset($data['created_at']));
139+
$this->assertTrue(isset($data['created_at_formatted']));
140+
141+
$this->assertEquals(Carbon::parse($user->created_at)->format('Y-m-d'), $data['created_at_formatted']);
142+
}
143+
124144
/** @test */
125145
public function it_accepts_a_relation()
126146
{
@@ -152,5 +172,10 @@ protected function setUp(): void
152172
->formatColumn('created_at', new DateFormatter('Y-m-d'))
153173
->toJson();
154174
});
175+
$router->get('/eloquent/formatColumn-closure', function (DataTables $dataTable) {
176+
return $dataTable->eloquent(User::query())
177+
->formatColumn('created_at', fn($value, $row) => Carbon::parse($value)->format('Y-m-d'))
178+
->toJson();
179+
});
155180
}
156181
}

0 commit comments

Comments
 (0)