mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
Merge branch 'MDL-46772-master' of git://github.com/andrewnicols/moodle
This commit is contained in:
commit
fc9b567f32
@ -1611,7 +1611,13 @@ class html_writer {
|
||||
$row->attributes['class'] .= ' lastrow';
|
||||
}
|
||||
|
||||
$output .= html_writer::start_tag('tr', array('class' => trim($row->attributes['class']), 'style' => $row->style, 'id' => $row->id)) . "\n";
|
||||
// Explicitly assigned properties should override those defined in the attributes.
|
||||
$row->attributes['class'] = trim($row->attributes['class']);
|
||||
$trattributes = array_merge($row->attributes, array(
|
||||
'id' => $row->id,
|
||||
'style' => $row->style,
|
||||
));
|
||||
$output .= html_writer::start_tag('tr', $trattributes) . "\n";
|
||||
$keys2 = array_keys($row->cells);
|
||||
$lastkey = end($keys2);
|
||||
|
||||
|
@ -168,4 +168,51 @@ class core_html_writer_testcase extends basic_testcase {
|
||||
public function test_end_span() {
|
||||
$this->assertSame('</span>', html_writer::end_span());
|
||||
}
|
||||
|
||||
public function test_table() {
|
||||
$row = new html_table_row();
|
||||
|
||||
// The attribute will get overwritten by the ID.
|
||||
$row->id = 'Bob';
|
||||
$row->attributes['id'] = 'will get overwritten';
|
||||
|
||||
// The data-name will be present in the output.
|
||||
$row->attributes['data-name'] = 'Fred';
|
||||
$row->class = 'this is a table row';
|
||||
|
||||
$cell = new html_table_cell();
|
||||
|
||||
// The attribute will get overwritten by the ID.
|
||||
$cell->id = 'Jeremy';
|
||||
$cell->attributes['id'] = 'will get overwritten';
|
||||
|
||||
// The data-name will be present in the output.
|
||||
$cell->attributes['data-name'] = 'John';
|
||||
$cell->class = 'this is a table cell';
|
||||
|
||||
$row->cells[] = $cell;
|
||||
|
||||
$table = new html_table();
|
||||
// The attribute will get overwritten by the ID.
|
||||
$table->id = 'Jeffrey';
|
||||
$table->attributes['id'] = 'will get overwritten';
|
||||
|
||||
// The data-name will be present in the output.
|
||||
$table->attributes['data-name'] = 'Colin';
|
||||
// The attribute will get overwritten by the ID above.
|
||||
$table->data[] = $row;
|
||||
|
||||
$output = html_writer::table($table);
|
||||
|
||||
$expected = <<<EOF
|
||||
<table class="generaltable" id="Jeffrey" data-name="Colin">
|
||||
<tbody><tr class="r0 lastrow" id="Bob" data-name="Fred">
|
||||
<td class="cell c0 lastcol" id="Jeremy" data-name="John" style=""></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
EOF;
|
||||
$this->assertSame($expected, $output);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user