From 66489aea0f834da3da51287ddd4e9c2dcdcf3e32 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Mon, 27 Apr 2020 12:41:06 +0200 Subject: [PATCH] MDL-68314 core_contentbank: Backup and restore tests --- backup/moodle2/tests/moodle2_test.php | 28 ++++++++++++ .../behat/import_contentbank_content.feature | 45 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 backup/util/ui/tests/behat/import_contentbank_content.feature diff --git a/backup/moodle2/tests/moodle2_test.php b/backup/moodle2/tests/moodle2_test.php index 6649934af94..b4fed991b69 100644 --- a/backup/moodle2/tests/moodle2_test.php +++ b/backup/moodle2/tests/moodle2_test.php @@ -1063,4 +1063,32 @@ class core_backup_moodle2_testcase extends advanced_testcase { } } } + + /** + * Test the content bank content through a backup and restore. + */ + public function test_contentbank_content_backup() { + global $DB, $USER, $CFG; + $this->resetAfterTest(); + + $this->setAdminUser(); + $generator = $this->getDataGenerator(); + $cbgenerator = $this->getDataGenerator()->get_plugin_generator('core_contentbank'); + + // Create course and add content bank content. + $course = $generator->create_course(); + $context = context_course::instance($course->id); + $filepath = $CFG->dirroot . '/h5p/tests/fixtures/filltheblanks.h5p'; + $contents = $cbgenerator->generate_contentbank_data('contenttype_h5p', 2, $USER->id, $context, true, $filepath); + $this->assertEquals(2, $DB->count_records('contentbank_content')); + + // Do backup and restore. + $newcourseid = $this->backup_and_restore($course); + + // Confirm that values were transferred correctly into content bank on new course. + $newcontext = context_course::instance($newcourseid); + + $this->assertEquals(4, $DB->count_records('contentbank_content')); + $this->assertEquals(2, $DB->count_records('contentbank_content', ['contextid' => $newcontext->id])); + } } diff --git a/backup/util/ui/tests/behat/import_contentbank_content.feature b/backup/util/ui/tests/behat/import_contentbank_content.feature new file mode 100644 index 00000000000..68f2fb39052 --- /dev/null +++ b/backup/util/ui/tests/behat/import_contentbank_content.feature @@ -0,0 +1,45 @@ +@core @core_backup @core_contentbank +Feature: Import course content bank content + In order to import content from a course contentbank + As a teacher + I need to confirm that errors will not happen + + Background: + Given the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + | Course 2 | C2 | 0 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | teacher1 | C2 | editingteacher | + And the following "contentbank content" exist: + | course| contenttype | user | contentname | + | C1 | contenttype_h5p | teacher1 | ipsums.h5p | + And I log in as "teacher1" + + Scenario: Import content bank content to another course + Given I am on "Course 2" course homepage + And I click on "Content bank" "link" + And I should not see "ipsums.h5p" + When I import "Course 1" course into "Course 2" course using this options: + And I click on "Content bank" "link" + Then I should see "ipsums.h5p" + And I am on "Course 1" course homepage + And I click on "Content bank" "link" + And I should see "ipsums.h5p" + + Scenario: User could configure not to import content bank + Given I am on "Course 2" course homepage + And I click on "Content bank" "link" + And I should not see "ipsums.h5p" + When I import "Course 1" course into "Course 2" course using this options: + | Initial | Include content bank content | 0 | + And I click on "Content bank" "link" + Then I should not see "ipsums.h5p" + And I am on "Course 1" course homepage + And I click on "Content bank" "link" + And I should see "ipsums.h5p"