From 3dc10958bc3be309758fecae2e8fc22cca56ceab Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Wed, 5 Jul 2023 19:37:36 +0800 Subject: [PATCH 1/2] MDL-63399 behat: new steps to verify downloads Co-authored-by: Tim Hunt --- lib/tests/behat/behat_download.php | 211 +++++++++++++++++++++++++++++ lib/tests/behat/behat_general.php | 24 +++- 2 files changed, 230 insertions(+), 5 deletions(-) create mode 100644 lib/tests/behat/behat_download.php diff --git a/lib/tests/behat/behat_download.php b/lib/tests/behat/behat_download.php new file mode 100644 index 00000000000..1ae4f5aa9fd --- /dev/null +++ b/lib/tests/behat/behat_download.php @@ -0,0 +1,211 @@ +. + +/** + * 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 verify the type and content. + * + * @Then following :link_text should download a file that: + * + * @param string $linktext the text of the link. + * @param TableNode $table the table of assertions to use the check the file contents. + * @throws ExpectationException if the file cannot be downloaded, or if the download does not pass all the checks. + */ + public function following_should_download_a_file_that(string $linktext, TableNode $table): void { + $this->following_in_element_should_download_a_file_that($linktext, '', '', $table); + } + + /** + * Downloads the file from a link on the page and verify the type and content. + * + * @Then following :link_text in the :element_container_string :text_selector_string should download a file that: + * + * @param string $linktext the text of the link. + * @param string $containerlocator the container element. + * @param string $containertype the container selector type. + * @param TableNode $table the table of assertions to use the check the file contents. + * @throws ExpectationException if the file cannot be downloaded, or if the download does not pass all the checks. + */ + public function following_in_element_should_download_a_file_that(string $linktext, string $containerlocator, + string $containertype, TableNode $table): void { + + $filecontent = $this->download_file($linktext, $containerlocator, $containertype); + $this->verify_file_content($filecontent, $table); + } + + /** + * Download a file from the given link. + * + * @param string $linktext the text of the link. + * @param string $containerlocator the container element. + * @param string $containertype the container selector type. + * @return string the file contents. + * @throws ExpectationException if the download fails. + */ + protected function download_file(string $linktext, string $containerlocator, string $containertype): string { + return behat_context_helper::get('behat_general')->download_file_from_link($linktext, $containerlocator, $containertype); + } + + /** + * Checks the content of the downloaded file. + * + * @param string $filecontent the content of the file. + * @param TableNode $table the table of assertions to check. + * @throws ExpectationException if the file content does not pass all the checks. + */ + private function verify_file_content(string $filecontent, TableNode $table): void { + foreach ($table->getRows() as $row) { + switch (strtolower(trim($row[0]))) { + case 'contains text': + $this->verify_file_contains_text($filecontent, $row[1]); + break; + case 'contains text in xml element': + $this->verify_xml_element_contains($filecontent, $row[1]); + break; + case 'has mimetype': + $this->verify_file_mimetype($filecontent, $row[1]); + break; + case 'contains file in zip': + $this->verify_zip_file_content($filecontent, $row[1]); + break; + default: + throw new ExpectationException( + 'Invalid type of file assertion: ' . $row[0], $this->getSession()); + } + } + } + + /** + * Validates the downloaded file appears to be of the mimetype. + * + * @param string $filecontent the content of the file. + * @param string $expectedmimetype the expected file mimetype e.g. 'application/xml'. + * @throws ExpectationException if the file does not appear to be of the expected type. + */ + protected function verify_file_mimetype(string $filecontent, string $expectedmimetype): void { + + $finfo = new finfo(FILEINFO_MIME_TYPE); + $actualmimetype = $finfo->buffer($filecontent); + + if ($actualmimetype !== $expectedmimetype) { + throw new ExpectationException( + "The file downloaded should have been a $expectedmimetype file, " . + "but got $actualmimetype instead.", + $this->getSession(), + ); + } + } + + /** + * Asserts that the given string is present in the file content. + * + * @param string $filecontent the content of the file. + * @param string $expectedcontent the string to search for. + * @throws ExpectationException if verification fails. + */ + protected function verify_file_contains_text(string $filecontent, string $expectedcontent): void { + if (!str_contains($filecontent, $expectedcontent)) { + throw new ExpectationException( + "The string '$expectedcontent' was not found in the file content.", + $this->getSession(), + ); + } + } + + /** + * Asserts that the given XML file is valid and contains the expected string. + * + * @param string $filecontent the content of the file. + * @param string $expectedcontent the string to search for. + * @throws ExpectationException + */ + protected function verify_xml_element_contains(string $filecontent, string $expectedcontent): void { + $xml = new SimpleXMLElement($filecontent); + $result = $xml->xpath("//*[contains(text(), '$expectedcontent')]"); + + if (empty($result)) { + throw new ExpectationException( + "The string '$expectedcontent' was not found in the content of any element in this XML file.", + $this->getSession(), + ); + } + } + + /** + * Save the downloaded file to tempdir and return the path. + * + * @param string $filecontent the content of the file. + * @param string $fileextension the expected file type, given as a file extension, e.g. 'txt', 'xml'. + * @return string path where the file was saved temporarily. + */ + protected function save_to_temp_file(string $filecontent, string $fileextension): string { + // Then perform additional image-specific validations. + $tempdir = make_request_directory(); + $filepath = $tempdir . '/downloaded.' . $fileextension; + file_put_contents($filepath, $filecontent); + return $filepath; + } + + /** + * Asserts that the given zip archive contains the expected file(s). + * + * @param string $filecontent the content of the file. + * @param string $expectedfile the name of the file to search for. + * @throws ExpectationException if the zip file does not contain the expected files. + */ + protected function verify_zip_file_content(string $filecontent, string $expectedfile): void { + + $zip = new ZipArchive(); + $res = $zip->open($this->save_to_temp_file($filecontent, 'zip')); + + if ($res !== true) { + throw new ExpectationException( + "Failed to open zip file.", + $this->getSession(), + ); + } + + if ($zip->locateName($expectedfile) === false) { + throw new ExpectationException( + "The file '$expectedfile' was not found in the downloaded zip archive.", + $this->getSession(), + ); + } + } +} diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index d4fedca51ec..6c6770bc5dc 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1644,15 +1644,24 @@ EOF; /** * Given the text of a link, download the linked file and return the contents. * - * This is a helper method used by {@link following_should_download_bytes()} - * and {@link following_should_download_between_and_bytes()} + * A helper method used by the steps in {@see behat_download}, and the legacy + * {@see following_should_download_bytes()} and {@see following_should_download_between_and_bytes()}. * * @param string $link the text of the link. + * @param string $containerlocator optional container element locator. + * @param string $containertype optional container element selector type. + * * @return string the content of the downloaded file. */ - public function download_file_from_link($link) { + public function download_file_from_link(string $link, string $containerlocator = '', string $containertype = ''): string { + // Find the link. - $linknode = $this->find_link($link); + if ($containerlocator !== '' && $containertype !== '') { + $linknode = $this->get_node_in_container('link', $link, $containertype, $containerlocator); + } else { + $linknode = $this->find_link($link); + } + $this->ensure_node_is_visible($linknode); // Get the href and check it. @@ -1674,6 +1683,8 @@ EOF; /** * Downloads the file from a link on the page and checks the size. * + * Not recommended any more. The steps in {@see behat_download} are much better! + * * Only works if the link has an href attribute. Javascript downloads are * not supported. Currently, the href must be an absolute URL. * @@ -1707,6 +1718,8 @@ EOF; /** * Downloads the file from a link on the page and checks the size is in a given range. * + * Not recommended any more. The steps in {@see behat_download} are much better! + * * Only works if the link has an href attribute. Javascript downloads are * not supported. Currently, the href must be an absolute URL. * @@ -1714,10 +1727,11 @@ EOF; * be between "5" and "10" bytes, and between "10" and "20" bytes. * * @Then /^following "(?P[^"]*)" should download between "(?P\d+)" and "(?P\d+)" bytes$/ - * @throws ExpectationException + * * @param string $link the text of the link. * @param number $minexpectedsize the minimum expected file size in bytes. * @param number $maxexpectedsize the maximum expected file size in bytes. + * @throws ExpectationException */ public function following_should_download_between_and_bytes($link, $minexpectedsize, $maxexpectedsize) { // If the minimum is greater than the maximum then swap the values. From f62ef26f37e1686790d23c347f0a73928e5bf41f Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 4 Jul 2024 13:43:27 +0100 Subject: [PATCH 2/2] MDL-63399 behat: update existing tests to use the better download steps Co-authored-by: Tim Hunt --- .../admin_presets/tests/behat/download.feature | 10 ++++++---- .../dataprivacy/tests/behat/dataexport.feature | 18 ++++++++++++------ analytics/tests/behat/manage_models.feature | 3 ++- mod/data/tests/behat/data_presets.feature | 7 ++++--- mod/folder/tests/behat/recent_activity.feature | 7 +++++-- mod/glossary/tests/behat/create_entry.feature | 5 +++-- .../aiken/tests/behat/aiken_export.feature | 4 +++- .../gift/tests/behat/import_export.feature | 4 +++- .../xml/tests/behat/import_export.feature | 5 ++++- .../ddimageortext/tests/behat/export.feature | 4 +++- .../type/ddmarker/tests/behat/export.feature | 4 +++- .../type/ddwtos/tests/behat/export.feature | 4 +++- .../description/tests/behat/export.feature | 4 +++- question/type/essay/tests/behat/export.feature | 6 +++++- .../gapselect/tests/behat/import_test.feature | 4 +++- question/type/match/tests/behat/export.feature | 4 +++- .../multichoice/tests/behat/export.feature | 5 ++++- .../type/numerical/tests/behat/export.feature | 5 ++++- .../type/ordering/tests/behat/export.feature | 6 ++++-- .../shortanswer/tests/behat/export.feature | 4 +++- .../type/truefalse/tests/behat/export.feature | 4 +++- 21 files changed, 83 insertions(+), 34 deletions(-) diff --git a/admin/tool/admin_presets/tests/behat/download.feature b/admin/tool/admin_presets/tests/behat/download.feature index 2866028325f..f2ba8b714aa 100644 --- a/admin/tool/admin_presets/tests/behat/download.feature +++ b/admin/tool/admin_presets/tests/behat/download.feature @@ -5,16 +5,18 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | Starter | diff --git a/admin/tool/dataprivacy/tests/behat/dataexport.feature b/admin/tool/dataprivacy/tests/behat/dataexport.feature index 662ccae191b..fb068e8a1f2 100644 --- a/admin/tool/dataprivacy/tests/behat/dataexport.feature +++ b/admin/tool/dataprivacy/tests/behat/dataexport.feature @@ -55,7 +55,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 file that: + | Contains file in zip | index.html | And the following config values are set as admin: | privacyrequestexpiry | 1 | tool_dataprivacy | And I wait "1" seconds @@ -90,7 +91,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 file that: + | Contains file in zip | index.html | And the following config values are set as admin: | privacyrequestexpiry | 1 | tool_dataprivacy | @@ -128,7 +130,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 file that: + | Contains file in zip | index.html | And the following config values are set as admin: | privacyrequestexpiry | 1 | tool_dataprivacy | @@ -187,7 +190,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 "172000" bytes + And following "Download" should download a file that: + | Contains file in zip | index.html | And the following config values are set as admin: | privacyrequestexpiry | 1 | tool_dataprivacy | And I wait "1" seconds @@ -231,7 +235,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 file that: + | Contains file in zip | index.html | @javascript Scenario: Filter before export data for a user and download it in the view request action @@ -264,4 +269,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 file that: + | Contains file in zip | index.html | diff --git a/analytics/tests/behat/manage_models.feature b/analytics/tests/behat/manage_models.feature index e01619227ee..c92ba3c75a6 100644 --- a/analytics/tests/behat/manage_models.feature +++ b/analytics/tests/behat/manage_models.feature @@ -148,7 +148,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 "Export" should download a file that: + | Contains file in zip | 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/mod/data/tests/behat/data_presets.feature b/mod/data/tests/behat/data_presets.feature index ff04cc5dc19..4d6de9ae3b6 100644 --- a/mod/data/tests/behat/data_presets.feature +++ b/mod/data/tests/behat/data_presets.feature @@ -291,7 +291,6 @@ Feature: Users can view and manage data presets And I should see "This is a short text" Then "Use this preset" "button" should exist - @javascript Scenario: Teachers can export any saved preset Given I am on the "Mountain landscapes" "data activity" page logged in as teacher1 When I follow "Presets" @@ -300,10 +299,12 @@ 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 + And following "Export" in the "Saved preset by teacher1" "table_row" should download a file that: + | Contains file in zip | preset.xml | 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 + And following "Export" in the "Saved preset 1" "table_row" should download a file that: + | Contains file in zip | preset.xml | @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 158461a8d89..fd787479657 100644 --- a/mod/folder/tests/behat/recent_activity.feature +++ b/mod/folder/tests/behat/recent_activity.feature @@ -36,5 +36,8 @@ 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 + And following "empty.txt" should download a file that: + | Has mimetype | text/plain | + | Contains text | empty file for testing purposes | + And following "gd-logo.png" should download a file that: + | Has mimetype | image/png | diff --git a/mod/glossary/tests/behat/create_entry.feature b/mod/glossary/tests/behat/create_entry.feature index 1895bab5678..f7e8935d9e4 100644 --- a/mod/glossary/tests/behat/create_entry.feature +++ b/mod/glossary/tests/behat/create_entry.feature @@ -44,5 +44,6 @@ Feature: Create a glossary entry. # Confirm you can download attachment from student's entry as teacher 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | Paul McCartney | diff --git a/question/format/aiken/tests/behat/aiken_export.feature b/question/format/aiken/tests/behat/aiken_export.feature index 28f20d56f5b..7c3380ee986 100644 --- a/question/format/aiken/tests/behat/aiken_export.feature +++ b/question/format/aiken/tests/behat/aiken_export.feature @@ -26,7 +26,9 @@ 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 file that: + | Has mimetype | text/plain | + | Contains text | 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 fc00ec7300f..c39a92ce65a 100644 --- a/question/format/gift/tests/behat/import_export.feature +++ b/question/format/gift/tests/behat/import_export.feature @@ -31,7 +31,9 @@ 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 file that: + | Has mimetype | text/plain | + | Contains text | 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 c09746929ae..9e68c3684d8 100644 --- a/question/format/xml/tests/behat/import_export.feature +++ b/question/format/xml/tests/behat/import_export.feature @@ -34,7 +34,10 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | Moodle acronym (True) | + | Contains text in xml element | 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 06d83e284ea..b5aed9589bc 100644 --- a/question/type/ddimageortext/tests/behat/export.feature +++ b/question/type/ddimageortext/tests/behat/export.feature @@ -26,7 +26,9 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | 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 edb928239ae..29e4db315bf 100644 --- a/question/type/ddmarker/tests/behat/export.feature +++ b/question/type/ddmarker/tests/behat/export.feature @@ -26,7 +26,9 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | 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 a74915b78e5..937de366fd7 100644 --- a/question/type/ddwtos/tests/behat/export.feature +++ b/question/type/ddwtos/tests/behat/export.feature @@ -26,7 +26,9 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | 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 28cc5cda094..403ade48dd4 100644 --- a/question/type/description/tests/behat/export.feature +++ b/question/type/description/tests/behat/export.feature @@ -25,7 +25,9 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | 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 e319fcdff44..198e7d6a21a 100644 --- a/question/type/essay/tests/behat/export.feature +++ b/question/type/essay/tests/behat/export.feature @@ -27,7 +27,11 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | essay-001 | + | Contains text in xml element | essay-002 | + | Contains text in xml element | 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 af9104c9b84..572ffc0e216 100644 --- a/question/type/gapselect/tests/behat/import_test.feature +++ b/question/type/gapselect/tests/behat/import_test.feature @@ -32,7 +32,9 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | 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 6d28231d648..31cb7d4d3a7 100644 --- a/question/type/match/tests/behat/export.feature +++ b/question/type/match/tests/behat/export.feature @@ -25,7 +25,9 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | 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 46fd6fec542..a9aee8ba554 100644 --- a/question/type/multichoice/tests/behat/export.feature +++ b/question/type/multichoice/tests/behat/export.feature @@ -26,7 +26,10 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | Multi-choice-001 | + | Contains text in xml element | 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 df9728ab09f..f4d797da90b 100644 --- a/question/type/numerical/tests/behat/export.feature +++ b/question/type/numerical/tests/behat/export.feature @@ -26,7 +26,10 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | Numerical-001 | + | Contains text in xml element | 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 5b218a159af..e054e20b6d9 100644 --- a/question/type/ordering/tests/behat/export.feature +++ b/question/type/ordering/tests/behat/export.feature @@ -21,11 +21,13 @@ Feature: Test exporting Ordering questions | questioncategory | qtype | name | template | | Test questions | ordering | Moodle | moodle | - Scenario: Export a Matching question + Scenario: Export a ordering question 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | 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 04f4a5fb262..62fe751e1b0 100644 --- a/question/type/shortanswer/tests/behat/export.feature +++ b/question/type/shortanswer/tests/behat/export.feature @@ -25,7 +25,9 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | 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 fb9f4005a29..67ebd816dc8 100644 --- a/question/type/truefalse/tests/behat/export.feature +++ b/question/type/truefalse/tests/behat/export.feature @@ -25,7 +25,9 @@ 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 file that: + | Has mimetype | text/xml | + | Contains text in xml element | 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