Skip to content

Commit

Permalink
Merge branch 'MDL-45935-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Jun 16, 2014
2 parents b3f297d + 87a37eb commit 6581e38
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 44 deletions.
24 changes: 12 additions & 12 deletions backup/util/ui/tests/behat/backup_courses.feature
Expand Up @@ -18,7 +18,7 @@ Feature: Backup Moodle courses
@javascript
Scenario: Backup a course providing options
When I backup "Course 1" course using this options:
| Filename | test_backup.mbz |
| Confirmation | Filename | test_backup.mbz |
Then I should see "Restore"
And I click on "Restore" "link" in the "test_backup.mbz" "table_row"
And I should see "URL of backup"
Expand All @@ -27,11 +27,11 @@ Feature: Backup Moodle courses
@javascript
Scenario: Backup a course with default options
When I backup "Course 1" course using this options:
| Filename | test_backup.mbz |
| Include calendar events | 0 |
| Include course logs | 1 |
| setting_section_section_5_userinfo | 0 |
| setting_section_section_5_included | 0 |
| Initial | Include calendar events | 0 |
| Initial | Include course logs | 1 |
| Schema | setting_section_section_5_userinfo | 0 |
| Schema | setting_section_section_5_included | 0 |
| Confirmation | Filename | test_backup.mbz |
Then I should see "Restore"
And I click on "Restore" "link" in the "test_backup.mbz" "table_row"
And I should not see "Section 3"
Expand All @@ -44,17 +44,17 @@ Feature: Backup Moodle courses
@javascript
Scenario: Backup a course without blocks
When I backup "Course 1" course using this options:
| id_setting_root_blocks | 0 |
| 1 | setting_root_blocks | 0 |
Then I should see "Course backup area"

