Skip to content

Commit

Permalink
test: add the test case for the bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
ping-yee committed Oct 20, 2023
1 parent 0995b38 commit df4b7c6
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions tests/system/View/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,99 @@ public static function orderedColumnUsecases(): iterable
],
];
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/8051
*/
public function testGenerateTableWithHeadingContainFieldNamedData(): void
{
$table_template = [
'table_open' => '<table border="1" cellpadding="2" cellspacing="1">',

'thead_open' => '<thead>',
'thead_close' => '</thead>',

'heading_row_start' => '<tr>',
'heading_row_end' => '</tr>',
'heading_cell_start' => '<th>',
'heading_cell_end' => '</th>',

'tfoot_open' => '<tfoot>',
'tfoot_close' => '</tfoot>',

'footing_row_start' => '<tr>',
'footing_row_end' => '</tr>',
'footing_cell_start' => '<td>',
'footing_cell_end' => '</td>',

'tbody_open' => '<tbody>',
'tbody_close' => '</tbody>',

'row_start' => '<tr>',
'row_end' => '</tr>',
'cell_start' => '<td>',
'cell_end' => '</td>',

'row_alt_start' => '<tr>',
'row_alt_end' => '</tr>',
'cell_alt_start' => '<td>',
'cell_alt_end' => '</td>',

'table_close' => '</table>',
];

$table = new \CodeIgniter\View\Table($table_template);
$table->setHeading([
'codigo' => 'Codigo Orçamento',
'data' => 'Data do Orçamento',
'tipo_desconto' => 'Tipo de Desconto',
'valor_desconto' => 'Valor do Desconto',
])->setSyncRowsWithHeading(true);

$sampleData = [
[
'id' => 1,
'id_cliente' => 1,
'codigo' => 'codigo1',
'data' => '2023-10-16 21:53:25',
'tipo_desconto' => 'NENHUM',
'valor_desconto' => '',
'created_at' => '2023-10-16 21:53:25',
'updated_at' => '2023-10-16 21:53:25',
'deleted_at' => '',
],
[
'id' => 2,
'id_cliente' => 2,
'codigo' => 'codigo2',
'data' => '2023-10-16 21:53:25',
'tipo_desconto' => 'REAL',
'valor_desconto' => 10.00,
'created_at' => '2023-10-16 21:53:25',
'updated_at' => '2023-10-16 21:53:25',
'deleted_at' => '',
],
[
'id' => 3,
'id_cliente' => 3,
'codigo' => 'codigo3',
'data' => '2023-10-16 21:53:25',
'tipo_desconto' => 'PERCENTUAL',
'valor_desconto' => 10.00,
'created_at' => '2023-10-16 21:53:25',
'updated_at' => '2023-10-16 21:53:25',
'deleted_at' => '',
],
];

$generated = $table->generate($sampleData);

$this->assertStringContainsString('<th>Codigo Orçamento</th><th>Data do Orçamento</th><th>Tipo de Desconto</th><th>Valor do Desconto</th>', $generated);

$this->assertStringContainsString('<td>codigo1</td><td>2023-10-16 21:53:25</td><td>NENHUM</td><td></td>', $generated);
$this->assertStringContainsString('<td>codigo2</td><td>2023-10-16 21:53:25</td><td>REAL</td><td>10</td>', $generated);
$this->assertStringContainsString('<td>codigo3</td><td>2023-10-16 21:53:25</td><td>PERCENTUAL</td><td>10</td>', $generated);
}
}

// We need this for the _set_from_db_result() test
Expand Down

0 comments on commit df4b7c6

Please sign in to comment.