Skip to content

Commit

Permalink
MDL-76859 h5p: Fix behat failures
Browse files Browse the repository at this point in the history
- Only resize if the H5P EmbedCommunicator is defined (otherwise, it was causing a
JS error)
- An unnecessary image has been removed from the greeting-card.h5p fixture package.
That way, the text will always be displayed (even if the iframe is still not
resized). Instead of replacing the original greeting-card-887.h5p file, I've
renamed it to greeting-card.h5p, to remove these ugly and unnecessary numbers
at the end of the file name).
  • Loading branch information
skodak authored and sarjona committed Apr 12, 2023
1 parent bd2de8e commit 43b56a9
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 36 deletions.
4 changes: 2 additions & 2 deletions contentbank/tests/behat/view_preferences.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Store the content bank view preference
And I log in as "admin"
And I follow "Manage private files..."
And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager
And I upload "h5p/tests/fixtures/greeting-card-887.h5p" file to "Files" filemanager
And I upload "h5p/tests/fixtures/greeting-card.h5p" file to "Files" filemanager
And I click on "Save changes" "button"
And I am on site homepage
And I turn editing mode on
Expand All @@ -35,7 +35,7 @@ Feature: Store the content bank view preference
And I click on "Upload" "link"
And I click on "Choose a file..." "button"
And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
And I click on "greeting-card-887.h5p" "link"
And I click on "greeting-card.h5p" "link"
And I set the field "Save as" to "greetingcard.h5p"
And I click on "Select this file" "button"
And I click on "Save changes" "button"
Expand Down
2 changes: 1 addition & 1 deletion contentbank/tests/contentbank_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function test_create_content_from_file() {
$this->resetAfterTest();
$this->setAdminUser();
$systemcontext = \context_system::instance();
$name = 'greeting-card-887.h5p';
$name = 'greeting-card.h5p';

// Create a dummy H5P file.
$dummyh5p = array(
Expand Down
6 changes: 3 additions & 3 deletions filter/displayh5p/tests/behat/inline_editing_content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Inline editing H5P content anywhere
| student1 | C1 | student |
And the following "contentbank content" exist:
| contextlevel | reference | contenttype | user | contentname | filepath |
| Course | C1 | contenttype_h5p | admin | Greeting card | /h5p/tests/fixtures/greeting-card-887.h5p |
| Course | C1 | contenttype_h5p | admin | Greeting card | /h5p/tests/fixtures/greeting-card.h5p |
And the following "activities" exist:
| activity | name | intro | introformat | course | content | contentformat | idnumber |
| page | PageName1 | PageDesc1 | 1 | C1 | H5Ptest | 1 | 1 |
Expand All @@ -42,7 +42,7 @@ Feature: Inline editing H5P content anywhere
And I log in as "teacher1"
# Upload the H5P to private user files.
And I follow "Manage private files..."
And I upload "h5p/tests/fixtures/greeting-card-887.h5p" file to "Files" filemanager
And I upload "h5p/tests/fixtures/greeting-card.h5p" file to "Files" filemanager
And I click on "Save changes" "button"
# Add H5P content to the page.
And I am on "Course 1" course homepage
Expand All @@ -51,7 +51,7 @@ Feature: Inline editing H5P content anywhere
And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element"
And I click on "Browse repositories..." "button" in the "Insert H5P" "dialogue"
And I select "Private files" repository in file picker
And I click on "greeting-card-887.h5p" "file" in repository content area
And I click on "greeting-card.h5p" "file" in repository content area
And I click on "Link to the file" "radio"
And I click on "Select this file" "button"
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
Expand Down
8 changes: 5 additions & 3 deletions h5p/templates/h5perror.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
</div>
{{#js}}
(function() {
H5PEmbedCommunicator.send('resize', {
scrollHeight: document.body.scrollHeight
});
if (typeof H5PEmbedCommunicator !== 'undefined') {
H5PEmbedCommunicator.send('resize', {
scrollHeight: document.body.scrollHeight
});
}
})();
{{/js}}
14 changes: 7 additions & 7 deletions h5p/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function test_get_original_content_from_pluginfile_url(): void {
$syscontext = \context_system::instance();

// Create the original file.
$filename = 'greeting-card-887.h5p';
$filename = 'greeting-card.h5p';
$path = __DIR__ . '/fixtures/' . $filename;
$originalfile = helper::create_fake_stored_file_from_path($path);
$originalfilerecord = [
Expand Down Expand Up @@ -491,7 +491,7 @@ public function test_can_edit_content(string $currentuser, string $fileauthor, s
}

// Create the file.
$filename = 'greeting-card-887.h5p';
$filename = 'greeting-card.h5p';
$path = __DIR__ . '/fixtures/' . $filename;
if ($filecomponent === 'contentbank') {
$generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank');
Expand Down Expand Up @@ -1197,33 +1197,33 @@ public function test_is_valid_package(string $filename, bool $expected, bool $is
public function is_valid_package_provider(): array {
return [
'Valid H5P file (as admin)' => [
'filename' => '/fixtures/greeting-card-887.h5p',
'filename' => '/fixtures/greeting-card.h5p',
'expected' => true,
'isadmin' => true,
],
'Valid H5P file (as user) without library update and checking content' => [
'filename' => '/fixtures/greeting-card-887.h5p',
'filename' => '/fixtures/greeting-card.h5p',
'expected' => false, // Libraries are missing and user hasn't the right permissions to upload them.
'isadmin' => false,
'onlyupdatelibs' => false,
'skipcontent' => false,
],
'Valid H5P file (as user) with library update and checking content' => [
'filename' => '/fixtures/greeting-card-887.h5p',
'filename' => '/fixtures/greeting-card.h5p',
'expected' => false, // Libraries are missing and user hasn't the right permissions to upload them.
'isadmin' => false,
'onlyupdatelibs' => true,
'skipcontent' => false,
],
'Valid H5P file (as user) without library update and skipping content' => [
'filename' => '/fixtures/greeting-card-887.h5p',
'filename' => '/fixtures/greeting-card.h5p',
'expected' => true, // Content check is skipped so the package will be considered valid.
'isadmin' => false,
'onlyupdatelibs' => false,
'skipcontent' => true,
],
'Valid H5P file (as user) with library update and skipping content' => [
'filename' => '/fixtures/greeting-card-887.h5p',
'filename' => '/fixtures/greeting-card.h5p',
'expected' => true, // Content check is skipped so the package will be considered valid.
'isadmin' => false,
'onlyupdatelibs' => true,
Expand Down
2 changes: 1 addition & 1 deletion h5p/tests/file_storage_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public function get_icon_url_provider(): array {
true,
],
'Icon not included' => [
'greeting-card-887.h5p',
'greeting-card.h5p',
false,
],
];
Expand Down
Binary file removed h5p/tests/fixtures/greeting-card-887.h5p
Binary file not shown.
Binary file added h5p/tests/fixtures/greeting-card.h5p
Binary file not shown.
8 changes: 4 additions & 4 deletions h5p/tests/helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function test_save_h5p_missing_libraries(): void {
$this->setUser($user);

// This is a valid .H5P file.
$path = __DIR__ . '/fixtures/greeting-card-887.h5p';
$path = __DIR__ . '/fixtures/greeting-card.h5p';
$file = helper::create_fake_stored_file_from_path($path, (int)$user->id);
$factory->get_framework()->set_file($file);

Expand Down Expand Up @@ -173,7 +173,7 @@ public function test_save_h5p_existing_libraries(): void {
$this->setUser($user);

// This is a valid .H5P file.
$path = __DIR__ . '/fixtures/greeting-card-887.h5p';
$path = __DIR__ . '/fixtures/greeting-card.h5p';
$file = helper::create_fake_stored_file_from_path($path, (int)$user->id);
$factory->get_framework()->set_file($file);

Expand Down Expand Up @@ -247,7 +247,7 @@ public function test_can_deploy_package(): void {
$admin = get_admin();

// Prepare a valid .H5P file.
$path = __DIR__ . '/fixtures/greeting-card-887.h5p';
$path = __DIR__ . '/fixtures/greeting-card.h5p';

// Files created by users can't be deployed.
$file = helper::create_fake_stored_file_from_path($path, (int)$user->id);
Expand Down Expand Up @@ -275,7 +275,7 @@ public function test_can_update_library(): void {
$admin = get_admin();

// Prepare a valid .H5P file.
$path = __DIR__ . '/fixtures/greeting-card-887.h5p';
$path = __DIR__ . '/fixtures/greeting-card.h5p';

// Libraries can't be updated when the file has been created by users.
$file = helper::create_fake_stored_file_from_path($path, (int)$user->id);
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/event/contentbank_content_uploaded_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function test_content_created() {
'filepath' => '/',
'filename' => 'dummy_h5p.h5p'
);
$path = $CFG->dirroot . '/h5p/tests/fixtures/greeting-card-887.h5p';
$path = $CFG->dirroot . '/h5p/tests/fixtures/greeting-card.h5p';
$dummyh5pfile = \core_h5p\helper::create_fake_stored_file_from_path($path);

// Trigger and capture the event when creating content from a file.
Expand Down
6 changes: 3 additions & 3 deletions lib/tests/h5p_clean_orphaned_records_task_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public function test_task_execution(): void {
$course = $this->getDataGenerator()->create_course();
$params = [
'course' => $course->id,
'packagefilepath' => $CFG->dirroot.'/h5p/tests/fixtures/greeting-card-887.h5p',
'packagefilepath' => $CFG->dirroot.'/h5p/tests/fixtures/greeting-card.h5p',
'introformat' => 1
];

// Create h5pactivity.
$activity = $this->getDataGenerator()->create_module('h5pactivity', $params);
$activity->filename = 'greeting-card-887.h5p';
$activity->filename = 'greeting-card.h5p';
$context = context_module::instance($activity->cmid);

// Create a fake deploy H5P file.
Expand All @@ -70,7 +70,7 @@ public function test_task_execution(): void {
AND filearea = 'content'
AND component = 'core_h5p'";
$orphanedfiles = $DB->get_records_sql($orphanedfilessql, ['h5pid' => $h5pid]);
$this->assertEquals(3, count($orphanedfiles));
$this->assertEquals(2, count($orphanedfiles));

// Execute task.
$task = new \core\task\h5p_clean_orphaned_records_task();
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/tests/behat/h5p_inline_editing_content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Inline editing H5P content in mod_forum
| student1 | C1 | student |
And the following "contentbank content" exist:
| contextlevel | reference | contenttype | user | contentname | filepath |
| Course | C1 | contenttype_h5p | admin | Greeting card | /h5p/tests/fixtures/greeting-card-887.h5p |
| Course | C1 | contenttype_h5p | admin | Greeting card | /h5p/tests/fixtures/greeting-card.h5p |
And the following "activities" exist:
| activity | name | intro | introformat | course | content | contentformat | idnumber |
| forum | ForumName1 | PageDesc1 | 1 | C1 | H5Ptest | 1 | 1 |
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/tests/h5p/canedit_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function test_can_edit_content(string $currentuser, string $fileauthor, s
}

// Create the file.
$filename = 'greeting-card-887.h5p';
$filename = 'greeting-card.h5p';
$path = __DIR__ . '/../../../../h5p/tests/fixtures/' . $filename;
if ($filecomponent === 'contentbank') {
$generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank');
Expand Down
8 changes: 4 additions & 4 deletions mod/h5pactivity/tests/behat/inline_editing_content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Feature: Inline editing H5P content
Scenario: Add H5P activity using link to content bank file
Given the following "contentbank content" exist:
| contextlevel | reference | contenttype | user | contentname | filepath |
| Course | C1 | contenttype_h5p | teacher1 | Greeting card | /h5p/tests/fixtures/greeting-card-887.h5p |
| Course | C1 | contenttype_h5p | teacher1 | Greeting card | /h5p/tests/fixtures/greeting-card.h5p |
And I log in as "admin"
# Add the navigation block.
And I am on "Course 1" course homepage with editing mode on
Expand Down Expand Up @@ -91,7 +91,7 @@ Feature: Inline editing H5P content
Scenario: Add H5P activity using copy to content bank file
Given the following "contentbank content" exist:
| contextlevel | reference | contenttype | user | contentname | filepath |
| Course | C1 | contenttype_h5p | admin | Greeting card | /h5p/tests/fixtures/greeting-card-887.h5p |
| Course | C1 | contenttype_h5p | admin | Greeting card | /h5p/tests/fixtures/greeting-card.h5p |
And I log in as "admin"
# Add the navigation block.
And I am on "Course 1" course homepage with editing mode on
Expand Down Expand Up @@ -154,7 +154,7 @@ Feature: Inline editing H5P content
Given I log in as "teacher1"
# Upload the H5P to private user files.
And I follow "Manage private files..."
And I upload "h5p/tests/fixtures/greeting-card-887.h5p" file to "Files" filemanager
And I upload "h5p/tests/fixtures/greeting-card.h5p" file to "Files" filemanager
And I click on "Save changes" "button"
# Create an H5P activity with a private user file.
And I am on "Course 1" course homepage with editing mode on
Expand All @@ -164,7 +164,7 @@ Feature: Inline editing H5P content
| Description | Description |
And I click on "Add..." "button" in the "Package file" "form_row"
And I select "Private files" repository in file picker
And I click on "greeting-card-887.h5p" "file" in repository content area
And I click on "greeting-card.h5p" "file" in repository content area
And I click on "Link to the file" "radio"
And I click on "Select this file" "button"
And I click on "Save and display" "button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public function test_get_h5pactivities_by_courses() {

$params = [
'course' => $course1->id,
'packagefilepath' => $CFG->dirroot.'/h5p/tests/fixtures/greeting-card-887.h5p',
'packagefilepath' => $CFG->dirroot.'/h5p/tests/fixtures/greeting-card.h5p',
'introformat' => 1
];
$activities[] = $this->getDataGenerator()->create_module('h5pactivity', $params);
// Add filename and contextid to make easier the asserts.
$activities[1]->filename = 'greeting-card-887.h5p';
$activities[1]->filename = 'greeting-card.h5p';
$context = context_module::instance($activities[1]->cmid);
$activities[1]->contextid = $context->id;

Expand Down
2 changes: 1 addition & 1 deletion repository/contentbank/tests/behat/search_content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Feature: Search content bank files using the content bank files repository
| Course | C2 | contenttype_h5p | admin | coursecontent2.h5p | /h5p/tests/fixtures/find-the-words.h5p |
| Category | CAT1 | contenttype_h5p | admin | categorycontent1.h5p | /h5p/tests/fixtures/ipsums.h5p |
| Category | CAT2 | contenttype_h5p | admin | categorycontent2.h5p | /h5p/tests/fixtures/multiple-choice-2-6.h5p |
| System | | contenttype_h5p | admin | systemcontent.h5p | /h5p/tests/fixtures/greeting-card-887.h5p |
| System | | contenttype_h5p | admin | systemcontent.h5p | /h5p/tests/fixtures/greeting-card.h5p |
And the following "activities" exist:
| activity | name | intro | introformat | course | idnumber |
| folder | Folder | FolderDesc | 1 | C1 | folder |
Expand Down
4 changes: 2 additions & 2 deletions repository/contentbank/tests/behat/select_content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Feature: Select content bank files using the content bank files repository
| contextlevel | reference | contenttype | user | contentname | filepath |
| Course | mscC1 | contenttype_h5p | admin | filltheblanks.h5p | /h5p/tests/fixtures/filltheblanks.h5p |
| Course | mscC2 | contenttype_h5p | admin | find-the-words.h5p | /h5p/tests/fixtures/find-the-words.h5p |
| Course | subcat1C1 | contenttype_h5p | admin | greeting-card-887.h5p | /h5p/tests/fixtures/greeting-card-887.h5p |
| Course | subcat1C1 | contenttype_h5p | admin | greeting-card.h5p | /h5p/tests/fixtures/greeting-card.h5p |
| Category | CAT1 | contenttype_h5p | admin | ipsums.h5p | /h5p/tests/fixtures/ipsums.h5p |
| Category | SUBCAT1 | contenttype_h5p | admin | multiple-choice-2-6.h5p | /h5p/tests/fixtures/multiple-choice-2-6.h5p |
| System | | contenttype_h5p | admin | filltheblanks.h5p | /h5p/tests/fixtures/filltheblanks.h5p |
Expand Down Expand Up @@ -76,7 +76,7 @@ Feature: Select content bank files using the content bank files repository
And I click on "SubCategory1Course1" "folder" in repository content area
And I should see "System > Category1 > SubCategory1 > SubCategory1Course1" breadcrumb navigation in repository
And I should see "1" elements in repository content area
And I should see "greeting-card-887.h5p" "file" in repository content area
And I should see "greeting-card.h5p" "file" in repository content area

Scenario: Admin can select and re-use content bank files using the content bank repository
Given I am on the Folder "Folder activity" page logged in as admin
Expand Down

0 comments on commit 43b56a9

Please sign in to comment.