diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php new file mode 100644 index 00000000000..3f5b4ba57f2 --- /dev/null +++ b/course/tests/behat/behat_course.php @@ -0,0 +1,103 @@ +. + +/** + * Behat course-related steps definitions. + * + * @package core_course + * @category test + * @copyright 2012 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, + Behat\Gherkin\Node\TableNode as TableNode; + +/** + * Course-related steps definitions. + * + * @package core_course + * @category test + * @copyright 2012 David Monllaó + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_course extends behat_base { + + /** + * Turns editing mode on. + * @Given /^I turn editing mode on$/ + */ + public function i_turn_editing_mode_on() { + return new Given('I press "Turn editing on"'); + } + + /** + * Turns editing mode off. + * @Given /^I turn editing mode off$/ + */ + public function i_turn_editing_mode_off() { + return new Given('I press "Turn editing off"'); + } + + /** + * Adds the selected activity/resource filling the form data with the specified field/value pairs. + * + * @When /^I add a "(?P(?:[^"]|\\")*)" to section "(?P\d+)" and I fill the form with:$/ + * @param string $activity The activity name + * @param string $section The section number + * @param TableNode $data The activity field/value data + */ + public function i_add_to_section_and_i_fill_the_form_with($activity, $section, TableNode $data) { + + $activity = $this->fixStepArgument($activity); + $section = $this->fixStepArgument($section); + + // The 'I wait until the page is ready' is just in case. + return array( + new Given('I add a "'.$activity.'" to section "'.$section.'"'), + new Given('I fill the moodle form with:', $data), + new Given('I press "Save and return to course"') + ); + } + + /** + * Opens the activity chooser and opens the activity/resource form page. + * + * @Given /^I add a "(?P(?:[^"]|\\")*)" to section "(?P\d+)"$/ + * @param string $activity + * @param string $section + */ + public function i_add_to_section($activity, $section) { + + $activity = $this->fixStepArgument($activity); + $section = $this->fixStepArgument($section); + + // Clicks add activity or resource section link. + $sectionxpath = "//*[@id='section-" . $section . "']/*/*/*/div[@class='section-modchooser']/*/*"; + $section = $this->getSession()->getPage()->find('xpath', $sectionxpath); + $section->click(); + + // Clicks the selected activity if it exists. + $activityxpath = ".//label[contains(.,'" . $activity . "')]/input"; + $activity = $this->getSession()->getPage()->find('xpath', $activityxpath); + $activity->doubleClick(); + } + +}