mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'MDL-38410_master' of git://github.com/dmonllao/moodle
This commit is contained in:
commit
eb8a3eeaac
68
lib/behat/form_field/behat_form_checkbox.php
Normal file
68
lib/behat/form_field/behat_form_checkbox.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Single checkbox form element.
|
||||
*
|
||||
* @package core_form
|
||||
* @category test
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
||||
|
||||
require_once(__DIR__ . '/behat_form_field.php');
|
||||
|
||||
/**
|
||||
* Checkbox form field.
|
||||
*
|
||||
* @package core_form
|
||||
* @category test
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class behat_form_checkbox extends behat_form_field {
|
||||
|
||||
/**
|
||||
* Sets the value of a checkbox.
|
||||
*
|
||||
* Anything !empty() is considered checked.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function set_value($value) {
|
||||
|
||||
if (!empty($value) && !$this->field->isChecked()) {
|
||||
// Check it if it should be checked and it is not.
|
||||
$this->field->click();
|
||||
|
||||
} else if (empty($value) && $this->field->isChecked()) {
|
||||
// Uncheck if it is checked and shouldn't.
|
||||
$this->field->click();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the field is checked or not.
|
||||
*
|
||||
* @return bool True if it is checked and false if it's not.
|
||||
*/
|
||||
public function get_value() {
|
||||
return $this->field->isChecked();
|
||||
}
|
||||
}
|
45
lib/behat/form_field/behat_form_date_selector.php
Normal file
45
lib/behat/form_field/behat_form_date_selector.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Date form field class.
|
||||
*
|
||||
* @package core_form
|
||||
* @category test
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
||||
|
||||
require_once(__DIR__ . '/behat_form_select.php');
|
||||
|
||||
/**
|
||||
* Date form field.
|
||||
*
|
||||
* Simple extension of behat_form_select to allow date-type
|
||||
* select fields to be filled like select elements instead of
|
||||
* text elements.
|
||||
*
|
||||
* This class will be refactored in case we are interested in
|
||||
* creating more complex formats to fill date and date-time fields.
|
||||
*
|
||||
* @package core_form
|
||||
* @category test
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class behat_form_date_selector extends behat_form_select {}
|
45
lib/behat/form_field/behat_form_date_time_selector.php
Normal file
45
lib/behat/form_field/behat_form_date_time_selector.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Date time form field class.
|
||||
*
|
||||
* @package core_form
|
||||
* @category test
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
||||
|
||||
require_once(__DIR__ . '/behat_form_select.php');
|
||||
|
||||
/**
|
||||
* Date time form field.
|
||||
*
|
||||
* Simple extension of behat_form_select to allow datetime-type
|
||||
* select fields to be filled like select elements instead of
|
||||
* text elements.
|
||||
*
|
||||
* This class will be refactored in case we are interested in
|
||||
* creating more complex formats to fill date and date-time fields.
|
||||
*
|
||||
* @package core_form
|
||||
* @category test
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class behat_form_date_time_selector extends behat_form_select {}
|
@ -179,6 +179,22 @@ class behat_forms extends behat_base {
|
||||
$selectnode->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the specified id|name|label from the specified radio button.
|
||||
*
|
||||
* @When /^I select "(?P<radio_button_string>(?:[^"]|\\")*)" radio button$/
|
||||
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||
* @param string $radio The radio button id, name or label value
|
||||
*/
|
||||
public function select_radio($radio) {
|
||||
|
||||
$radionode = $this->find_radio($radio);
|
||||
$radionode->check();
|
||||
|
||||
// Adding a click as Selenium requires it to fire some JS events.
|
||||
$radionode->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks checkbox with specified id|name|label|value.
|
||||
*
|
||||
|
33
mod/choice/tests/behat/add_choice.feature
Normal file
33
mod/choice/tests/behat/add_choice.feature
Normal file
@ -0,0 +1,33 @@
|
||||
@mod_choice
|
||||
Feature: Add choice activity
|
||||
In order to ask questions as a choice of multiple responses
|
||||
As a moodle teacher
|
||||
I need to add choice activities to courses
|
||||
|
||||
@javascript
|
||||
Scenario: Add a choice activity and complete the activity as a student
|
||||
Given the following "users" exists:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@asd.com |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
And the following "courses" exists:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exists:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I turn editing mode on
|
||||
And I add a "choice" to section "1" and I fill the form with:
|
||||
| Choice name | Choice name |
|
||||
| Description | Choice Description |
|
||||
| option[0] | Option 1 |
|
||||
| option[1] | Option 2 |
|
||||
And I log out
|
||||
When I log in as "student1"
|
||||
And I follow "Course 1"
|
||||
And I choose "Option 1" from "Choice name" choice activity
|
||||
Then I should see "Your selection: Option 1"
|
||||
And I should see "Your choice has been saved"
|
59
mod/choice/tests/behat/behat_mod_choice.php
Normal file
59
mod/choice/tests/behat/behat_mod_choice.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Steps definitions for choice activity.
|
||||
*
|
||||
* @package mod_choice
|
||||
* @category test
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
||||
|
||||
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
|
||||
|
||||
use Behat\Behat\Context\Step\Given as Given;
|
||||
|
||||
/**
|
||||
* Choice activity definitions.
|
||||
*
|
||||
* @package mod_choice
|
||||
* @category test
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class behat_mod_choice extends behat_base {
|
||||
|
||||
/**
|
||||
* Chooses the specified option from the choice activity named as specified. You should be located in the activity's course page.
|
||||
*
|
||||
* @Given /^I choose "(?P<option_string>(?:[^"]|\\")*)" from "(?P<choice_activity_string>(?:[^"]|\\")*)" choice activity$/
|
||||
* @param string $option
|
||||
* @param string $choiceactivity
|
||||
*/
|
||||
public function I_choose_option_from_activity($option, $choiceactivity) {
|
||||
|
||||
// Escaping again the strings as backslashes have been removed by the automatic transformation.
|
||||
return array(
|
||||
new Given('I follow "' . $this->escape($choiceactivity) . '"'),
|
||||
new Given('I select "' . $this->escape($option) . '" radio button'),
|
||||
new Given('I press "Save my choice"')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user