diff --git a/lib/form/tests/behat/filetypes.feature b/lib/form/tests/behat/filetypes.feature new file mode 100644 index 00000000000..b65ca66bff8 --- /dev/null +++ b/lib/form/tests/behat/filetypes.feature @@ -0,0 +1,27 @@ +@core_form +Feature: There is a form element allowing to select filetypes + In order to test the filetypes field + As an admin + I need a test form that makes use of the filetypes field + + Background: + Given the following "courses" exist: + | fullname | shortname | format | + | Course 1 | C1 | topics | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | label | L1 | FixtureLink | C1 | label1 | + And I log in as "admin" + And I am on "Course 1" course homepage + And I follow "FixtureLink" + + Scenario: File types can be provided via direct input with JavaScript disabled + Given I set the field "Choose from all file types" to ".png .gif .jpg" + When I press "Save changes" + Then the field "Choose from all file types" matches value ".png .gif .jpg" + + @javascript + Scenario: File types can be provided via direct input with JavaScript enabled + Given I set the field "Choose from all file types" to ".png .gif .jpg" + When I press "Save changes" + Then the field "Choose from all file types" matches value ".png .gif .jpg" \ No newline at end of file diff --git a/lib/form/tests/fixtures/filetypes.php b/lib/form/tests/fixtures/filetypes.php new file mode 100644 index 00000000000..331fbfa7fe8 --- /dev/null +++ b/lib/form/tests/fixtures/filetypes.php @@ -0,0 +1,74 @@ +. + +/** + * Fixture script for Behat test for testing the filetypes element. + * + * @package core_form + * @category test + * @copyright 2017 David Mudrák + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +// No login check is expected here as this is for Behat tests only. +// @codingStandardsIgnoreLine +require(__DIR__.'/../../../../config.php'); +require_once($CFG->libdir.'/formslib.php'); + +// Behat test fixture only. +defined('BEHAT_SITE_RUNNING') || die('Only available on Behat test server'); + +/** + * Defines a test form to be used in automatic tests. + * + * @copyright 2017 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class test_form extends moodleform { + + /** + * Defines the form fields. + */ + public function definition() { + $mform = $this->_form; + + $mform->addElement('filetypes', 'filetypes0', 'Choose from all file types'); + $mform->setDefault('filetypes0', '.pdf'); + + $mform->addElement('filetypes', 'filetypes1', 'Choose from a limited set', + ['onlytypes' => array('.pdf', 'web_image', 'image')]); + + $mform->addElement('filetypes', 'filetypes2', 'Choose without "all"', + ['allowall' => false]); + + $mform->addElement('filetypes', 'filetypes3', 'Unknown file types are allowed here', + ['allowunknown' => true]); + + $this->add_action_buttons(false); + } +} + +$PAGE->set_context(context_system::instance()); +$PAGE->set_url('/lib/form/tests/fixtures/filetypes.php'); +$PAGE->set_title('Filetypes element test page'); + +$form = new test_form($PAGE->url); +$formdata = $form->get_data(); + +echo $OUTPUT->header(); +echo $OUTPUT->heading($PAGE->title); +$form->display(); +echo $OUTPUT->footer(); \ No newline at end of file