MDL-65919 core: Skip send headers during phpunit exec in dataformats
authorAlberto Lara Hernández <albertolara@moodle.com>
Thu, 13 Jun 2019 20:34:37 +0000 (22:34 +0200)
committerMarina Glancy <marina@moodle.com>
Mon, 30 Sep 2019 10:00:33 +0000 (12:00 +0200)
lib/classes/dataformat/base.php
lib/classes/dataformat/spout_base.php

index d00e46f..b9682b9 100644 (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;
         }
index f7d8a74..55947ef 100644 (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;