diff --git a/admin/tool/admin_presets/tests/behat/behat_admin_presets.php b/admin/tool/admin_presets/tests/behat/behat_admin_presets.php index 23b8f9ff31a0c..48d0507954014 100644 --- a/admin/tool/admin_presets/tests/behat/behat_admin_presets.php +++ b/admin/tool/admin_presets/tests/behat/behat_admin_presets.php @@ -63,6 +63,7 @@ class behat_admin_presets extends behat_base { */ final public function following_in_the_should_download_between_and_bytes(string $link, string $selectortype, string $nodeelement, string $nodeselectortype, int $minexpectedsize, int $maxexpectedsize): void { + // TO BE DEPRECATED. // If the minimum is greater than the maximum then swap the values. if ((int) $minexpectedsize > (int) $maxexpectedsize) { list($minexpectedsize, $maxexpectedsize) = [$maxexpectedsize, $minexpectedsize]; diff --git a/admin/tool/admin_presets/tests/behat/download.feature b/admin/tool/admin_presets/tests/behat/download.feature index 2866028325f8d..94a0bcffa889c 100644 --- a/admin/tool/admin_presets/tests/behat/download.feature +++ b/admin/tool/admin_presets/tests/behat/download.feature @@ -5,16 +5,16 @@ Feature: I can download a preset | name | | Custom preset | - @javascript Scenario: Custom preset settings can be downloaded Given I log in as "admin" And I navigate to "Site admin presets" in site administration When I open the action menu in "Custom preset" "table_row" - Then following "Download" "link" in the "Custom preset" "table_row" should download between "0" and "5000" bytes + Then following "Download" in the "Custom preset" "table_row" should download a "xml" file that: + | Contains | Custom preset | - @javascript Scenario: Core preset settings can be downloaded Given I log in as "admin" And I navigate to "Site admin presets" in site administration When I open the action menu in "Starter" "table_row" - Then following "Download" "link" in the "Starter" "table_row" should download between "0" and "5000" bytes + Then following "Download" in the "Starter" "table_row" should download a "xml" file that: + | Contains | Starter | diff --git a/admin/tool/dataprivacy/tests/behat/dataexport.feature b/admin/tool/dataprivacy/tests/behat/dataexport.feature index 0efed8fed2502..698db5e107b40 100644 --- a/admin/tool/dataprivacy/tests/behat/dataexport.feature +++ b/admin/tool/dataprivacy/tests/behat/dataexport.feature @@ -54,7 +54,8 @@ Feature: Data export from the privacy API And I reload the page And I should see "Download ready" in the "Victim User 1" "table_row" And I open the action menu in "Victim User 1" "table_row" - And following "Download" should download between "1" and "200000" bytes + And following "Download" should download a "zip" file that: + | Contains | index.html | And the following config values are set as admin: | privacyrequestexpiry | 1 | tool_dataprivacy | And I wait "1" seconds @@ -89,7 +90,8 @@ Feature: Data export from the privacy API And I reload the page And I should see "Download ready" in the "Export all of my personal data" "table_row" And I open the action menu in "Victim User 1" "table_row" - And following "Download" should download between "1" and "200000" bytes + And following "Download" should download a "zip" file that: + | Contains | index.html | And the following config values are set as admin: | privacyrequestexpiry | 1 | tool_dataprivacy | @@ -126,7 +128,8 @@ Feature: Data export from the privacy API And I reload the page And I should see "Download ready" in the "Victim User 1" "table_row" And I open the action menu in "Victim User 1" "table_row" - And following "Download" should download between "1" and "200000" bytes + And following "Download" should download a "zip" file that: + | Contains | index.html | And the following config values are set as admin: | privacyrequestexpiry | 1 | tool_dataprivacy | @@ -185,7 +188,8 @@ Feature: Data export from the privacy API And I reload the page And I should see "Download ready" in the "Victim User 1" "table_row" And I open the action menu in "Victim User 1" "table_row" - And following "Download" should download between "1" and "170000" bytes + Then following "Download" should download a "zip" file that: + | Contains | index.html | And the following config values are set as admin: | privacyrequestexpiry | 1 | tool_dataprivacy | And I wait "1" seconds @@ -229,7 +233,8 @@ Feature: Data export from the privacy API And I reload the page And I should see "Download ready" in the "Victim User 1" "table_row" And I open the action menu in "Victim User 1" "table_row" - And following "Download" should download between "1" and "180000" bytes + And following "Download" should download a "zip" file that: + | Contains | index.html | @javascript Scenario: Filter before export data for a user and download it in the view request action @@ -262,4 +267,5 @@ Feature: Data export from the privacy API And I reload the page And I should see "Download ready" in the "Victim User 1" "table_row" And I open the action menu in "Victim User 1" "table_row" - And following "Download" should download between "1" and "180000" bytes + And following "Download" should download a "zip" file that: + | Contains | index.html | diff --git a/analytics/tests/behat/manage_models.feature b/analytics/tests/behat/manage_models.feature index 13e721e327592..e068c42585c3d 100644 --- a/analytics/tests/behat/manage_models.feature +++ b/analytics/tests/behat/manage_models.feature @@ -147,7 +147,8 @@ Feature: Manage analytics models When I open the action menu in "Students at risk of not meeting the course completion conditions" "table_row" And I choose "Export" in the open action menu And I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" - And following "Export" should download between "100" and "500" bytes + And following "Download" should download a "zip" file that: + | Contains | model-config.json | Scenario: Check invalid site elements When I open the action menu in "Students at risk of not meeting the course completion conditions" "table_row" diff --git a/lib/tests/behat/behat_download.php b/lib/tests/behat/behat_download.php new file mode 100644 index 0000000000000..cae166df78521 --- /dev/null +++ b/lib/tests/behat/behat_download.php @@ -0,0 +1,224 @@ +. + +/** + * Steps definitions to verify a downloaded file. + * + * @package core + * @category test + * @copyright 2024 Simey Lameze + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use Behat\Gherkin\Node\TableNode; +use Behat\Mink\Exception\ExpectationException; + +require_once(__DIR__ . '/../../behat/behat_base.php'); + +/** + * Steps definitions to verify a downloaded file. + * + * @package core + * @category test + * @copyright 2024 Simey Lameze + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_download extends behat_base { + + /** + * Downloads the file from a link on the page and checks the size is in a given range. + * + * @Then /^following "(?P[^"]*)" in the "(?P(?:[^"]|\\")*)" "(?P[^"]*)" should download a "(?P[^"]*)" file that:$/ + * + * @param string $link the text of the link. + * @param string $elementcontainer the container element. + * @param string $textselector the text selector. + * @param string $format the expected file format. + * @param TableNode|null $table the table of assertions to check. + * @throws ExpectationException + */ + public function following_in_element_should_download_a_file_that(string $link, string $elementcontainer, + string $textselector, string $format, ?TableNode $table = null): void { + + $this->following_should_download_a_file_that($link, $format, $elementcontainer, $textselector, $table); + } + + /** + * Downloads the file from a link on the page and checks the size is in a given range. + * + * @Then /^following "(?P[^"]*)" should download a "(?P[^"]*)" file$/ + * @Then /^following "(?P[^"]*)" should download a "(?P[^"]*)" file that:$/ + * + * @param string $link the text of the link. + * @param string $format the expected file format. + * @param string|null $nodeelement the element to look in. + * @param string|null $nodeselectortype the type of selector to look in. + * @param TableNode|null $table the table of assertions to check. + * @throws ExpectationException + */ + public function following_should_download_a_file_that(string $link, string $format, ?string $nodeelement = null, + ?string $nodeselectortype = null, ?TableNode $table = null): void { + + $behatgeneralcontext = behat_context_helper::get('behat_general'); + $exception = new ExpectationException( + "Error while downloading data from {$link}", + $this->getSession(), + ); + + $format = strtolower($format); + $linkparams = empty($nodeelement) && empty($nodeselectortype) + ? [$link] + : [$link, $nodeselectortype, $nodeelement]; + + $filecontent = $this->spin( + fn($context, $link) => $behatgeneralcontext->download_file_from_link(...$linkparams), + $link, + behat_base::get_extended_timeout(), + $exception + ); + + // Images don't need to be checked for content. + if (in_array($format, ['png', 'jpg', 'gif'])) { + $this->assert_file_type_image($filecontent, $format); + return; + } + + $this->validate_mime_type($filecontent, $format); + $this->assert_file_content($filecontent, $format, $table); + } + private function assert_file_content(string $filecontent, string $format, ?TableNode $table): void { + if (!$rows = $table->getRows()) { + return; + } + + // Determine the assertion method to use based on the file format. + // If the format is 'gift' or 'aiken', use the text assertion method. + $assertmethod = ($format === 'gift' || $format === 'aiken') ? "assert_file_type_text" : "assert_file_type_{$format}"; + + foreach ($rows as $row) { + $assertion = strtolower(trim($row[0])); + match ($assertion) { + 'contains' => $this->$assertmethod($filecontent, $row[1]), + default => throw new ExpectationException( + "Invalid assertion: {$assertion}", + $this->getSession(), + ) + }; + } + } + + protected function validate_mime_type(string $filecontent, string $format): void { + + $finfo = new \finfo(FILEINFO_MIME_TYPE); + $mimetype = $finfo->buffer($filecontent); + + $validmimetypes = match ($format) { + 'zip' => ['application/zip', 'application/x-zip-compressed', 'multipart/x-zip'], + 'xml' => ['application/xml', 'text/xml'], + 'text' => ['text/plain'], + 'gift' => ['text/plain'], + 'aiken' => ['text/plain'], + 'png' => ['image/png'], + default => [$format], // If the format is not one of the above, assume it is the only valid MIME type + }; + + if (!in_array($mimetype, $validmimetypes)) { + throw new ExpectationException( + "The file downloaded should have been a {$format} file, but got {$mimetype} instead.", + $this->getSession(), + ); + } + } + + protected function assert_file_type_xml(string $filecontent, string $contains): void { + + // Load the XML content into a SimpleXMLElement object + $xml = new SimpleXMLElement($filecontent); + + // Use xpath to search for the string in the XML content + $result = $xml->xpath("//*[contains(text(), '$contains')]"); + + // If the result is empty, the string was not found in the XML content + if (empty($result)) { + throw new ExpectationException( + "The string '{$contains}' was not found in the XML content.", + $this->getSession(), + ); + } + } + + protected function assert_file_type_image(string $filecontent, string $format): void { + // First validate the MIME type + $this->validate_mime_type($filecontent, $format); + + // Then perform additional image-specific validations + $tempdir = make_request_directory(); + $filepath = $tempdir . '/downloaded.' . $format; + file_put_contents($filepath, $filecontent); + + if (!getimagesize($filepath)) { + throw new ExpectationException( + "The file downloaded does not appear to be a valid {$format} image.", + $this->getSession(), + ); + } + } + + protected function assert_file_type_zip(string $filecontent, string $expectedfile): void { + + // Save the file to disk. + $tempdir = make_request_directory(); + $filepath = $tempdir . '/downloaded.zip'; + file_put_contents($filepath, $filecontent); + + $zip = new ZipArchive(); + $res = $zip->open($filepath); + + if ($res !== true) { + throw new ExpectationException( + "Failed to open zip file.", + $this->getSession(), + ); + } + + // Check if the expected file exists in the zip archive. + if ($zip->locateName($expectedfile) === false) { + throw new ExpectationException( + "The file '{$expectedfile}' was not found in the zip archive.", + $this->getSession(), + ); + } + } + + protected function assert_file_type_text(string $filecontent, string $contains): void { + + // Check if the string is present in the file content. + if (!str_contains($filecontent, $contains)) { + throw new ExpectationException( + "The string '{$contains}' was not found in the file content.", + $this->getSession(), + ); + } + } + + protected function assert_file_type_gift(string $filecontent, string $contains): void { + $this->assert_file_type_text($filecontent, $contains); + } + + protected function assert_file_type_aiken(string $filecontent, string $contains): void { + $this->assert_file_type_text($filecontent, $contains); + } +} diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index b38bd60956df5..c354a5ac5f6a2 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1569,15 +1569,25 @@ public function following_should_not_exist_in_the_table($table, TableNode $data) * and {@link following_should_download_between_and_bytes()} * * @param string $link the text of the link. + * @param string $nodeselectortype the type of the node where the link is. + * @param string $nodeelement the element of the node where the link is. + * * @return string the content of the downloaded file. */ - public function download_file_from_link($link) { + public function download_file_from_link(string $link, string $nodeselectortype = '', string $nodeelement = '') { + // Find the link. - $linknode = $this->find_link($link); + if (!empty($nodeselectortype) && !empty($nodeelement)) { + $linknode = $this->get_node_in_container('link', $link, $nodeselectortype, $nodeelement); + } else { + $linknode = $this->find_link($link); + } + $this->ensure_node_is_visible($linknode); // Get the href and check it. $url = $linknode->getAttribute('href'); + if (!$url) { throw new ExpectationException('Download link does not have href attribute', $this->getSession()); @@ -1641,6 +1651,8 @@ function($context, $args) { * @param number $maxexpectedsize the maximum expected file size in bytes. */ public function following_should_download_between_and_bytes($link, $minexpectedsize, $maxexpectedsize) { + // TO BE DEPRECATED + // If the minimum is greater than the maximum then swap the values. if ((int)$minexpectedsize > (int)$maxexpectedsize) { list($minexpectedsize, $maxexpectedsize) = array($maxexpectedsize, $minexpectedsize); diff --git a/mod/data/tests/behat/data_presets.feature b/mod/data/tests/behat/data_presets.feature index ff04cc5dc191f..6f26f7cc75de3 100644 --- a/mod/data/tests/behat/data_presets.feature +++ b/mod/data/tests/behat/data_presets.feature @@ -300,10 +300,14 @@ Feature: Users can view and manage data presets # The teacher should be able to export any saved preset. And I open the action menu in "Saved preset by teacher1" "table_row" Then I should see "Export" - And following "Export" "link" in the "Saved preset by teacher1" "table_row" should download between "1" and "5000" bytes + # Failing. + Then following "Export" should download a "xml" file that: + | Contains | Saved preset by teacher1 | And I open the action menu in "Saved preset 1" "table_row" And I should see "Export" - And following "Export" "link" in the "Saved preset 1" "table_row" should download between "1" and "5000" bytes + # Failing. + And following "Export" should download a "xml" file that: + | Contains | Saved preset 1 | @javascript @_file_upload Scenario Outline: Admins and Teachers can load a preset from a file diff --git a/mod/folder/tests/behat/recent_activity.feature b/mod/folder/tests/behat/recent_activity.feature index 158461a8d89a6..39e3cbfb3a32d 100644 --- a/mod/folder/tests/behat/recent_activity.feature +++ b/mod/folder/tests/behat/recent_activity.feature @@ -36,5 +36,6 @@ Feature: Files added in folder activity are visible in the recent activity block And "//img[@alt='empty.txt']" "xpath_element" should exist And "//img[contains(@src, 'preview=tinyicon')]" "xpath_element" should exist # Confirm files are downloadable - And following "empty.txt" should download between "1" and "3000" bytes - And following "gd-logo.png" should download between "1" and "3000" bytes + Then following "empty.txt" should download a "text" file that: + | Contains | empty file for testing purposes | + And following "gd-logo.png" should download a "png" file diff --git a/mod/glossary/tests/behat/create_entry.feature b/mod/glossary/tests/behat/create_entry.feature index 1895bab567842..a1ab3f255790e 100644 --- a/mod/glossary/tests/behat/create_entry.feature +++ b/mod/glossary/tests/behat/create_entry.feature @@ -45,4 +45,5 @@ Feature: Create a glossary entry. When I am on the "Test glossary" "glossary activity" page logged in as teacher1 Then I should see "Entry 1" And I should see "musicians.xml" - And following "musicians.xml" should download between "1" and "3000" bytes + And following "musicians.xml" should download a "xml" file that: + | Contains | Paul McCartney | diff --git a/question/format/aiken/tests/behat/aiken_export.feature b/question/format/aiken/tests/behat/aiken_export.feature index 28f20d56f5b3d..2867018fe9dfe 100644 --- a/question/format/aiken/tests/behat/aiken_export.feature +++ b/question/format/aiken/tests/behat/aiken_export.feature @@ -26,7 +26,8 @@ Feature: Test exporting questions using Aiken format. When I am on the "Course 1" "core_question > course question export" page logged in as "teacher1" And I set the field "id_format_aiken" to "1" When I press "Export questions to file" - Then following "click here" should download between "68" and "70" bytes + Then following "click here" should download a "aiken" file that: + | Contains | Which is the oddest number? | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/format/gift/tests/behat/import_export.feature b/question/format/gift/tests/behat/import_export.feature index fc00ec7300fb7..a7176df80e979 100644 --- a/question/format/gift/tests/behat/import_export.feature +++ b/question/format/gift/tests/behat/import_export.feature @@ -31,7 +31,8 @@ Feature: Test importing questions from GIFT format. And I am on the "Course 1" "core_question > course question export" page And I set the field "id_format_gift" to "1" And I press "Export questions to file" - And following "click here" should download between "1500" and "1800" bytes + And following "click here" should download a "gift" file that: + | Contains | What's between orange and green in the spectrum? | @javascript @_file_upload Scenario: import a GIFT file which specifies the category diff --git a/question/format/xml/tests/behat/import_export.feature b/question/format/xml/tests/behat/import_export.feature index c09746929aebd..9e1782ff6bff3 100644 --- a/question/format/xml/tests/behat/import_export.feature +++ b/question/format/xml/tests/behat/import_export.feature @@ -34,7 +34,9 @@ Feature: Test importing questions from Moodle XML format. And I set the field "id_format_xml" to "1" And I set the field "Export category" to "TrueFalse" And I press "Export questions to file" - Then following "click here" should download between "57100" and "58150" bytes + Then following "click here" should download a "xml" file that: + | Contains | Moodle acronym (True) | + | Contains | Moodle acronym (False) | @javascript @_file_upload Scenario: import some multiple choice questions from Moodle XML format diff --git a/question/type/ddimageortext/tests/behat/export.feature b/question/type/ddimageortext/tests/behat/export.feature index 06d83e284ea30..3a6fd88509ffc 100644 --- a/question/type/ddimageortext/tests/behat/export.feature +++ b/question/type/ddimageortext/tests/behat/export.feature @@ -26,7 +26,8 @@ Feature: Test exporting drag and drop onto image questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "18600" and "19150" bytes + Then following "click here" should download a "xml" file that: + | Contains | Drag onto image | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/ddmarker/tests/behat/export.feature b/question/type/ddmarker/tests/behat/export.feature index edb928239ae14..780d7b7795202 100644 --- a/question/type/ddmarker/tests/behat/export.feature +++ b/question/type/ddmarker/tests/behat/export.feature @@ -26,7 +26,8 @@ Feature: Test exporting drag and drop markers questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "233700" and "233950" bytes + Then following "click here" should download a "xml" file that: + | Contains | Drag markers | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/ddwtos/tests/behat/export.feature b/question/type/ddwtos/tests/behat/export.feature index a74915b78e509..02ff8b4a2c801 100644 --- a/question/type/ddwtos/tests/behat/export.feature +++ b/question/type/ddwtos/tests/behat/export.feature @@ -26,7 +26,8 @@ Feature: Test exporting drag and drop into text questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - And following "click here" should download between "1550" and "1700" bytes + And following "click here" should download a "xml" file that: + | Contains | Drag to text | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/description/tests/behat/export.feature b/question/type/description/tests/behat/export.feature index 28cc5cda0947b..6d9069d53b04c 100644 --- a/question/type/description/tests/behat/export.feature +++ b/question/type/description/tests/behat/export.feature @@ -25,7 +25,8 @@ Feature: Test exporting Description questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "650" and "900" bytes + Then following "click here" should download a "xml" file that: + | Contains | description-001 | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/essay/tests/behat/export.feature b/question/type/essay/tests/behat/export.feature index e319fcdff4410..7c0105c66a5c6 100644 --- a/question/type/essay/tests/behat/export.feature +++ b/question/type/essay/tests/behat/export.feature @@ -27,7 +27,10 @@ Feature: Test exporting Essay questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "3000" and "3500" bytes + Then following "click here" should download a "xml" file that: + | Contains | essay-001 | + | Contains | essay-002 | + | Contains | essay-003 | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/gapselect/tests/behat/import_test.feature b/question/type/gapselect/tests/behat/import_test.feature index af9104c9b8414..fda12aeb5c579 100644 --- a/question/type/gapselect/tests/behat/import_test.feature +++ b/question/type/gapselect/tests/behat/import_test.feature @@ -32,7 +32,8 @@ Feature: Import and export select missing words questions And I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - And following "click here" should download between "1650" and "1800" bytes + And following "click here" should download a "xml" file that: + | Contains | Select missing words 001 | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/match/tests/behat/export.feature b/question/type/match/tests/behat/export.feature index 6d28231d648b5..014122ebdeccf 100644 --- a/question/type/match/tests/behat/export.feature +++ b/question/type/match/tests/behat/export.feature @@ -25,7 +25,8 @@ Feature: Test exporting Matching questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "1600" and "1750" bytes + Then following "click here" should download a "xml" file that: + | Contains | matching-001 | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/multichoice/tests/behat/export.feature b/question/type/multichoice/tests/behat/export.feature index 46fd6fec54235..1fd05ab8ec779 100644 --- a/question/type/multichoice/tests/behat/export.feature +++ b/question/type/multichoice/tests/behat/export.feature @@ -26,7 +26,9 @@ Feature: Test exporting Multiple choice questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "3900" and "4100" bytes + Then following "click here" should download a "xml" file that: + | Contains | Multi-choice-001 | + | Contains | Multi-choice-002 | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/numerical/tests/behat/export.feature b/question/type/numerical/tests/behat/export.feature index df9728ab09f25..b635f45782cfb 100644 --- a/question/type/numerical/tests/behat/export.feature +++ b/question/type/numerical/tests/behat/export.feature @@ -26,7 +26,9 @@ Feature: Test exporting Numerical questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "3650" and "3750" bytes + Then following "click here" should download a "xml" file that: + | Contains | Numerical-001 | + | Contains | Numerical-002 | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/ordering/tests/behat/export.feature b/question/type/ordering/tests/behat/export.feature index 5b218a159af25..6a3f598d7b367 100644 --- a/question/type/ordering/tests/behat/export.feature +++ b/question/type/ordering/tests/behat/export.feature @@ -25,7 +25,8 @@ Feature: Test exporting Ordering questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher1 And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "1700" and "2350" bytes + Then following "click here" should download a "xml" file that: + | Contains | Moodle | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/shortanswer/tests/behat/export.feature b/question/type/shortanswer/tests/behat/export.feature index 04f4a5fb26233..47e04faaac38b 100644 --- a/question/type/shortanswer/tests/behat/export.feature +++ b/question/type/shortanswer/tests/behat/export.feature @@ -25,7 +25,8 @@ Feature: Test exporting Short answer questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "1200" and "1450" bytes + Then following "click here" should download a "xml" file that: + | Contains | shortanswer-001 | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/question/type/truefalse/tests/behat/export.feature b/question/type/truefalse/tests/behat/export.feature index fb9f4005a2906..f65aebc892852 100644 --- a/question/type/truefalse/tests/behat/export.feature +++ b/question/type/truefalse/tests/behat/export.feature @@ -25,7 +25,8 @@ Feature: Test exporting True/False questions When I am on the "Course 1" "core_question > course question export" page logged in as teacher And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "1000" and "1200" bytes + Then following "click here" should download a "xml" file that: + | Contains | true-false-001 | # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout