diff --git a/lib/tests/tablelib_test.php b/lib/tests/tablelib_test.php index e43fdb11a38..63146696de5 100644 --- a/lib/tests/tablelib_test.php +++ b/lib/tests/tablelib_test.php @@ -618,4 +618,26 @@ class core_tablelib_testcase extends basic_testcase { unset($_GET['tifirst']); $this->assertTrue($table->can_be_reset()); } + + /** + * Test export in CSV format + */ + public function test_table_export() { + $table = new flexible_table('tablelib_test_export'); + $table->define_baseurl('/invalid.php'); + $table->define_columns(['c1', 'c2', 'c3']); + $table->define_headers(['Col1', 'Col2', 'Col3']); + + ob_start(); + $table->is_downloadable(true); + $table->is_downloading('csv'); + + $table->setup(); + $table->add_data(['column0' => 'a', 'column1' => 'b', 'column2' => 'c']); + $output = ob_get_contents(); + ob_end_clean(); + + $this->assertEquals("Col1,Col2,Col3\na,b,c\n", substr($output, 3)); + } + }