| 1 | efrain | 1 | @core @core_backup
 | 
        
           |  |  | 2 | Feature: Restore Moodle 2 course backups
 | 
        
           |  |  | 3 |   In order to continue using my stored course contents
 | 
        
           |  |  | 4 |   As a teacher and an admin
 | 
        
           |  |  | 5 |   I need to restore them inside other Moodle courses or in new courses
 | 
        
           |  |  | 6 |   | 
        
           |  |  | 7 |   Background:
 | 
        
           |  |  | 8 |     Given the following "courses" exist:
 | 
        
           |  |  | 9 |       | fullname | shortname | category | format | numsections | coursedisplay | initsections |
 | 
        
           |  |  | 10 |       | Course 1 | C1        | 0        | topics | 15          | 1             | 1            |
 | 
        
           |  |  | 11 |       | Course 2 | C2        | 0        | topics | 5           | 0             | 1            |
 | 
        
           |  |  | 12 |       | Course 3 | C3        | 0        | topics | 2           | 0             | 1            |
 | 
        
           |  |  | 13 |       | Course 4 | C4        | 0        | topics | 20          | 0             | 1            |
 | 
        
           |  |  | 14 |       | Course 5 | C5        | 0        | topics | 15          | 1             | 0            |
 | 
        
           |  |  | 15 |     And the following "activities" exist:
 | 
        
           |  |  | 16 |       | activity | course | idnumber | name               | intro                | section | externalurl           |
 | 
        
           |  |  | 17 |       | assign   | C3     | assign1  | Test assign name   | Assign description   | 1       |                       |
 | 
        
           |  |  | 18 |       | data     | C3     | data1    | Test database name | Database description | 2       |                       |
 | 
        
           |  |  | 19 |       | forum    | C1     | 0001     | Test forum name    |                      | 1       |                       |
 | 
        
           |  |  | 20 |       | url      | C1     | url1     | Test URL name      | Test URL description | 3       | http://www.moodle.org |
 | 
        
           |  |  | 21 |       | forum    | C5     | 0005     | Test forum name    |                      | 1       |                       |
 | 
        
           |  |  | 22 |       | url      | C5     | url5     | Test URL name      | Test URL description | 3       | http://www.moodle.org |
 | 
        
           |  |  | 23 |     And the following "blocks" exist:
 | 
        
           |  |  | 24 |       | blockname        | contextlevel | reference | pagetypepattern | defaultregion |
 | 
        
           |  |  | 25 |       | activity_modules | Course       | C1        | course-view-*   | side-pre      |
 | 
        
           |  |  | 26 |       | activity_modules | Course       | C5        | course-view-*   | side-pre      |
 | 
        
           |  |  | 27 |     And the following config values are set as admin:
 | 
        
           |  |  | 28 |       | enableasyncbackup | 0 |
 | 
        
           |  |  | 29 |     And I log in as "admin"
 | 
        
           |  |  | 30 |     And I am on "Course 1" course homepage with editing mode on
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 |   @javascript
 | 
        
           |  |  | 33 |   Scenario: Restore a course in another existing course
 | 
        
           |  |  | 34 |     When I backup "Course 1" course using this options:
 | 
        
           |  |  | 35 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 36 |     And I restore "test_backup.mbz" backup into "Course 2" course using this options:
 | 
        
           |  |  | 37 |     Then I should see "Course 2"
 | 
        
           |  |  | 38 |     And I should see "Activities" in the "Activities" "block"
 | 
        
           |  |  | 39 |     And I should see "Test forum name"
 | 
        
           |  |  | 40 |   | 
        
           |  |  | 41 |   @javascript
 | 
        
           |  |  | 42 |   Scenario: Restore a course in a new course
 | 
        
           |  |  | 43 |     When I backup "Course 1" course using this options:
 | 
        
           |  |  | 44 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 45 |     And I restore "test_backup.mbz" backup into a new course using this options:
 | 
        
           |  |  | 46 |       | Schema | Course name | Course 1 restored in a new course |
 | 
        
           |  |  | 47 |     Then I should see "Course 1 restored in a new course"
 | 
        
           |  |  | 48 |     And I should see "Activities" in the "Activities" "block"
 | 
        
           |  |  | 49 |     And I should see "Test forum name"
 | 
        
           |  |  | 50 |     And I should see "Section 15"
 | 
        
           |  |  | 51 |     And I should not see "Section 16"
 | 
        
           |  |  | 52 |     And I navigate to "Settings" in current page administration
 | 
        
           |  |  | 53 |     And I expand all fieldsets
 | 
        
           |  |  | 54 |     And the field "id_format" matches value "Custom sections"
 | 
        
           |  |  | 55 |     And I press "Cancel"
 | 
        
           |  |  | 56 |   | 
        
           |  |  | 57 |   @javascript
 | 
        
           |  |  | 58 |   Scenario: Restore a backup into the same course
 | 
        
           |  |  | 59 |     When I backup "Course 3" course using this options:
 | 
        
           |  |  | 60 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 61 |     And I restore "test_backup.mbz" backup into "Course 2" course using this options:
 | 
        
           |  |  | 62 |       | Schema | Test database name | 0 |
 | 
        
           |  |  | 63 |       | Schema | Section 2 | 0 |
 | 
        
           |  |  | 64 |     Then I should see "Course 2"
 | 
        
           |  |  | 65 |     And I should see "Test assign name"
 | 
        
           |  |  | 66 |     And I should not see "Test database name"
 | 
        
           |  |  | 67 |   | 
        
           |  |  | 68 |   @javascript
 | 
        
           |  |  | 69 |   Scenario: Restore a backup into the same course removing it's contents before that
 | 
        
           |  |  | 70 |     When I backup "Course 1" course using this options:
 | 
        
           |  |  | 71 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 72 |     And the following "activity" exists:
 | 
        
           |  |  | 73 |       | activity | forum                              |
 | 
        
           |  |  | 74 |       | course   | C1                                 |
 | 
        
           |  |  | 75 |       | section  | 1                                  |
 | 
        
           |  |  | 76 |       | name     | Test forum post backup name        |
 | 
        
           |  |  | 77 |     And I am on the "Course 1" "restore" page
 | 
        
           |  |  | 78 |     And I merge "test_backup.mbz" backup into the current course after deleting it's contents using this options:
 | 
        
           |  |  | 79 |       | Schema | Section 3 | 0 |
 | 
        
           |  |  | 80 |     Then I should see "Course 1"
 | 
        
           |  |  | 81 |     And I should not see "Section 3"
 | 
        
           |  |  | 82 |     And I should not see "Test forum post backup name"
 | 
        
           |  |  | 83 |     And I should see "Activities" in the "Activities" "block"
 | 
        
           |  |  | 84 |     And I should see "Test forum name"
 | 
        
           |  |  | 85 |   | 
        
           |  |  | 86 |   @javascript
 | 
        
           |  |  | 87 |   Scenario: Restore a backup into a new course changing the course format afterwards
 | 
        
           |  |  | 88 |     Given I backup "Course 5" course using this options:
 | 
        
           |  |  | 89 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 90 |     When I restore "test_backup.mbz" backup into a new course using this options:
 | 
        
           |  |  | 91 |     Then I should see "New section"
 | 
        
           |  |  | 92 |     And I should see "Test forum name"
 | 
        
           |  |  | 93 |     And I navigate to "Settings" in current page administration
 | 
        
           |  |  | 94 |     And I expand all fieldsets
 | 
        
           |  |  | 95 |     And the field "id_format" matches value "Custom sections"
 | 
        
           |  |  | 96 |     And I set the following fields to these values:
 | 
        
           |  |  | 97 |       | id_startdate_day   | 1               |
 | 
        
           |  |  | 98 |       | id_startdate_month | January         |
 | 
        
           |  |  | 99 |       | id_startdate_year  | 2020            |
 | 
        
           |  |  | 100 |       | id_format          | Weekly sections |
 | 
        
           |  |  | 101 |       | id_enddate_enabled | 0               |
 | 
        
           |  |  | 102 |     And I press "Save and display"
 | 
        
           |  |  | 103 |     And I should see "1 January - 7 January"
 | 
        
           |  |  | 104 |     And I should see "Test forum name"
 | 
        
           |  |  | 105 |     And I navigate to "Settings" in current page administration
 | 
        
           |  |  | 106 |     And I expand all fieldsets
 | 
        
           |  |  | 107 |     And the field "id_format" matches value "Weekly sections"
 | 
        
           |  |  | 108 |     And I set the following fields to these values:
 | 
        
           |  |  | 109 |       | id_format | Social |
 | 
        
           |  |  | 110 |     And I press "Save and display"
 | 
        
           |  |  | 111 |     And I should see "An open forum for chatting about anything you want to"
 | 
        
           |  |  | 112 |     And I navigate to "Settings" in current page administration
 | 
        
           |  |  | 113 |     And I expand all fieldsets
 | 
        
           |  |  | 114 |     And the field "id_format" matches value "Social"
 | 
        
           |  |  | 115 |     And I press "Cancel"
 | 
        
           |  |  | 116 |   | 
        
           |  |  | 117 |   @javascript
 | 
        
           |  |  | 118 |   Scenario: Restore a backup in an existing course retaining the backup course settings
 | 
        
           |  |  | 119 |     Given I hide section "3"
 | 
        
           |  |  | 120 |     And I hide section "7"
 | 
        
           |  |  | 121 |     When I backup "Course 1" course using this options:
 | 
        
           |  |  | 122 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 123 |     And I restore "test_backup.mbz" backup into "Course 2" course using this options:
 | 
        
           |  |  | 124 |       | Schema | Overwrite course configuration | Yes |
 | 
        
           |  |  | 125 |     And I navigate to "Settings" in current page administration
 | 
        
           |  |  | 126 |     And I expand all fieldsets
 | 
        
           |  |  | 127 |     Then the field "id_format" matches value "Custom sections"
 | 
        
           |  |  | 128 |     And the field "Course layout" matches value "Show one section per page"
 | 
        
           |  |  | 129 |     And the field "Course short name" matches value "C1_1"
 | 
        
           |  |  | 130 |     And I press "Cancel"
 | 
        
           |  |  | 131 |     And section "3" should be visible
 | 
        
           |  |  | 132 |     And section "7" should be hidden
 | 
        
           |  |  | 133 |     And section "15" should be visible
 | 
        
           |  |  | 134 |     And I should see "Section 15"
 | 
        
           |  |  | 135 |     And I should not see "Section 16"
 | 
        
           |  |  | 136 |     And I should see "Test URL name" in the "Section 3" "section"
 | 
        
           |  |  | 137 |     And I should see "Test forum name" in the "Section 1" "section"
 | 
        
           |  |  | 138 |   | 
        
           |  |  | 139 |   @javascript
 | 
        
           |  |  | 140 |   Scenario: Restore a backup in an existing course keeping the target course settings
 | 
        
           |  |  | 141 |     Given I hide section "3"
 | 
        
           |  |  | 142 |     And I hide section "7"
 | 
        
           |  |  | 143 |     When I backup "Course 1" course using this options:
 | 
        
           |  |  | 144 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 145 |     And I restore "test_backup.mbz" backup into "Course 2" course using this options:
 | 
        
           |  |  | 146 |       | Schema | Overwrite course configuration | No |
 | 
        
           |  |  | 147 |     And I navigate to "Settings" in current page administration
 | 
        
           |  |  | 148 |     And I expand all fieldsets
 | 
        
           |  |  | 149 |     Then the field "id_format" matches value "Custom sections"
 | 
        
           |  |  | 150 |     And the field "Course short name" matches value "C2"
 | 
        
           |  |  | 151 |     And the field "Course layout" matches value "Show all sections on one page"
 | 
        
           |  |  | 152 |     And I press "Cancel"
 | 
        
           |  |  | 153 |     And section "3" should be visible
 | 
        
           |  |  | 154 |     And section "7" should be hidden
 | 
        
           |  |  | 155 |     And section "15" should be visible
 | 
        
           |  |  | 156 |     And I should see "Section 15"
 | 
        
           |  |  | 157 |     And I should not see "Section 16"
 | 
        
           |  |  | 158 |     And I should see "Test URL name" in the "Section 3" "section"
 | 
        
           |  |  | 159 |     And I should see "Test forum name" in the "Section 1" "section"
 | 
        
           |  |  | 160 |   | 
        
           |  |  | 161 |   @javascript
 | 
        
           |  |  | 162 |   Scenario: Restore a backup in an existing course deleting contents and retaining the backup course settings
 | 
        
           |  |  | 163 |     Given I hide section "3"
 | 
        
           |  |  | 164 |     And I hide section "7"
 | 
        
           |  |  | 165 |     When I backup "Course 1" course using this options:
 | 
        
           |  |  | 166 |       | Initial |  Include enrolled users | 0 |
 | 
        
           |  |  | 167 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 168 |     And I am on the "Course 2" "restore" page
 | 
        
           |  |  | 169 |     And I merge "test_backup.mbz" backup into the current course after deleting it's contents using this options:
 | 
        
           |  |  | 170 |       | Schema | Overwrite course configuration | Yes |
 | 
        
           |  |  | 171 |     And I navigate to "Settings" in current page administration
 | 
        
           |  |  | 172 |     And I expand all fieldsets
 | 
        
           |  |  | 173 |     Then the field "id_format" matches value "Custom sections"
 | 
        
           |  |  | 174 |     And the field "Course layout" matches value "Show one section per page"
 | 
        
           |  |  | 175 |     And the field "Course short name" matches value "C1_1"
 | 
        
           |  |  | 176 |     And I press "Cancel"
 | 
        
           |  |  | 177 |     And section "3" should be hidden
 | 
        
           |  |  | 178 |     And section "7" should be hidden
 | 
        
           |  |  | 179 |     And section "15" should be visible
 | 
        
           |  |  | 180 |     And I should see "Section 15"
 | 
        
           |  |  | 181 |     And I should not see "Section 16"
 | 
        
           |  |  | 182 |     And I should see "Test URL name" in the "Section 3" "section"
 | 
        
           |  |  | 183 |     And I should see "Test forum name" in the "Section 1" "section"
 | 
        
           |  |  | 184 |   | 
        
           |  |  | 185 |   @javascript
 | 
        
           |  |  | 186 |   Scenario: Restore a backup in an existing course deleting contents and keeping the current course settings
 | 
        
           |  |  | 187 |     Given I hide section "3"
 | 
        
           |  |  | 188 |     And I hide section "7"
 | 
        
           |  |  | 189 |     When I backup "Course 1" course using this options:
 | 
        
           |  |  | 190 |       | Initial |  Include enrolled users | 0 |
 | 
        
           |  |  | 191 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 192 |     And I am on the "Course 2" "restore" page
 | 
        
           |  |  | 193 |     And I merge "test_backup.mbz" backup into the current course after deleting it's contents using this options:
 | 
        
           |  |  | 194 |       | Schema | Overwrite course configuration | No |
 | 
        
           |  |  | 195 |     And I navigate to "Settings" in current page administration
 | 
        
           |  |  | 196 |     And I expand all fieldsets
 | 
        
           |  |  | 197 |     Then the field "id_format" matches value "Custom sections"
 | 
        
           |  |  | 198 |     And the field "Course short name" matches value "C2"
 | 
        
           |  |  | 199 |     And the field "Course layout" matches value "Show all sections on one page"
 | 
        
           |  |  | 200 |     And I press "Cancel"
 | 
        
           |  |  | 201 |     And section "3" should be hidden
 | 
        
           |  |  | 202 |     And section "7" should be hidden
 | 
        
           |  |  | 203 |     And section "15" should be visible
 | 
        
           |  |  | 204 |     And I should see "Section 15"
 | 
        
           |  |  | 205 |     And I should not see "Section 16"
 | 
        
           |  |  | 206 |     And I should see "Test URL name" in the "Section 3" "section"
 | 
        
           |  |  | 207 |     And I should see "Test forum name" in the "Section 1" "section"
 | 
        
           |  |  | 208 |   | 
        
           |  |  | 209 |   @javascript
 | 
        
           |  |  | 210 |   Scenario: Restore a backup in an existing course deleting contents decreasing the number of sections
 | 
        
           |  |  | 211 |     Given I hide section "3"
 | 
        
           |  |  | 212 |     And I hide section "7"
 | 
        
           |  |  | 213 |     When I backup "Course 1" course using this options:
 | 
        
           |  |  | 214 |       | Initial |  Include enrolled users | 0 |
 | 
        
           |  |  | 215 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 216 |     And I am on the "Course 4" "restore" page
 | 
        
           |  |  | 217 |     And I merge "test_backup.mbz" backup into the current course after deleting it's contents using this options:
 | 
        
           |  |  | 218 |       | Schema | Overwrite course configuration | No |
 | 
        
           |  |  | 219 |     And I navigate to "Settings" in current page administration
 | 
        
           |  |  | 220 |     And I expand all fieldsets
 | 
        
           |  |  | 221 |     Then the field "id_format" matches value "Custom sections"
 | 
        
           |  |  | 222 |     And the field "Course short name" matches value "C4"
 | 
        
           |  |  | 223 |     And the field "Course layout" matches value "Show all sections on one page"
 | 
        
           |  |  | 224 |     And I press "Cancel"
 | 
        
           |  |  | 225 |     And section "3" should be hidden
 | 
        
           |  |  | 226 |     And section "7" should be hidden
 | 
        
           |  |  | 227 |     And section "15" should be visible
 | 
        
           |  |  | 228 |     And I should see "Section 15"
 | 
        
           |  |  | 229 |     And I should not see "Section 16"
 | 
        
           |  |  | 230 |     And I should see "Test URL name" in the "Section 3" "section"
 | 
        
           |  |  | 231 |     And I should see "Test forum name" in the "Section 1" "section"
 | 
        
           |  |  | 232 |   | 
        
           |  |  | 233 |   @javascript
 | 
        
           |  |  | 234 |   Scenario: Restore a backup with override permission
 | 
        
           |  |  | 235 |     Given the following "permission overrides" exist:
 | 
        
           |  |  | 236 |       | capability         | permission | role           | contextlevel | reference |
 | 
        
           |  |  | 237 |       | enrol/manual:enrol | Allow      | teacher        | Course       | C1        |
 | 
        
           |  |  | 238 |     And I backup "Course 1" course using this options:
 | 
        
           |  |  | 239 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 240 |     When I restore "test_backup.mbz" backup into a new course using this options:
 | 
        
           |  |  | 241 |       | Settings | Include permission overrides | 1 |
 | 
        
           |  |  | 242 |     Then I am on the "Course 1 copy 1" "permissions" page
 | 
        
           |  |  | 243 |     And I should see "Non-editing teacher (1)"
 | 
        
           |  |  | 244 |     And I set the field "Advanced role override" to "Non-editing teacher (1)"
 | 
        
           |  |  | 245 |     And "enrol/manual:enrol" capability has "Allow" permission
 | 
        
           |  |  | 246 |   | 
        
           |  |  | 247 |   @javascript
 | 
        
           |  |  | 248 |   Scenario: Restore a backup without override permission
 | 
        
           |  |  | 249 |     Given the following "permission overrides" exist:
 | 
        
           |  |  | 250 |       | capability         | permission | role           | contextlevel | reference |
 | 
        
           |  |  | 251 |       | enrol/manual:enrol | Allow      | teacher        | Course       | C1        |
 | 
        
           |  |  | 252 |     And I backup "Course 1" course using this options:
 | 
        
           |  |  | 253 |       | Confirmation | Filename | test_backup.mbz |
 | 
        
           |  |  | 254 |     When I restore "test_backup.mbz" backup into a new course using this options:
 | 
        
           |  |  | 255 |       | Settings | Include permission overrides | 0 |
 | 
        
           |  |  | 256 |     Then I am on the "Course 1 copy 1" "permissions" page
 | 
        
           |  |  | 257 |     And I should see "Non-editing teacher (0)"
 | 
        
           | 1441 | ariadna | 258 |   | 
        
           |  |  | 259 |   @javascript @core_badges
 | 
        
           |  |  | 260 |   Scenario Outline: Restore course badges
 | 
        
           |  |  | 261 |     Given the following "core_badges > Badges" exist:
 | 
        
           |  |  | 262 |       | name                                      | course | description       | image                        | status | type |
 | 
        
           |  |  | 263 |       | Published course badge                    | C1     | Badge description | badges/tests/behat/badge.png | active | 2    |
 | 
        
           |  |  | 264 |       | Unpublished course badge                  | C1     | Badge description | badges/tests/behat/badge.png | 0      | 2    |
 | 
        
           |  |  | 265 |       | Unpublished without criteria course badge | C1     | Badge description | badges/tests/behat/badge.png | 0      | 2    |
 | 
        
           |  |  | 266 |     And the following "core_badges > Criterias" exist:
 | 
        
           |  |  | 267 |       | badge                    | role           |
 | 
        
           |  |  | 268 |       | Published course badge   | editingteacher |
 | 
        
           |  |  | 269 |       | Unpublished course badge | editingteacher |
 | 
        
           |  |  | 270 |     And I backup "Course 1" course using this options:
 | 
        
           |  |  | 271 |       | Initial      | Include badges                   | 1                   |
 | 
        
           |  |  | 272 |       | Initial      | Include activities and resources | <includeactivities> |
 | 
        
           |  |  | 273 |       | Initial      | Include enrolled users           | 0                   |
 | 
        
           |  |  | 274 |       | Initial      | Include blocks                   | 0                   |
 | 
        
           |  |  | 275 |       | Initial      | Include files                    | 0                   |
 | 
        
           |  |  | 276 |       | Initial      | Include filters                  | 0                   |
 | 
        
           |  |  | 277 |       | Initial      | Include calendar events          | 0                   |
 | 
        
           |  |  | 278 |       | Initial      | Include groups and groupings     | 0                   |
 | 
        
           |  |  | 279 |       | Initial      | Include competencies             | 0                   |
 | 
        
           |  |  | 280 |       | Initial      | Include custom fields            | 0                   |
 | 
        
           |  |  | 281 |       | Initial      | Include calendar events          | 0                   |
 | 
        
           |  |  | 282 |       | Initial      | Include content bank content     | 0                   |
 | 
        
           |  |  | 283 |       | Initial      | Include legacy course files      | 0                   |
 | 
        
           |  |  | 284 |       | Confirmation | Filename                         | test_backup.mbz     |
 | 
        
           |  |  | 285 |     When I restore "test_backup.mbz" backup into a new course using this options:
 | 
        
           |  |  | 286 |       | Settings | Include badges | 1 |
 | 
        
           |  |  | 287 |     And I navigate to "Badges" in current page administration
 | 
        
           |  |  | 288 |     Then I should see "Published course badge"
 | 
        
           |  |  | 289 |     And I should see "Unpublished course badge"
 | 
        
           |  |  | 290 |     And I should see "Unpublished without criteria course badge"
 | 
        
           |  |  | 291 |     # If activities were included, the criteria have been restored too; otherwise no criteria have been set up for badges.
 | 
        
           |  |  | 292 |     And ".no-criteria-set" "css_element" <shouldornotexist> in the "Published course badge" "table_row"
 | 
        
           |  |  | 293 |     And ".no-criteria-set" "css_element" <shouldornotexist> in the "Unpublished course badge" "table_row"
 | 
        
           |  |  | 294 |     And ".no-criteria-set" "css_element" should exist in the "Unpublished without criteria course badge" "table_row"
 | 
        
           |  |  | 295 |   | 
        
           |  |  | 296 |     Examples:
 | 
        
           |  |  | 297 |       | includeactivities | shouldornotexist |
 | 
        
           |  |  | 298 |       | 0                 | should exist     |
 | 
        
           |  |  | 299 |       | 1                 | should not exist |
 |