Merge branch 'MDL-65919-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Adrian Greeve
2019-10-03 15:59:03 +08:00
3 changed files with 28 additions and 2 deletions
+1 -1
View File
@@ -76,7 +76,7 @@ abstract class base {
* Output file headers to initialise the download of the file.
*/
public function send_http_headers() {
if (defined('BEHAT_SITE_RUNNING')) {
if (defined('BEHAT_SITE_RUNNING') || PHPUNIT_TEST) {
// For text based formats - we cannot test the output with behat if we force a file download.
return;
}
+5 -1
View File
@@ -56,7 +56,11 @@ abstract class spout_base extends \core\dataformat\base {
$this->writer->setTempFolder(make_request_directory());
}
$filename = $this->filename . $this->get_extension();
$this->writer->openToBrowser($filename);
if (PHPUNIT_TEST) {
$this->writer->openToFile('php://output');
} else {
$this->writer->openToBrowser($filename);
}
// By default one sheet is always created, but we want to rename it when we call start_sheet().
$this->renamecurrentsheet = true;
+22
View File
@@ -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));
}
}