Skip to content

Commit

Permalink
Merge branch 'wip-mdl-57325-m32' of https://github.com/rajeshtaneja/m…
Browse files Browse the repository at this point in the history
…oodle into MOODLE_32_STABLE
  • Loading branch information
danpoltawski committed Dec 12, 2016
2 parents 6e4cc6c + 457c913 commit b82ddcb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 154 deletions.
160 changes: 56 additions & 104 deletions backup/util/ui/tests/behat/behat_backup.php
Expand Up @@ -43,19 +43,6 @@
*/
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.
Expand All @@ -70,33 +57,31 @@ public function i_backup_course_using_this_options($backupcourse, $options = fal

// 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'));
}

/**
Expand All @@ -116,21 +101,19 @@ public function i_perform_a_quick_backup_of_course($backupcourse) {
$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'));
}

/**
Expand All @@ -152,15 +135,13 @@ public function i_import_course_into_course($fromcourse, $tocourse, $options = f

// 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',
Expand All @@ -175,25 +156,24 @@ public function i_import_course_into_course($fromcourse, $tocourse, $options = f
$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'));
}

/**
Expand All @@ -215,17 +195,16 @@ public function i_restore_backup_into_course_using_this_options($backupfilename,
$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);
Expand All @@ -246,16 +225,15 @@ public function i_restore_backup_into_a_new_course_using_this_options($backupfil
$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);
Expand All @@ -276,15 +254,14 @@ public function i_merge_backup_into_the_current_course($backupfilename, $options
$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);
Expand All @@ -305,15 +282,14 @@ public function i_merge_backup_into_current_course_deleting_its_contents($backup
$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);
Expand All @@ -340,7 +316,7 @@ protected function select_backup($backupfilename) {
$restorelink->click();

// Confirm the backup contents.
$restore = $this->find_button(get_string('continue'))->press();
$this->find_button(get_string('continue'))->press();
}

/**
Expand All @@ -356,23 +332,20 @@ protected function process_restore($options) {

// 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'));

// Last restore continue button, redirected to restore course after this.
$this->find_button(get_string('restorestage32action', 'backup'))->press();
// Wait till the final button is visible.
$this->execute("behat_general::wait_until_the_page_is_ready");

// Long wait when waiting for the restore to finish.
$this->wait(self::EXTENDED_TIMEOUT);
// Last restore continue button, redirected to restore course after this.
$this->execute("behat_general::i_click_on", array(get_string('restorestage32action', 'backup'), 'button'));
}

/**
Expand Down Expand Up @@ -431,25 +404,4 @@ protected function get_step_options($options, $step) {

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);
}

}
48 changes: 0 additions & 48 deletions theme/boost/tests/behat/behat_theme_boost_behat_backup.php

This file was deleted.

3 changes: 1 addition & 2 deletions theme/boost/tests/behat/blacklist.json
Expand Up @@ -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"
]
}

0 comments on commit b82ddcb

Please sign in to comment.