-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-67786 core_contentbank: Unit and behat tests
- Loading branch information
Amaia Anabitarte
committed
Apr 15, 2020
1 parent
7081907
commit bd4e0a7
Showing
9 changed files
with
759 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
contentbank/contenttype/h5p/tests/behat/admin_upload_content.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
@core @core_contentbank @contenttype_h5p @_file_upload @_switch_iframe @javascript | ||
Feature: H5P file upload to content bank for admins | ||
In order import new H5P content to content bank | ||
As an admin | ||
I need to be able to upload a new .h5p file to content bank | ||
|
||
Background: | ||
Given 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 click on "Save changes" "button" | ||
And I press "Customise this page" | ||
And I add the "Navigation" block if not present | ||
And I expand "Site pages" node | ||
And I click on "Content bank" "link" | ||
|
||
Scenario: Admins can upload .h5p extension files to content bank | ||
Given I should not see "filltheblanks.h5p" | ||
When 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 "filltheblanks.h5p" "link" | ||
And I click on "Select this file" "button" | ||
And I click on "Save changes" "button" | ||
And I wait until the page is ready | ||
Then I should see "filltheblanks.h5p" | ||
|
||
Scenario: Admins can see uploaded H5P contents | ||
Given I should not see "filltheblanks.h5p" | ||
When 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 "filltheblanks.h5p" "link" | ||
And I click on "Select this file" "button" | ||
And I click on "Save changes" "button" | ||
And I wait until the page is ready | ||
And I click on "filltheblanks.h5p" "link" | ||
And I switch to "h5p-player" class iframe | ||
And I switch to "h5p-iframe" class iframe | ||
Then I should see "Of which countries" | ||
|
||
Scenario: Users can't see content managed by disabled plugins | ||
Given 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 "filltheblanks.h5p" "link" | ||
And I click on "Select this file" "button" | ||
And I click on "Save changes" "button" | ||
And I wait until the page is ready | ||
And I should see "filltheblanks.h5p" | ||
And I navigate to "Plugins > Content bank > Manage content bank content types" in site administration | ||
And I click on "Disable" "icon" in the "H5P" "table_row" | ||
And I wait until the page is ready | ||
When I click on "Content bank" "link" | ||
Then I should not see "filltheblanks.h5p" | ||
|
||
Scenario: Contents in a context are not available from other contexts | ||
Given the following "courses" exist: | ||
| fullname | shortname | category | | ||
| Course 1 | C1 | 0 | | ||
When 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 "filltheblanks.h5p" "link" | ||
And I click on "Select this file" "button" | ||
And I click on "Save changes" "button" | ||
And I wait until the page is ready | ||
Then I should see "filltheblanks.h5p" | ||
And I am on "Course 1" course homepage | ||
And I add the "Navigation" block if not present | ||
And I expand "Site pages" node | ||
And I click on "Content bank" "link" | ||
And I should not see "filltheblanks.h5p" |
73 changes: 73 additions & 0 deletions
73
contentbank/contenttype/h5p/tests/behat/teacher_upload_content.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
@core @core_contentbank @contenttype_h5p @_file_upload @_switch_iframe @javascript | ||
Feature: H5P file upload to content bank for non admins | ||
In order import new H5P content to content bank | ||
As an admin | ||
I need to be able to upload a new .h5p file to content bank | ||
|
||
Background: | ||
Given the following "users" exist: | ||
| username | firstname | lastname | email | | ||
| teacher1 | Teacher | 1 | teacher1@example.com | | ||
| teacher2 | Teacher | 2 | teacher2@example.com | | ||
And the following "categories" exist: | ||
| name | category | idnumber | | ||
| Cat 1 | 0 | CAT1 | | ||
And the following "courses" exist: | ||
| fullname | shortname | category | | ||
| Course 1 | C1 | CAT1 | | ||
And the following "course enrolments" exist: | ||
| user | course | role | | ||
| teacher1 | C1 | editingteacher | | ||
| teacher2 | C1 | editingteacher | | ||
And I log in as "teacher1" | ||
And I follow "Manage private files..." | ||
And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager | ||
And I click on "Save changes" "button" | ||
|
||
Scenario: Teachers can not access system level content bank | ||
Given I press "Customise this page" | ||
And I add the "Navigation" block if not present | ||
When I expand "Site pages" node | ||
Then I should not see "Content bank" | ||
|
||
Scenario: Teachers can access course level content bank | ||
Given I am on "Course 1" course homepage with editing mode on | ||
And I add the "Navigation" block if not present | ||
When I expand "Site pages" node | ||
Then I should see "Content bank" | ||
|
||
Scenario: Teachers can upload .h5p extension files to course content bank | ||
Given I am on "Course 1" course homepage with editing mode on | ||
And I add the "Navigation" block if not present | ||
When I expand "Site pages" node | ||
And I click on "Content bank" "link" | ||
Then I should not see "filltheblanks.h5p" | ||
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 "filltheblanks.h5p" "link" | ||
And I click on "Select this file" "button" | ||
And I click on "Save changes" "button" | ||
And I wait until the page is ready | ||
And I should see "filltheblanks.h5p" | ||
|
||
Scenario: Other teachers can see uploaded H5P contents | ||
Given I am on "Course 1" course homepage with editing mode on | ||
And I add the "Navigation" block if not present | ||
When I expand "Site pages" node | ||
And I click on "Content bank" "link" | ||
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 "filltheblanks.h5p" "link" | ||
And I click on "Select this file" "button" | ||
And I click on "Save changes" "button" | ||
And I wait until the page is ready | ||
And I should see "filltheblanks.h5p" | ||
And I log out | ||
When I log in as "teacher2" | ||
And I am on "Course 1" course homepage with editing mode on | ||
And I add the "Navigation" block if not present | ||
And I expand "Site pages" node | ||
And I click on "Content bank" "link" | ||
Then I should see "filltheblanks.h5p" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Test for H5P content bank plugin. | ||
* | ||
* @package contenttype_h5p | ||
* @category test | ||
* @copyright 2020 Amaia Anabitarte <amaia@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
/** | ||
* Test for H5P content bank plugin. | ||
* | ||
* @package contenttype_h5p | ||
* @category test | ||
* @copyright 2020 Amaia Anabitarte <amaia@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @coversDefaultClass \contenttype_h5p\content | ||
*/ | ||
class contenttype_h5p_content_plugin_testcase extends advanced_testcase { | ||
|
||
/** | ||
* Tests for uploaded file. | ||
* | ||
* @covers ::get_file | ||
*/ | ||
public function test_upload_file() { | ||
$this->resetAfterTest(); | ||
|
||
// Create content. | ||
$record = new stdClass(); | ||
$record->name = 'Test content'; | ||
$record->configdata = ''; | ||
$contenttype = new \contenttype_h5p\contenttype(context_system::instance()); | ||
$content = $contenttype->create_content($record); | ||
|
||
// Create a dummy file. | ||
$filename = 'content.h5p'; | ||
$dummy = array( | ||
'contextid' => \context_system::instance()->id, | ||
'component' => 'contentbank', | ||
'filearea' => 'public', | ||
'itemid' => $content->get_id(), | ||
'filepath' => '/', | ||
'filename' => $filename | ||
); | ||
$fs = get_file_storage(); | ||
$fs->create_file_from_string($dummy, 'dummy content'); | ||
|
||
$file = $content->get_file(); | ||
$this->assertInstanceOf(\stored_file::class, $file); | ||
$this->assertEquals($filename, $file->get_filename()); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
contentbank/contenttype/h5p/tests/contenttype_h5p_test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Test for H5P content bank plugin. | ||
* | ||
* @package contenttype_h5p | ||
* @category test | ||
* @copyright 2020 Amaia Anabitarte <amaia@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
/** | ||
* Test for H5P content bank plugin. | ||
* | ||
* @package contenttype_h5p | ||
* @category test | ||
* @copyright 2020 Amaia Anabitarte <amaia@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @coversDefaultClass \contenttype_h5p\contenttype | ||
*/ | ||
class contenttype_h5p_contenttype_plugin_testcase extends advanced_testcase { | ||
|
||
/** | ||
* Tests can_upload behavior. | ||
* | ||
* @covers ::can_upload | ||
*/ | ||
public function test_can_upload() { | ||
$this->resetAfterTest(); | ||
|
||
$systemcontext = \context_system::instance(); | ||
$systemtype = new \contenttype_h5p\contenttype($systemcontext); | ||
|
||
// Admins can upload. | ||
$this->setAdminUser(); | ||
$this->assertTrue($systemtype->can_upload()); | ||
|
||
// Teacher can upload in the course but not at system level. | ||
$course = $this->getDataGenerator()->create_course(); | ||
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher'); | ||
$coursecontext = \context_course::instance($course->id); | ||
$coursetype = new \contenttype_h5p\contenttype($coursecontext); | ||
$this->setUser($teacher); | ||
$this->assertTrue($coursetype->can_upload()); | ||
$this->assertFalse($systemtype->can_upload()); | ||
|
||
// Users can't upload. | ||
$user = $this->getDataGenerator()->create_user(); | ||
$this->setUser($user); | ||
$this->assertFalse($coursetype->can_upload()); | ||
$this->assertFalse($systemtype->can_upload()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@core @core_contentbank | ||
Feature: Access permission to content Bank | ||
In order to control access to content bank | ||
As an admin | ||
I need to be able to configure users' permissions | ||
|
||
Background: | ||
Given the following "users" exist: | ||
| username | firstname | lastname | email | | ||
| teacher1 | Teacher | 1 | user1@example.com | | ||
And the following "courses" exist: | ||
| fullname | shortname | category | | ||
| Course 1 | C1 | 0 | | ||
And the following "course enrolments" exist: | ||
| user | course | role | | ||
| teacher1 | C1 | editingteacher | | ||
|
||
Scenario: Admins access content bank | ||
Given I log in as "admin" | ||
Then "Content bank" "link" should exist | ||
|
||
Scenario: Editing teachers can access content bank at course level | ||
Given I log in as "teacher1" | ||
And I am on "Course 1" course homepage with editing mode on | ||
Then "Content bank" "link" should exist | ||
|
||
Scenario: Editing teachers can't access content bank at system level | ||
Given I log in as "teacher1" | ||
Then "Content bank" "link" should not exist |
Oops, something went wrong.