Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250711) (9addea9f0ac)
behat_download Class Reference

Steps definitions to verify a downloaded file. More...

Inheritance diagram for behat_download:
behat_base behat_session_interface

Public Member Functions

 following_in_element_should_download_a_file_that (string $linktext, string $containerlocator, string $containertype, TableNode $table)
 Downloads the file from a link on the page and verify the type and content.
 
 following_should_download_a_file_that (string $linktext, TableNode $table)
 Downloads the file from a link on the page and verify the type and content.
 
 getSession ($name=null)
 Returns the Mink session.
 

Public Attributes

const PAGE_READY_JS
 The JS code to check that the page is ready.
 

Protected Member Functions

 download_file (string $linktext, string $containerlocator, string $containertype)
 Download a file from the given link.
 
 save_to_temp_file (string $filecontent, string $fileextension)
 Save the downloaded file to tempdir and return the path.
 
 verify_file_contains_text (string $filecontent, string $expectedcontent)
 Asserts that the given string is present in the file content.
 
 verify_file_mimetype (string $filecontent, string $expectedmimetype)
 Validates the downloaded file appears to be of the mimetype.
 
 verify_xml_element_contains (string $filecontent, string $expectedcontent)
 Asserts that the given XML file is valid and contains the expected string.
 
 verify_zip_file_content (string $filecontent, string $expectedfile)
 Asserts that the given zip archive contains the expected file(s).
 

Detailed Description

Steps definitions to verify a downloaded file.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ download_file()

behat_download::download_file ( string $linktext,
string $containerlocator,
string $containertype )
protected

Download a file from the given link.

Parameters
string$linktextthe text of the link.
string$containerlocatorthe container element.
string$containertypethe container selector type.
Return values
stringthe file contents.
Exceptions
ExpectationExceptionif the download fails.

◆ following_in_element_should_download_a_file_that()

behat_download::following_in_element_should_download_a_file_that ( string $linktext,
string $containerlocator,
string $containertype,
TableNode $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:

Parameters
string$linktextthe text of the link.
string$containerlocatorthe container element.
string$containertypethe container selector type.
TableNode$tablethe table of assertions to use the check the file contents.
Exceptions
ExpectationExceptionif the file cannot be downloaded, or if the download does not pass all the checks.

◆ following_should_download_a_file_that()

behat_download::following_should_download_a_file_that ( string $linktext,
TableNode $table )

Downloads the file from a link on the page and verify the type and content.

@Then following :link_text should download a file that:

Parameters
string$linktextthe text of the link.
TableNode$tablethe table of assertions to use the check the file contents.
Exceptions
ExpectationExceptionif the file cannot be downloaded, or if the download does not pass all the checks.

◆ getSession()

behat_session_interface::getSession ( $name = null)
inherited

Returns the Mink session.

Parameters
string | null$namename of the session OR active session will be used
Return values
Behat::Mink::Session

Implemented in behat_form_field.

◆ save_to_temp_file()

behat_download::save_to_temp_file ( string $filecontent,
string $fileextension )
protected

Save the downloaded file to tempdir and return the path.

Parameters
string$filecontentthe content of the file.
string$fileextensionthe expected file type, given as a file extension, e.g. 'txt', 'xml'.
Return values
stringpath where the file was saved temporarily.

◆ verify_file_contains_text()

behat_download::verify_file_contains_text ( string $filecontent,
string $expectedcontent )
protected

Asserts that the given string is present in the file content.

Parameters
string$filecontentthe content of the file.
string$expectedcontentthe string to search for.
Exceptions
ExpectationExceptionif verification fails.

◆ verify_file_mimetype()

behat_download::verify_file_mimetype ( string $filecontent,
string $expectedmimetype )
protected

Validates the downloaded file appears to be of the mimetype.

Parameters
string$filecontentthe content of the file.
string$expectedmimetypethe expected file mimetype e.g. 'application/xml'.
Exceptions
ExpectationExceptionif the file does not appear to be of the expected type.

◆ verify_xml_element_contains()

behat_download::verify_xml_element_contains ( string $filecontent,
string $expectedcontent )
protected

Asserts that the given XML file is valid and contains the expected string.

Parameters
string$filecontentthe content of the file.
string$expectedcontentthe string to search for.
Exceptions
ExpectationException

◆ verify_zip_file_content()

behat_download::verify_zip_file_content ( string $filecontent,
string $expectedfile )
protected

Asserts that the given zip archive contains the expected file(s).

Parameters
string$filecontentthe content of the file.
string$expectedfilethe name of the file to search for.
Exceptions
ExpectationExceptionif the zip file does not contain the expected files.

Member Data Documentation

◆ PAGE_READY_JS

const behat_session_interface::PAGE_READY_JS
inherited
Initial value:
= "document.readyState === 'complete' && " .
"(typeof M !== 'object' || typeof M.util !== 'object' || " .
"typeof M.util.pending_js === 'undefined' || M.util.pending_js.length === 0)"

The JS code to check that the page is ready.

The document must be complete and either M.util.pending_js must be empty, or it must not be defined at all.


The documentation for this class was generated from the following file: