Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 82 additions & 31 deletions tests/behat/behat_filter_ally.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,24 @@ protected function get_current_course() {
}

/**
* @Given /^I create a label with fixture images "(?P<images_string>[^"]*)"$/
* @param string $images (csv)
* Add a set of fixture images to the text of a component.
* @param $text
* @param array $images
* @param $component
* @param $filearea
* @param $contextid
* @return string
* @throws coding_exception
* @throws file_exception
* @throws stored_file_creation_exception
*/
public function i_create_label_with_sample_images($images) {
global $CFG, $DB;

$gen = testing_util::get_data_generator();
private function add_fixture_images_to_text($text, array $images, $component, $filearea, $contextid) {
global $CFG;

$fixturedir = $CFG->dirroot.'/filter/ally/tests/fixtures/';
$images = explode(',', $images);

$labeltext = '<h2>A test label</h2>';

$voidtype = '/>';

$course = $this->get_current_course();

$data = (object) [
'course' => $course->id,
'name' => 'test label',
'intro' => 'pre file inserts',
'introformat' => FORMAT_HTML
];

$label = $gen->create_module('label', $data);

$i = 0;
$voidtype = '>';
foreach ($images as $image) {
$image = trim($image);
$i ++;
Expand All @@ -139,16 +130,42 @@ public function i_create_label_with_sample_images($images) {
}

// Add actual file there.
$filerecord = ['component' => 'mod_label', 'filearea' => 'intro',
'contextid' => context_module::instance($label->cmid)->id, 'itemid' => 0,
$filerecord = ['component' => $component, 'filearea' => $filearea,
'contextid' => $contextid, 'itemid' => 0,
'filename' => $image, 'filepath' => '/'];
$fs = get_file_storage();
$fs->create_file_from_pathname($filerecord, $fixturepath);
$path = '@@PLUGINFILE@@/' . $image;
$labeltext .= 'Some text before the image';
$labeltext .= '<img src="' . $path . '" alt="test file ' . $i . '" ' . $voidtype;
$labeltext .= 'Some text after the image';
$text .= 'Some text before the image';
$text .= '<img src="' . $path . '" alt="test file ' . $i . '" ' . $voidtype;
$text .= 'Some text after the image';
}
return $text;
}

/**
* @Given /^I create a label with fixture images "(?P<images_string>[^"]*)"$/
* @param string $images (csv)
*/
public function i_create_label_with_sample_images($images) {
global $DB;

$gen = testing_util::get_data_generator();
$images = explode(',', $images);
$labeltext = '<h2>A test label</h2>';

$course = $this->get_current_course();

$data = (object) [
'course' => $course->id,
'name' => 'test label',
'intro' => 'pre file inserts',
'introformat' => FORMAT_HTML
];

$label = $gen->create_module('label', $data);
$contextid = context_module::instance($label->cmid)->id;
$labeltext = $this->add_fixture_images_to_text($labeltext, $images, 'mod_label', 'intro', $contextid);

$label = $DB->get_record('label', ['id' => $label->id]);
$label->intro = $labeltext;
Expand Down Expand Up @@ -260,11 +277,14 @@ protected function get_block_manager($regions, $context, $pagetype = 'page-type'
}

/**
* @Given I add a html block with title :title and content :content
* @param string $title
* @param string $content
* @param $title
* @param $content
* @throws ExpectationException
* @throws coding_exception
* @throws dml_exception
* @return stdClass
*/
public function i_add_a_html_block_with_content($title, $content) {
private function add_html_block($title, $content) {
global $DB;
// Note - we are not going to use behat_blocks::i_add_the_block because we don't want to test
// fhe block UI, we just want to add a block!
Expand All @@ -287,6 +307,37 @@ public function i_add_a_html_block_with_content($title, $content) {
];
$block->configdata = base64_encode(serialize($blockconfig));
$DB->update_record('block_instances', $block);
return $block;
}

/**
* @Given I add a html block with title :title and content :content
* @param string $title
* @param string $content
*/
public function i_add_a_html_block_with_content($title, $content) {
$this->add_html_block($title, $content);
}

/**
* @Given I add a html block with title ":title" with fixture images ":images"
* @param string $title
* @param string $content
*/
public function i_add_a_html_block_with_fixture_images($title, $images) {
global $DB;

$block = $this->add_html_block($title, '');
$images = explode(',', $images);

$blockconfig = unserialize(base64_decode($block->configdata));
$blocktext = $blockconfig->text;
$contextid = context_block::instance($block->id)->id;
$blocktext = $this->add_fixture_images_to_text($blocktext, $images, 'block_html', 'content', $contextid);

$blockconfig->text = $blocktext;
$block->configdata = base64_encode(serialize($blockconfig));
$DB->update_record('block_instances', $block);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/behat/block_html_annotation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Feature: When the ally filter is enabled ally annotations are inserted when appr
And html block with title "Some block" is annotated

Examples:
| theme |
| clean |
| boost |
| theme |
| classic |
| boost |
# Note - we could test for snap here too but if we did that it'd break the tests on non standard moodle installs.
70 changes: 70 additions & 0 deletions tests/behat/block_html_files.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 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/>.
#
# Tests for Ally filter block_hmtl annotations.
#
# @package filter_ally
# @author Guy Thomas
# @copyright Copyright (c) 2019 Blackboard Inc.
# @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later


@filter @filter_ally
Feature: When the ally filter is enabled files inside blockhtml are wrapped and have place hodlers for ally icons.

Background:
Given the ally filter is enabled
And the following "courses" exist:
| fullname | shortname | category | format |
| Course 1 | C1 | 0 | topics |
And the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | teacher |

@javascript
Scenario Outline: Block html is wrapped and has appropriate placeholders.
Given the following config values are set as admin:
| theme | <theme> |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I add a html block with title "Some block" with fixture images "bpd_bikes_640px.jpg, testgif_small.gif, testpng_small.png"
When I reload the page
And I wait until the page is ready
Then I should see the feedback place holder for the "1st" image
And I should see the feedback place holder for the "2nd" image
And I should see the feedback place holder for the "3rd" image
And the ally image cover area should exist for the "1st" image
And the ally image cover area should exist for the "2nd" image
And the ally image cover area should exist for the "3rd" image
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
Then I should not see the feedback place holder for the "1st" image
And I should not see the feedback place holder for the "2nd" image
And I should not see the feedback place holder for the "3rd" image
And the ally image cover area should exist for the "1st" image
And the ally image cover area should exist for the "2nd" image
And the ally image cover area should exist for the "3rd" image

Examples:
| theme |
| boost |
| classic |
# Note - we could test for snap here too but if we did that it'd break the tests on non standard moodle installs.