Skip to content

Commit

Permalink
Merge branch 'MDL-66405-master' of git://github.com/aanabit/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Nov 10, 2019
2 parents c9f0abc + ba70ec2 commit a1e0f47
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 6 deletions.
4 changes: 2 additions & 2 deletions filter/displayh5p/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public function filterobject_prepare_replacement_callback($tagbegin, $tagend, $u
$sourceurl .= $urlmodifier;
}

$h5piframesrc = $sourceurl.
'" class="h5p-iframe" style="height:230px; width: 100%; border: 0;" allowfullscreen="allowfullscreen">';
$h5piframesrc = $sourceurl . '" class="h5p-iframe" name="h5pcontent"' .
' style="height:230px; width: 100%; border: 0;" allowfullscreen="allowfullscreen">';

// We want to request the resizing script only once.
if (self::$loadresizerjs) {
Expand Down
81 changes: 81 additions & 0 deletions filter/displayh5p/tests/behat/h5p_filter.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
@editor @filter @filter_displayh5p @core_h5p @_file_upload @_switch_iframe
Feature: Render H5P content using filters
To write rich text - I need to render H5P content.

Background:
Given the following "courses" exist:
| shortname | fullname |
| C1 | Course 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | intro | introformat | course | content | contentformat | idnumber |
| page | PageName1 | PageDesc1 | 1 | C1 | H5Ptest | 1 | 1 |
And the "displayh5p" filter is "on"

@javascript
Scenario: Render an external H5P content URL.
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "PageName1"
And I navigate to "Edit settings" in current page administration
And I set the field "Page content" to "<div>Go for it</div>https://h5p.org/h5p/embed/576651"
When I click on "Save and display" "button"
And I wait until the page is ready
And I switch to "h5p-iframe" class iframe
Then I should see "Lorum ipsum"

@javascript
Scenario: Add an external H5P content URL in a link. Shouldn't be rendered.
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "PageName1"
And I navigate to "Edit settings" in current page administration
And I set the field "Page content" to "<a href='https://h5p.org/h5p/embed/576651'>Go to https://h5p.org/h5p/embed/576651</a>"
When I click on "Save and display" "button"
And I wait until the page is ready
Then ".h5p-iframe" "css_element" should not exist

@javascript
Scenario: Render a server H5P file
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add a "File" to section "1"
And I set the following fields to these values:
| Name | ipsumFile |
And I upload "filter/displayh5p/tests/fixtures/ipsums.h5p" file to "Select files" filemanager
And I press "Save and return to course"
And I follow "PageName1"
And I navigate to "Edit settings" in current page administration
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 click on "Server files" "link" in the ".fp-repo-area" "css_element"
And I click on "ipsumFile (File)" "link"
And I click on "ipsums.h5p" "link"
And I click on "Select this file" "button"
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
And I wait until the page is ready
When I click on "Save and display" "button"
# Switch to iframe created by filter
And I switch to "h5p-iframe" class iframe
# Switch to iframe created by embed.php page
And I switch to "h5p-iframe" class iframe
Then I should see "Lorum ipsum"
And I switch to the main frame
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "PageName1"
# Switch to iframe created by filter
And I switch to "h5p-iframe" class iframe
# Switch to iframe created by embed.php page
And I switch to "h5p-iframe" class iframe
And I should not see "you don't have access"
And I should see "Lorum ipsum"

File renamed without changes.
5 changes: 5 additions & 0 deletions lib/behat/classes/partial_named_selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function __construct() {
'group_message_header' => 'group_message_header',
'group_message' => 'group_message',
'autocomplete' => 'autocomplete',
'iframe' => 'iframe',
);

/**
Expand Down Expand Up @@ -121,6 +122,7 @@ public function __construct() {
'autocomplete_selection' => 'autocomplete_selection',
'autocomplete_suggestions' => 'autocomplete_suggestions',
'autocomplete' => 'autocomplete',
'iframe' => 'iframe',
);

/**
Expand Down Expand Up @@ -229,6 +231,9 @@ public function __construct() {
XPATH
, 'autocomplete' => <<<XPATH
.//descendant::input[@id = //label[contains(normalize-space(string(.)), %locator%)]/@for]/ancestor::*[@data-fieldtype = 'autocomplete']
XPATH
, 'iframe' => <<<XPATH
.//iframe[contains(concat(' ', normalize-space(@class), ' '), %locator% )]
XPATH
);

Expand Down
132 changes: 128 additions & 4 deletions lib/editor/atto/plugins/h5p/tests/behat/h5p.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@editor @editor_atto @atto @atto_h5p @_file_upload @_switch_iframe
@editor @editor_atto @atto @atto_h5p @core_h5p @_file_upload @_switch_iframe
Feature: Add h5ps to Atto
To write rich text - I need to add h5ps.

Expand All @@ -15,6 +15,7 @@ Feature: Add h5ps to Atto
And the following "activities" exist:
| activity | name | intro | introformat | course | content | contentformat | idnumber |
| page | PageName1 | PageDesc1 | 1 | C1 | H5Ptest | 1 | 1 |
And the "displayh5p" filter is "on"

@javascript
Scenario: Insert an embedded h5p
Expand All @@ -33,17 +34,16 @@ Feature: Add h5ps to Atto
@javascript
Scenario: Insert an h5p file
Given I log in as "admin"
And I change window size to "large"
And I follow "Manage private files..."
And I upload "lib/editor/atto/tests/fixtures/ipsums.h5p" file to "Files" filemanager
And I upload "lib/editor/atto/tests/fixtures/guess-the-answer.h5p" file to "Files" filemanager
And I click on "Save changes" "button"
And I am on "Course 1" course homepage
And I follow "PageName1"
And I navigate to "Edit settings" in current page administration
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 click on "Private files" "link" in the ".fp-repo-area" "css_element"
And I click on "ipsums.h5p" "link"
And I click on "guess-the-answer.h5p" "link"
And I click on "Select this file" "button"
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
And I wait until the page is ready
Expand Down Expand Up @@ -98,3 +98,127 @@ Feature: Add h5ps to Atto
When I navigate to "Edit settings" in current page administration
And I click on "Insert H5P" "button"
Then I should not see "H5P file upload" in the "Insert H5P" "dialogue"

@javascript
Scenario: Edit H5P content
Given I log in as "teacher1"
And I follow "Manage private files..."
And I upload "lib/editor/atto/tests/fixtures/drag.h5p" file to "Files" filemanager
And I click on "Save changes" "button"
And I am on "Course 1" course homepage
And I follow "PageName1"
And I navigate to "Edit settings" in current page administration
And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element"
# H5P file content
And I click on "Browse repositories..." "button" in the "Insert H5P" "dialogue"
And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
And I click on "drag" "link"
And I click on "Select this file" "button"
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
And I wait until the page is ready
When I click on "Save and display" "button"
And I switch to "h5pcontent" iframe
And I switch to "h5p-iframe" class iframe
Then I should not see "reveal"
And I should see "Cloudberries"
And I switch to the main frame
And I navigate to "Edit settings" in current page administration
And I click on ".h5p-placeholder" "css_element"
And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element"
# External URL
And I set the field with xpath "//textarea[@data-region='h5purl']" to "https://h5p.org/h5p/embed/576651"
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
And I wait until the page is ready
And I click on "Save and display" "button"
And I switch to "h5pcontent" iframe
And I should see "Lorum ipsum"
And I should not see "Cloudberries"

@javascript
Scenario: Enable/disable H5P options
Given I log in as "teacher1"
And I follow "Manage private files..."
And I upload "lib/editor/atto/tests/fixtures/guess-the-answer.h5p" file to "Files" filemanager
And I click on "Save changes" "button"
And I am on "Course 1" course homepage
And I follow "PageName1"
And I navigate to "Edit settings" in current page administration
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 click on "Private files" "link" in the ".fp-repo-area" "css_element"
And I click on "guess-the-answer.h5p" "link"
And I click on "Select this file" "button"
# No display option button displayed
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
And I wait until the page is ready
When I click on "Save and display" "button"
And I wait until the page is ready
And I switch to "h5pcontent" iframe
And I switch to "h5p-iframe" class iframe
Then I should not see "Reuse"
And I should not see "Embed"
And I should not see "Rights of use"
And I switch to the main frame
And I navigate to "Edit settings" in current page administration
And I click on ".h5p-placeholder" "css_element"
And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element"
And I click on "H5P options" "link"
# Only Allow Download button displayed
And I click on "Allow download" "checkbox"
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
And I wait until the page is ready
And I click on "Save and display" "button"
And I wait until the page is ready
And I switch to "h5pcontent" iframe
And I switch to "h5p-iframe" class iframe
And I should see "Reuse"
And I should not see "Embed"
And I should not see "Rights of use"
And I switch to the main frame
And I navigate to "Edit settings" in current page administration
And I click on ".h5p-placeholder" "css_element"
And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element"
# Embed and copyright buttons displayed. Download not displayed
And I click on "Allow download" "checkbox"
And I click on "Embed button" "checkbox"
And I click on "Copyright button" "checkbox"
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
And I wait until the page is ready
And I click on "Save and display" "button"
And I wait until the page is ready
And I switch to "h5pcontent" iframe
And I switch to "h5p-iframe" class iframe
And I should not see "Reuse"
And I should see "Embed"
And I should see "Rights of use"

@javascript
Scenario: Private H5P files are shown to students
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And I log in as "teacher1"
And I follow "Manage private files..."
And I upload "lib/editor/atto/tests/fixtures/guess-the-answer.h5p" file to "Files" filemanager
And I click on "Save changes" "button"
And I am on "Course 1" course homepage
And I follow "PageName1"
And I navigate to "Edit settings" in current page administration
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 click on "Private files" "link" in the ".fp-repo-area" "css_element"
And I click on "guess-the-answer.h5p" "link"
And I click on "Select this file" "button"
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
And I wait until the page is ready
And I click on "Save and display" "button"
And I log out
When I log in as "student1"
And I am on "Course 1" course homepage
And I follow "PageName1"
Then I switch to "h5pcontent" iframe
And I switch to "h5p-iframe" class iframe
And I should see "reveal"
Binary file added lib/editor/atto/tests/fixtures/drag.h5p
Binary file not shown.
Binary file not shown.
28 changes: 28 additions & 0 deletions lib/tests/behat/behat_general.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,34 @@ function($context, $iframename) {
);
}

/**
* Switches to the iframe containing specified class.
*
* @Given /^I switch to "(?P<iframe_name_string>(?:[^"]|\\")*)" class iframe$/
* @param string $classname
*/
public function switch_to_class_iframe($classname) {
// We spin to give time to the iframe to be loaded.
// Using extended timeout as we don't know about which
// kind of iframe will be loaded.
$this->spin(
function($context, $classname) {
$iframe = $this->find('iframe', $classname);
if (!empty($iframe->getAttribute('id'))) {
$iframename = $iframe->getAttribute('id');
} else {
$iframename = $iframe->getAttribute('name');
}
$context->getSession()->switchToIFrame($iframename);

// If no exception we are done.
return true;
},
$classname,
behat_base::get_extended_timeout()
);
}

/**
* Switches to the main Moodle frame.
*
Expand Down

0 comments on commit a1e0f47

Please sign in to comment.