MDL-57325 behat: Fixed backup/restore steps to use proper api

This commit is contained in:
Rajesh Taneja
2016-12-09 09:30:18 +08:00
parent 5ef81f2b0b
commit 2700a9aff1
3 changed files with 57 additions and 154 deletions
+56 -104
View File
@@ -43,19 +43,6 @@ use Behat\Gherkin\Node\TableNode as TableNode,
*/
class behat_backup extends behat_base {
/**
* Follow a link like 'Backup' or 'Import', where the link name comes from
* a language string, in the settings nav block of a course.
* @param string $langstring the lang string to look for. E.g. 'backup' or 'import'.
* @param string $component (optional) second argument to {@link get_string}.
*/
protected function navigate_to_course_settings_link($langstring, $component = '') {
$behatnavigation = new behat_navigation();
$behatnavigation->setMink($this->getMink());
$behatnavigation->i_navigate_to_node_in(get_string($langstring, $component),
get_string('courseadministration'));
}
/**
* Backups the specified course using the provided options. If you are interested in restoring this backup would be
* useful to provide a 'Filename' option.
@@ -70,33 +57,31 @@ class behat_backup extends behat_base {
// Go to homepage.
$this->getSession()->visit($this->locate_path('/?redirect=0'));
$this->execute("behat_general::wait_until_the_page_is_ready");
// Click the course link.
$this->find_link($backupcourse)->click();
$this->execute("behat_general::click_link", $backupcourse);
// Click the backup link.
$this->navigate_to_course_settings_link('backup');
$this->wait();
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration", get_string('backup'));
// Initial settings.
$this->fill_backup_restore_form($this->get_step_options($options, "Initial"));
$this->find_button(get_string('backupstage1action', 'backup'))->press();
$this->wait();
$this->execute("behat_forms::press_button", get_string('backupstage1action', 'backup'));
// Schema settings.
$this->fill_backup_restore_form($this->get_step_options($options, "Schema"));
$this->find_button(get_string('backupstage2action', 'backup'))->press();
$this->wait();
$this->execute("behat_forms::press_button", get_string('backupstage2action', 'backup'));
// Confirmation and review, backup filename can also be specified.
$this->fill_backup_restore_form($this->get_step_options($options, "Confirmation"));
$this->find_button(get_string('backupstage4action', 'backup'))->press();
$this->execute("behat_forms::press_button", get_string('backupstage4action', 'backup'));
// Waiting for it to finish.
$this->wait(self::EXTENDED_TIMEOUT);
$this->execute("behat_general::wait_until_the_page_is_ready");
// Last backup continue button.
$this->find_button(get_string('backupstage16action', 'backup'))->press();
$this->execute("behat_general::i_click_on", array(get_string('backupstage16action', 'backup'), 'button'));
}
/**
@@ -116,21 +101,19 @@ class behat_backup extends behat_base {
$this->getSession()->visit($this->locate_path('/?redirect=0'));
// Click the course link.
$this->find_link($backupcourse)->click();
$this->execute("behat_general::click_link", $backupcourse);
// Click the backup link.
$this->find_link(get_string('backup'))->click();
$this->wait();
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration", get_string('backup'));
// Initial settings.
$this->find_button(get_string('jumptofinalstep', 'backup'))->press();
$this->wait();
$this->execute("behat_forms::press_button", get_string('jumptofinalstep', 'backup'));
// Waiting for it to finish.
$this->wait(self::EXTENDED_TIMEOUT);
$this->execute("behat_general::wait_until_the_page_is_ready");
// Last backup continue button.
$this->find_button(get_string('backupstage16action', 'backup'))->press();
$this->execute("behat_general::i_click_on", array(get_string('backupstage16action', 'backup'), 'button'));
}
/**
@@ -152,15 +135,13 @@ class behat_backup extends behat_base {
// Go to homepage.
$this->getSession()->visit($this->locate_path('/?redirect=0'));
$this->wait();
$this->execute("behat_general::wait_until_the_page_is_ready");
// Click the course link.
$this->find_link($tocourse)->click();
$this->wait();
$this->execute("behat_general::click_link", $tocourse);
// Click the import link.
$this->navigate_to_course_settings_link('import');
$this->wait();
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration", get_string('import'));
// Select the course.
$exception = new ExpectationException('"' . $fromcourse . '" course not found in the list of courses to import from',
@@ -175,25 +156,24 @@ class behat_backup extends behat_base {
$radiofield = new behat_form_field($this->getSession(), $radionode);
$radiofield->set_value(1);
$this->find_button(get_string('continue'))->press();
$this->wait();
$this->execute("behat_forms::press_button", get_string('continue'));
// Initial settings.
$this->fill_backup_restore_form($this->get_step_options($options, "Initial"));
$this->find_button(get_string('importbackupstage1action', 'backup'))->press();
$this->wait();
$this->execute("behat_forms::press_button", get_string('importbackupstage1action', 'backup'));
// Schema settings.
$this->fill_backup_restore_form($this->get_step_options($options, "Schema"));
$this->find_button(get_string('importbackupstage2action', 'backup'))->press();
$this->wait();
$this->execute("behat_forms::press_button", get_string('importbackupstage2action', 'backup'));
// Run it.
$this->find_button(get_string('importbackupstage4action', 'backup'))->press();
$this->wait(self::EXTENDED_TIMEOUT);
$this->execute("behat_forms::press_button", get_string('importbackupstage4action', 'backup'));
// Wait to ensure restore is complete.
$this->execute("behat_general::wait_until_the_page_is_ready");
// Continue and redirect to 'to' course.
$this->find_button(get_string('continue'))->press();
$this->execute("behat_general::i_click_on", array(get_string('continue'), 'button'));
}
/**
@@ -215,17 +195,16 @@ class behat_backup extends behat_base {
$existingcourse = behat_context_helper::escape($existingcourse);
// Selecting the specified course (we can not call behat_forms::select_radio here as is in another behat subcontext).
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-existing-course ')]" .
$radionodexpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-existing-course ')]" .
"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' restore-course-search ')]" .
"/descendant::tr[contains(., $existingcourse)]" .
"/descendant::input[@type='radio']");
$radionode->click();
"/descendant::input[@type='radio']";
$this->execute("behat_general::i_click_on", array($radionodexpath, 'xpath_element'));
// Pressing the continue button of the restore into an existing course section.
$continuenode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-existing-course ')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();
$continuenodexpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-existing-course ')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']";
$this->execute("behat_general::i_click_on", array($continuenodexpath, 'xpath_element'));
// Common restore process using provided key/value options.
$this->process_restore($options);
@@ -246,16 +225,15 @@ class behat_backup extends behat_base {
$this->select_backup($backupfilename);
// The first category in the list.
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-new-course ')]" .
$radionodexpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-new-course ')]" .
"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' restore-course-search ')]" .
"/descendant::input[@type='radio']");
$radionode->click();
"/descendant::input[@type='radio']";
$this->execute("behat_general::i_click_on", array($radionodexpath, 'xpath_element'));
// Pressing the continue button of the restore into an existing course section.
$continuenode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-new-course ')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();
$continuenodexpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-new-course ')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']";
$this->execute("behat_general::i_click_on", array($continuenodexpath, 'xpath_element'));
// Common restore process using provided key/value options.
$this->process_restore($options);
@@ -276,15 +254,14 @@ class behat_backup extends behat_base {
$this->select_backup($backupfilename);
// Merge without deleting radio option.
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='radio'][@name='target'][@value='1']");
$radionode->click();
$radionodexpath = "//div[contains(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='radio'][@name='target'][@value='1']";
$this->execute("behat_general::i_click_on", array($radionodexpath, 'xpath_element'));
// Pressing the continue button of the restore merging section.
$continuenode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();
$continuenodexpath = "//div[contains(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']";
$this->execute("behat_general::i_click_on", array($continuenodexpath, 'xpath_element'));
// Common restore process using provided key/value options.
$this->process_restore($options);
@@ -305,15 +282,14 @@ class behat_backup extends behat_base {
$this->select_backup($backupfilename);
// Delete contents radio option.
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='radio'][@name='target'][@value='0']");
$radionode->click();
$radionodexpath = "//div[contains(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='radio'][@name='target'][@value='0']";
$this->execute("behat_general::i_click_on", array($radionodexpath, 'xpath_element'));
// Pressing the continue button of the restore merging section.
$continuenode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();
$continuenodexpath = "//div[contains(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']";
$this->execute("behat_general::i_click_on", array($continuenodexpath, 'xpath_element'));
// Common restore process using provided key/value options.
$this->process_restore($options);
@@ -340,7 +316,7 @@ class behat_backup extends behat_base {
$restorelink->click();
// Confirm the backup contents.
$restore = $this->find_button(get_string('continue'))->press();
$this->find_button(get_string('continue'))->press();
}
/**
@@ -356,23 +332,20 @@ class behat_backup extends behat_base {
// Settings.
$this->fill_backup_restore_form($this->get_step_options($options, "Settings"));
$this->find_button(get_string('restorestage4action', 'backup'))->press();
$this->wait();
$this->execute("behat_forms::press_button", get_string('restorestage4action', 'backup'));
// Schema.
$this->fill_backup_restore_form($this->get_step_options($options, "Schema"));
$this->find_button(get_string('restorestage8action', 'backup'))->press();
$this->wait();
$this->execute("behat_forms::press_button", get_string('restorestage8action', 'backup'));
// Review, no options here.
$this->find_button(get_string('restorestage16action', 'backup'))->press();
$this->wait();
$this->execute("behat_forms::press_button", get_string('restorestage16action', 'backup'));
// Wait till the final button is visible.
$this->execute("behat_general::wait_until_the_page_is_ready");
// Last restore continue button, redirected to restore course after this.
$this->find_button(get_string('restorestage32action', 'backup'))->press();
// Long wait when waiting for the restore to finish.
$this->wait(self::EXTENDED_TIMEOUT);
$this->execute("behat_general::i_click_on", array(get_string('restorestage32action', 'backup'), 'button'));
}
/**
@@ -431,25 +404,4 @@ class behat_backup extends behat_base {
return $pageoptions;
}
/**
* Waits until the DOM and the page Javascript code is ready.
*
* @param int $timeout The number of seconds that we wait.
* @return void
*/
protected function wait($timeout = false) {
if (!$this->running_javascript()) {
return;
}
if (!$timeout) {
$timeout = self::TIMEOUT;
}
$this->getSession()->wait($timeout * 1000, self::PAGE_READY_JS);
}
}
@@ -1,48 +0,0 @@
<?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/>.
/**
* Backup and restore actions to help behat feature files writting overrides.
*
* @copyright 2016 Damyon Wiese
* @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__ . '/../../../../backup/util/ui/tests/behat/behat_backup.php');
require_once(__DIR__ . '/behat_theme_boost_behat_navigation.php');
use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Behat\Mink\Exception\ExpectationException as ExpectationException;
/**
* Backup-related steps definitions overrides.
*
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_boost_behat_backup extends behat_backup {
protected function navigate_to_course_settings_link($langstring, $component = '') {
$behatnavigation = new behat_theme_boost_behat_navigation();
$behatnavigation->setMink($this->getMink());
$behatnavigation->i_navigate_to_node_in(get_string($langstring, $component),
get_string('courseadministration'));
}
}
+1 -2
View File
@@ -3,7 +3,6 @@
"lib/tests/behat/action_menu.feature",
"course/tests/behat/activities_edit_with_block_dock.feature",
"blocks/tests/behat/hide_blocks.feature",
"blocks/tests/behat/move_blocks.feature",
"backup/util/ui/tests/behat/restore_moodle2_courses.feature"
"blocks/tests/behat/move_blocks.feature"
]
}