@javascript
Scenario: Backup selecting just one section
When I backup "Course 2" course using this options:
| Filename | test_backup.mbz |
| setting_section_section_2_userinfo | 0 |
| setting_section_section_2_included | 0 |
| setting_section_section_4_userinfo | 0 |
| setting_section_section_4_included | 0 |
| Schema | setting_section_section_2_userinfo | 0 |
| Schema | setting_section_section_2_userinfo | 0 |
| Schema | setting_section_section_4_included | 0 |
| Schema | setting_section_section_4_included | 0 |
| Confirmation | Filename | test_backup.mbz |
Then I should see "Course backup area"
And I click on "Restore" "link" in the "test_backup.mbz" "table_row"
And I should not see "Section 2"
Expand Down
56 changes: 38 additions & 18 deletions backup/util/ui/tests/behat/behat_backup.php
Expand Up @@ -50,34 +50,31 @@ class behat_backup extends behat_base {
* @param TableNode $options Backup options or false if no options provided
*/
public function i_backup_course_using_this_options($backupcourse, $options = false) {

// We can not use other steps here as we don't know where the provided data
// table elements are used, and we need to catch exceptions contantly.

// Go to homepage.
$this->getSession()->visit($this->locate_path('/'));
$this->wait();

// Click the course link.
$this->find_link($backupcourse)->click();
$this->wait();

// Click the backup link.
$this->find_link(get_string('backup'))->click();
$this->wait();

// Initial settings.
$this->fill_backup_restore_form($options);
$this->fill_backup_restore_form($this->get_step_options($options, "Initial"));
$this->find_button(get_string('backupstage1action', 'backup'))->press();
$this->wait();

// Schema settings.
$this->fill_backup_restore_form($options);
$this->fill_backup_restore_form($this->get_step_options($options, "Schema"));
$this->find_button(get_string('backupstage2action', 'backup'))->press();
$this->wait();

// Confirmation and review, backup filename can also be specified.
$this->fill_backup_restore_form($options);
$this->fill_backup_restore_form($this->get_step_options($options, "Confirmation"));
$this->find_button(get_string('backupstage4action', 'backup'))->press();

// Waiting for it to finish.
Expand Down Expand Up @@ -132,12 +129,12 @@ public function i_import_course_into_course($fromcourse, $tocourse, $options = f
$this->wait();

// Initial settings.
$this->fill_backup_restore_form($options);
$this->fill_backup_restore_form($this->get_step_options($options, "Initial"));
$this->find_button(get_string('importbackupstage1action', 'backup'))->press();
$this->wait();

// Schema settings.
$this->fill_backup_restore_form($options);
$this->fill_backup_restore_form($this->get_step_options($options, "Schema"));
$this->find_button(get_string('importbackupstage2action', 'backup'))->press();
$this->wait();

Expand Down Expand Up @@ -303,12 +300,12 @@ protected function process_restore($options) {
// table elements are used, and we need to catch exceptions contantly.

// Settings.
$this->fill_backup_restore_form($options);
$this->fill_backup_restore_form($this->get_step_options($options, "Settings"));
$this->find_button(get_string('restorestage4action', 'backup'))->press();
$this->wait();

// Schema.
$this->fill_backup_restore_form($options);
$this->fill_backup_restore_form($this->get_step_options($options, "Schema"));
$this->find_button(get_string('restorestage8action', 'backup'))->press();
$this->wait();

Expand Down Expand Up @@ -341,23 +338,46 @@ protected function fill_backup_restore_form($options) {
return;
}

// Wait for the page to be loaded and the JS ready.
$this->wait();

// If we find any of the provided options in the current form we should set the value.
$datahash = $options->getRowsHash();
foreach ($datahash as $locator => $value) {
$field = behat_field_manager::get_form_field_from_label($locator, $this);
$field->set_value($value);
}
}

try {
$field = behat_field_manager::get_form_field_from_label($locator, $this);
$field->set_value($value);
/**
* Get the options specific to this step of the backup/restore process.
*
* @param TableNode $options The options table to filter
* @param string $step The name of the step
* @return TableNode The filtered options table
* @throws ExpectationException
*/
protected function get_step_options($options, $step) {
// Nothing to fill if no options are provided.
if (!$options) {
return;
}

} catch (ElementNotFoundException $e) {
// Next provided option then, this one should be part of another page's fields.
$pageoptions = clone $options;

$rows = $options->getRows();
$newrows = array();
foreach ($rows as $k => $data) {
if (count($data) !== 3) {
// Not enough information to guess the page.
throw new ExpectationException("The backup/restore step must be specified for all backup options");
} else if ($data[0] == $step) {
unset($data[0]);
$newrows[] = $data;
}
}
$pageoptions->setRows($newrows);
return $pageoptions;
}


/**
* Waits until the DOM and the page Javascript code is ready.
*
Expand Down
28 changes: 14 additions & 14 deletions backup/util/ui/tests/behat/restore_moodle2_courses.feature
Expand Up @@ -25,7 +25,7 @@ Feature: Restore Moodle 2 course backups
@javascript
Scenario: Restore a course in another existing course
When I backup "Course 1" course using this options:
| Filename | test_backup.mbz |
| Confirmation | Filename | test_backup.mbz |
And I restore "test_backup.mbz" backup into "Course 2" course using this options:
Then I should see "Course 2"
And I should see "Community finder" in the "Community finder" "block"
Expand All @@ -34,9 +34,9 @@ Feature: Restore Moodle 2 course backups
@javascript
Scenario: Restore a course in a new course
When I backup "Course 1" course using this options:
| Filename | test_backup.mbz |
| Confirmation | Filename | test_backup.mbz |
And I restore "test_backup.mbz" backup into a new course using this options:
| Course name | Course 1 restored in a new course |
| Schema | Course name | Course 1 restored in a new course |
Then I should see "Course 1 restored in a new course"
And I should see "Community finder" in the "Community finder" "block"
And I should see "Test forum name"
Expand All @@ -50,28 +50,28 @@ Feature: Restore Moodle 2 course backups
@javascript
Scenario: Restore a backup into the same course
When I backup "Course 3" course using this options:
| Filename | test_backup.mbz |
| Confirmation | Filename | test_backup.mbz |
And I restore "test_backup.mbz" backup into "Course 2" course using this options:
| setting_section_section_3_included | 0 |
| setting_section_section_3_userinfo | 0 |
| setting_section_section_5_included | 0 |
| setting_section_section_5_userinfo | 0 |
| Schema | setting_section_section_3_included | 0 |
| Schema | setting_section_section_3_userinfo | 0 |
| Schema | setting_section_section_5_included | 0 |
| Schema | setting_section_section_5_userinfo | 0 |
Then I should see "Course 2"
And I should see "Test assign name"
And I should not see "Test database name"

@javascript
Scenario: Restore a backup into the same course removing it's contents before that
When I backup "Course 1" course using this options:
| Filename | test_backup.mbz |
| Confirmation | Filename | test_backup.mbz |
And I follow "Course 1"
And I add a "Forum" to section "1" and I fill the form with:
| Forum name | Test forum post backup name |
| Description | Test forum post backup description |
And I follow "Restore"
And I merge "test_backup.mbz" backup into the current course after deleting it's contents using this options:
| setting_section_section_5_userinfo | 0 |
| setting_section_section_5_included | 0 |
| Schema | setting_section_section_8_userinfo | 0 |
| Schema | setting_section_section_8_included | 0 |
Then I should see "Course 1"
And I should not see "Section 3"
And I should not see "Test forum post backup name"
Expand All @@ -81,7 +81,7 @@ Feature: Restore Moodle 2 course backups
@javascript
Scenario: Restore a backup into a new course changing the course format afterwards
Given I backup "Course 1" course using this options:
| Filename | test_backup.mbz |
| Confirmation | Filename | test_backup.mbz |
When I restore "test_backup.mbz" backup into a new course using this options:
Then I should see "Topic 1"
And I should see "Test forum name"
Expand Down Expand Up @@ -117,9 +117,9 @@ Feature: Restore Moodle 2 course backups
And I hide section "3"
And I hide section "7"
When I backup "Course 1" course using this options:
| Filename | test_backup.mbz |
| Confirmation | Filename | test_backup.mbz |
And I restore "test_backup.mbz" backup into "Course 2" course using this options:
| Overwrite course configuration | Yes |
| Schema | Overwrite course configuration | Yes |
And I click on "Edit settings" "link" in the "Administration" "block"
And I expand all fieldsets
Then the field "id_format" matches value "Topics format"
Expand Down

0 comments on commit 6581e38

Please sign in to comment.