Skip to content

Commit df4b7c6

Browse files
committed
test: add the test case for the bug fix.
1 parent 0995b38 commit df4b7c6

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

tests/system/View/TableTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,99 @@ public static function orderedColumnUsecases(): iterable
816816
],
817817
];
818818
}
819+
820+
/**
821+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/8051
822+
*/
823+
public function testGenerateTableWithHeadingContainFieldNamedData(): void
824+
{
825+
$table_template = [
826+
'table_open' => '<table border="1" cellpadding="2" cellspacing="1">',
827+
828+
'thead_open' => '<thead>',
829+
'thead_close' => '</thead>',
830+
831+
'heading_row_start' => '<tr>',
832+
'heading_row_end' => '</tr>',
833+
'heading_cell_start' => '<th>',
834+
'heading_cell_end' => '</th>',
835+
836+
'tfoot_open' => '<tfoot>',
837+
'tfoot_close' => '</tfoot>',
838+
839+
'footing_row_start' => '<tr>',
840+
'footing_row_end' => '</tr>',
841+
'footing_cell_start' => '<td>',
842+
'footing_cell_end' => '</td>',
843+
844+
'tbody_open' => '<tbody>',
845+
'tbody_close' => '</tbody>',
846+
847+
'row_start' => '<tr>',
848+
'row_end' => '</tr>',
849+
'cell_start' => '<td>',
850+
'cell_end' => '</td>',
851+
852+
'row_alt_start' => '<tr>',
853+
'row_alt_end' => '</tr>',
854+
'cell_alt_start' => '<td>',
855+
'cell_alt_end' => '</td>',
856+
857+
'table_close' => '</table>',
858+
];
859+
860+
$table = new \CodeIgniter\View\Table($table_template);
861+
$table->setHeading([
862+
'codigo' => 'Codigo Orçamento',
863+
'data' => 'Data do Orçamento',
864+
'tipo_desconto' => 'Tipo de Desconto',
865+
'valor_desconto' => 'Valor do Desconto',
866+
])->setSyncRowsWithHeading(true);
867+
868+
$sampleData = [
869+
[
870+
'id' => 1,
871+
'id_cliente' => 1,
872+
'codigo' => 'codigo1',
873+
'data' => '2023-10-16 21:53:25',
874+
'tipo_desconto' => 'NENHUM',
875+
'valor_desconto' => '',
876+
'created_at' => '2023-10-16 21:53:25',
877+
'updated_at' => '2023-10-16 21:53:25',
878+
'deleted_at' => '',
879+
],
880+
[
881+
'id' => 2,
882+
'id_cliente' => 2,
883+
'codigo' => 'codigo2',
884+
'data' => '2023-10-16 21:53:25',
885+
'tipo_desconto' => 'REAL',
886+
'valor_desconto' => 10.00,
887+
'created_at' => '2023-10-16 21:53:25',
888+
'updated_at' => '2023-10-16 21:53:25',
889+
'deleted_at' => '',
890+
],
891+
[
892+
'id' => 3,
893+
'id_cliente' => 3,
894+
'codigo' => 'codigo3',
895+
'data' => '2023-10-16 21:53:25',
896+
'tipo_desconto' => 'PERCENTUAL',
897+
'valor_desconto' => 10.00,
898+
'created_at' => '2023-10-16 21:53:25',
899+
'updated_at' => '2023-10-16 21:53:25',
900+
'deleted_at' => '',
901+
],
902+
];
903+
904+
$generated = $table->generate($sampleData);
905+
906+
$this->assertStringContainsString('<th>Codigo Orçamento</th><th>Data do Orçamento</th><th>Tipo de Desconto</th><th>Valor do Desconto</th>', $generated);
907+
908+
$this->assertStringContainsString('<td>codigo1</td><td>2023-10-16 21:53:25</td><td>NENHUM</td><td></td>', $generated);
909+
$this->assertStringContainsString('<td>codigo2</td><td>2023-10-16 21:53:25</td><td>REAL</td><td>10</td>', $generated);
910+
$this->assertStringContainsString('<td>codigo3</td><td>2023-10-16 21:53:25</td><td>PERCENTUAL</td><td>10</td>', $generated);
911+
}
819912
}
820913

821914
// We need this for the _set_from_db_result() test

0 commit comments

Comments
 (0)