first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,102 @@
<?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/>.
namespace tool_brickfield;
use tool_brickfield\local\tool\filter;
/**
* Unit tests for {@accessibility tool_brickfield\accessibility.php}.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Jay Churchward (jay@brickfieldlabs.ie)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class accessibility_test extends \advanced_testcase {
/**
* Test get_title().
*
* @throws \coding_exception
* @throws \dml_exception
* @throws \moodle_exception
*/
public function test_get_title(): void {
$this->resetAfterTest();
$object = new accessibility();
$filter = new filter();
// Testing the else statement.
$output = $object->get_title($filter, 0);
$this->assertEquals($output, 'Error details: all reviewed courses (0 courses)');
$output = $object->get_title($filter, 5);
$this->assertEquals($output, 'Error details: all reviewed courses (5 courses)');
// Testing the if statement.
$filter->courseid = 1;
$output = $object->get_title($filter, 0);
$this->assertEquals($output, 'Error details: course PHPUnit test site');
}
/**
* Test check_ids().
*
* @throws \dml_exception
*/
public function test_check_ids(): void {
$this->resetAfterTest();
$object = new accessibility();
$output = $object->checkids();
$this->assertEquals($output[1], 'a_links_dont_open_new_window');
$this->assertEquals($output[10], 'css_text_has_contrast');
$output = $object->checkids(2);
$this->assertEmpty($output);
}
/**
* Test get_translations().
*
* @throws \dml_exception
*/
public function test_get_translations(): void {
$this->resetAfterTest();
$object = new accessibility();
$output = $object->get_translations();
$this->assertEquals($output['a_must_contain_text']['title'], 'Links should contain text');
$this->assertStringContainsString('<p>Because many users of screen readers use links to ' .
'navigate the page, providing links with no text (or with images that have empty \'alt\' attributes and no other ' .
'readable text) hinders these users.</p>', $output['a_must_contain_text']['description']);
}
/**
* Test get_category_courseids().
*
* @throws \dml_exception
*/
public function test_get_category_courseids(): void {
$this->resetAfterTest();
$object = new accessibility();
$category = $this->getDataGenerator()->create_category();
$course = $this->getDataGenerator()->create_course((object)['category' => $category->id]);
$output = $object->get_category_courseids($category->id);
$this->assertEquals($output[0], $course->id);
}
}
+244
View File
@@ -0,0 +1,244 @@
<?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/>.
namespace tool_brickfield;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/admin/tool/brickfield/tests/area_test_base.php');
/**
* Class tool_brickfield_area_testcase
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class area_test extends area_test_base {
/**
* Test for the area assign intro
*/
public function test_assign(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign1 = $this->getDataGenerator()->create_module('assign', array(
'course' => $course->id, 'name' => 'Test!', 'intro' => '<p>Here we go</p>',
'introformat' => FORMAT_HTML));
list($course1, $cm1) = get_course_and_cm_from_instance($assign1->id, 'assign');
$assign2 = $this->getDataGenerator()->create_module('assign', array(
'course' => SITEID, 'name' => 'Test2!', 'intro' => 'Something',
'introformat' => FORMAT_MOODLE));
list($course2, $cm2) = get_course_and_cm_from_instance($assign2->id, 'assign');
$c = new \tool_brickfield\local\areas\mod_assign\intro();
$this->assertEquals('mod_assign', $c->get_component());
$this->assertEquals('assign', $c->get_tablename());
$resultsrs = $c->find_course_areas($course1->id);
$resultsrs2 = $c->find_course_areas($course2->id);
// Set up a results array from the recordset for easier testing.
$results = array_merge($this->array_from_recordset($resultsrs), $this->array_from_recordset($resultsrs2));
$this->assertEquals([
(object)[
'type' => area_base::TYPE_FIELD,
'contextid' => \context_module::instance($cm1->id)->id,
'component' => $c->get_component(),
'tablename' => $c->get_tablename(),
'fieldorarea' => $c->get_fieldname(),
'itemid' => $assign1->id,
'cmid' => $cm1->id,
'courseid' => $course1->id,
'content' => $assign1->intro,
],
(object)[
'type' => area_base::TYPE_FIELD,
'contextid' => \context_module::instance($cm2->id)->id,
'component' => $c->get_component(),
'tablename' => $c->get_tablename(),
'fieldorarea' => $c->get_fieldname(),
'itemid' => $assign2->id,
'cmid' => $cm2->id,
'courseid' => $course2->id,
'content' => $assign2->intro,
]
], $results);
// Emulate the course_module_updated event.
$event = \core\event\course_module_updated::create_from_cm($cm1);
$relevantresultsrs = $c->find_relevant_areas($event);
// Set up a relevantresults array from the recordset for easier testing.
$relevantresults = $this->array_from_recordset($relevantresultsrs);
$this->assertEquals([$results[0]], $relevantresults);
}
/**
* Test for the area questiontext
*/
public function test_questiontext(): void {
$this->resetAfterTest();
/** @var \core_question_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$component = 'core_question';
list($category1, $course1, $qcat1, $questions1) = $generator->setup_course_and_questions('course');
list($category2, $course2, $qcat2, $questions2) = $generator->setup_course_and_questions('category');
list($category3, $course3, $qcat3, $questions3) = $generator->setup_course_and_questions('system');
$c = new \tool_brickfield\local\areas\core_question\questiontext();
// Set up results arrays from the recordset for easier testing.
$course1areas = $this->array_from_recordset($c->find_course_areas($course1->id));
$course2areas = $c->find_course_areas($course2->id);
$course3areas = $c->find_course_areas($course3->id);
$sysareas = $this->array_from_recordset($c->find_system_areas());
// Assert the core_question area exists for the individual question's context, courseid and categoryid.
$this->assert_area_in_array(
$course1areas,
$component,
\context_course::instance($course1->id)->id,
$questions1[0]->id,
$course1->id,
null
);
$this->assert_area_in_array(
$sysareas,
$component,
\context_coursecat::instance($category2->id)->id,
$questions2[0]->id,
SITEID,
$category2->id
);
$this->assert_area_in_array(
$sysareas,
$component,
\context_system::instance()->id,
$questions3[0]->id,
SITEID,
null
);
// Emulate the question_created event.
$event = \core\event\question_created::create_from_question_instance($questions1[1],
\context_course::instance($course1->id));
$relevantresults = $this->array_from_recordset($c->find_relevant_areas($event));
$this->assert_area_in_array(
$course1areas,
$component,
\context_course::instance($relevantresults[0]->courseid)->id,
$relevantresults[0]->itemid,
$relevantresults[0]->courseid,
$relevantresults[0]->categoryid
);
}
/**
* test for the area questionanswers
*/
public function test_questionanswers(): void {
global $DB;
$this->resetAfterTest();
/** @var \core_question_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$course = $this->getDataGenerator()->create_course();
$cat = $generator->create_question_category(['contextid' => \context_course::instance($course->id)->id]);
$question1 = $generator->create_question('multichoice', null,
['name' => 'Example multichoice question', 'category' => $cat->id]);
$question2 = $generator->create_question('numerical', null,
['name' => 'Example numerical question', 'category' => $cat->id]);
$dbanswers = $DB->get_records('question_answers', [] , 'id');
$this->assertNotEmpty(count($dbanswers));
$c = new \tool_brickfield\local\areas\core_question\questionanswers();
$resultsrs = $c->find_course_areas($course->id);
$results = $this->array_from_recordset($resultsrs);
// There will be the same number of results as the number of records in the question_answers table.
$this->assertEquals(count($dbanswers), count($results));
// Emulate the question_updated event.
$event = \core\event\question_updated::create_from_question_instance($question1,
\context_course::instance($course->id));
$relevantresultsrs = $c->find_relevant_areas($event);
// Set up a relevantresults array from the recordset for easier testing.
$relevantresults = $this->array_from_recordset($relevantresultsrs);
$dbanswers = array_values($DB->get_records('question_answers', ['question' => $question1->id], 'id'));
$this->assertEquals(count($dbanswers), count($relevantresults));
foreach ($dbanswers as $i => $dbanswer) {
$relevantresult = $relevantresults[$i];
$this->assertEquals($dbanswer->answer, $relevantresult->content);
$this->assertEquals('question', $relevantresult->reftable);
$this->assertEquals($question1->id, $relevantresult->refid);
$this->assertEquals($dbanswer->id, $relevantresult->itemid);
}
}
/**
* Test for the areas choice intro and choice options
*/
public function test_choice(): void {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$choice1 = $this->getDataGenerator()->create_module('choice', [
'course' => $course->id, 'option' => ['fried rice', 'spring rolls', 'sweet and sour pork']
]);
list($course1, $cm1) = get_course_and_cm_from_instance($choice1->id, 'choice');
$choice2 = $this->getDataGenerator()->create_module('choice', [
'course' => $course->id, 'option' => ['blue', 'red']
]);
list($course2, $cm2) = get_course_and_cm_from_instance($choice2->id, 'choice');
// Testing the choice intro.
$c = new \tool_brickfield\local\areas\mod_choice\intro();
$resultsrs = $c->find_course_areas($course->id);
// Set up a results array from the recordset for easier testing.
$results = $this->array_from_recordset($resultsrs);
$this->assertCount(2, $results);
$this->assertEquals($cm1->id, $results[0]->cmid);
$this->assertEquals($choice2->id, $results[1]->itemid);
// Emulate the course_module_created event.
$event = \core\event\course_module_created::create_from_cm($cm1);
$relevantresultsrs = $c->find_relevant_areas($event);
$relevantresults = $this->array_from_recordset($relevantresultsrs);
$this->assertEquals([$results[0]], $relevantresults);
// Testing the choice options.
$c = new \tool_brickfield\local\areas\mod_choice\option();
$resultsrs = $c->find_course_areas($course->id);
// Set up a results array from the recordset for easier testing.
$results = $this->array_from_recordset($resultsrs);
$this->assertCount(5, $results);
$this->assertEquals($cm2->id, $results[3]->cmid);
$this->assertEquals('choice_options', $results[3]->tablename);
$this->assertEquals('choice', $results[3]->reftable);
$this->assertEquals($choice2->id, $results[3]->refid);
$options3 = $DB->get_records_menu('choice_options', ['choiceid' => $choice2->id], 'id', 'text,id');
$this->assertEquals($options3['blue'], $results[3]->itemid);
$this->assertEquals('blue', $results[3]->content);
// Emulate the course_module_updated event.
$event = \core\event\course_module_updated::create_from_cm($cm2);
$relevantresultsrs = $c->find_relevant_areas($event);
$relevantresults = $this->array_from_recordset($relevantresultsrs);
$this->assertEquals([$results[3], $results[4]], $relevantresults);
}
}
@@ -0,0 +1,94 @@
<?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/>.
namespace tool_brickfield;
/**
* Class area_test_base provides some utility functions that can be used by testing.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class area_test_base extends \advanced_testcase {
/** @var string Message for failed area test. */
protected $areatestmessage = 'Expected %component% area not found';
/**
* Create and return an array from a recordset. Recordset is destroyed.
* @param \moodle_recordset $rs
* @return array
*/
public function array_from_recordset(\moodle_recordset $rs): array {
$records = [];
foreach ($rs as $record) {
$records[] = $record;
}
// Can't rewind a recordset, so might as well close it.
$rs->close();
return $records;
}
/**
* Test for specified component information present in area recordset. Recordset cannot be reused.
* @param \moodle_recordset $areasrs
* @param string $component
* @param int $contextid
* @param int $itemid
* @param int|null $courseid
* @param int|null $categoryid
* @return void
*/
public function assert_area_in_recordset(\moodle_recordset $areasrs, string $component, int $contextid, int $itemid,
?int $courseid, ?int $categoryid): void {
$this->assert_area_in_array(
$this->array_from_recordset($areasrs),
$component,
$contextid,
$itemid,
$courseid,
$categoryid
);
}
/**
* Test for specified component information present in area array.
* @param array $areas
* @param string $component
* @param int $contextid
* @param int $itemid
* @param int|null $courseid
* @param int|null $categoryid
* @return void
*/
public function assert_area_in_array(array $areas, string $component, int $contextid, int $itemid,
?int $courseid, ?int $categoryid): void {
$found = false;
$message = str_replace('%component%', $component, $this->areatestmessage);
foreach ($areas as $area) {
if (($area->component == $component) &&
($area->contextid == $contextid) &&
((empty($courseid) ? empty($area->courseid) : ($area->courseid == $courseid))) &&
((empty($categoryid) ? empty($area->categoryid) : ($area->categoryid == $categoryid))) &&
($area->itemid == $itemid)
) {
$found = true;
break;
}
}
$this->assertTrue($found, $message);
}
}
@@ -0,0 +1,49 @@
@tool @tool_brickfield
Feature: Brickfield activityresults
Background:
Given the following "courses" exist:
| fullname | shortname | category | description |
| Course 1 | C1 | 0 | <b> Description text </b> |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| label | Label one | <b>Bold text is bold.</b> | C1 | id001 |
| label | Label two | <a href="modle.org">Click here</a> | C1 | id002 |
And the following config values are set as admin:
| analysistype | 1 | tool_brickfield |
@javascript
Scenario: Test the Brickfield accessibility tool plugin
Given I log in as "admin"
And I navigate to "Plugins > Admin tools > Accessibility > Brickfield registration" in site administration
And I set the field "id_key" to "123456789012345678901234567890ab"
And I set the field "id_hash" to "ab123456789012345678901234567890"
And I press "Activate"
Then I should see "Your accessibility toolkit is functional while being validated."
And I navigate to "Plugins > Admin tools > Accessibility > Reports" in site administration
And I press "Submit for analysis"
Then I should see "The global (course independent) content has been scheduled for analysis."
And I am on "Course 1" course homepage
And I navigate to "Accessibility toolkit" in current page administration
And I press "Submit for analysis"
Then I should see "This course has been scheduled for analysis."
And I run the scheduled task "\tool_brickfield\task\process_analysis_requests"
And I run the scheduled task "\tool_brickfield\task\bulk_process_courses"
And I run the scheduled task "\tool_brickfield\task\bulk_process_caches"
And I navigate to "Accessibility toolkit" in current page administration
And I should see "Error details: course Course 1"
And I should see "The overall page content length"
And I should see "Bold (b) elements should not be used"
And I should see "Link text should be descriptive"
And I follow "Activity breakdown"
Then I should see "Results per activity: course Course 1"
And I navigate to "Plugins > Admin tools > Accessibility > Brickfield registration" in site administration
And I set the field "id_key" to "123456789012345678901234567890ab"
And I set the field "id_hash" to "ab123456789012345678901234567890"
And I press "Activate"
And I navigate to "Plugins > Admin tools > Accessibility > Reports" in site administration
And I should see "Error details: all reviewed courses (2 courses)"
And I follow "Activity breakdown"
Then I should see "Results per activity: all reviewed courses (2 courses)"
And I follow "Content types"
Then I should see "Results per content type: all reviewed courses (2 courses)"
@@ -0,0 +1,216 @@
<?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/>.
namespace tool_brickfield;
use tool_brickfield\local\tool\filter;
/**
* Unit tests for {@filter tool_brickfield\local\tool\filter}.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Jay Churchward (jay.churchward@poetopensource.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filters_test extends \advanced_testcase {
public function test_constructor(): void {
$this->resetAfterTest();
// Variables.
$courseid = 1;
$categoryid = 2;
$tab = 'tab';
$page = 3;
$perpage = 4;
$url = 'url';
// Test responses.
$object = new filter();
$this->assertEquals($object->courseid, 0);
$this->assertEquals($object->categoryid, 0);
$this->assertEquals($object->tab, '');
$this->assertEquals($object->page, 0);
$this->assertEquals($object->perpage, 0);
$this->assertEquals($object->url, '');
$object = new filter($courseid, $categoryid, $tab, $page, $perpage, $url);
$this->assertEquals($object->courseid, $courseid);
$this->assertEquals($object->categoryid, $categoryid);
$this->assertEquals($object->tab, $tab);
$this->assertEquals($object->page, $page);
$this->assertEquals($object->perpage, $perpage);
$this->assertEquals($object->url, $url);
}
public function test_get_course_sql(): void {
$this->resetAfterTest();
$object = new filter();
$output = $object->get_course_sql();
$this->assertIsArray($output);
$this->assertEquals($output[0], '');
$object = $this->create_object_with_params();
$output = $object->get_course_sql();
$this->assertEquals($output[0], ' AND (courseid = ?)');
$this->assertEquals($output[1][0], $object->courseid);
}
public function test_validate_filters(): void {
$this->resetAfterTest();
// Variables.
$courseid = 0;
$categoryid = 2;
$tab = 'tab';
$page = 3;
$perpage = 4;
$url = 'url';
$object = new filter();
$output = $object->validate_filters();
$this->assertTrue($output);
$object = $this->create_object();
$output = $object->validate_filters();
$this->assertTrue($output);
$object = new filter($courseid, $categoryid, $tab, $page, $perpage);
$output = $object->validate_filters();
$this->assertFalse($output);
$category = $this->getDataGenerator()->create_category();
$object = new filter($courseid, $category->id, $tab, $page, $perpage);
$output = $object->validate_filters();
$this->assertFalse($output);
}
public function test_has_course_filters(): void {
$this->resetAfterTest();
$object = new filter();
$output = $object->has_course_filters();
$this->assertFalse($output);
$object = $this->create_object();
$output = $object->has_course_filters();
$this->assertTrue($output);
}
public function test_has_capability_in_context(): void {
global $DB;
$this->resetAfterTest();
$object = $this->create_object_with_params();
$capability = accessibility::get_capability_name('viewcoursetools');
$output = $object->has_capability_in_context($capability, \context_system::instance());
$this->assertFalse($output);
$output = $object->has_capability_in_context($capability, \context_coursecat::instance($object->categoryid));
$this->assertFalse($output);
$output = $object->has_capability_in_context($capability, \context_course::instance($object->courseid));
$this->assertFalse($output);
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$this->setUser($user);
$output = $object->has_capability_in_context($capability, \context_system::instance());
$this->assertFalse($output);
$output = $object->has_capability_in_context($capability, \context_coursecat::instance($object->categoryid));
$this->assertFalse($output);
$output = $object->has_capability_in_context($capability, \context_course::instance($course->id));
$this->assertTrue($output);
$teacherrole = $DB->get_record('role', ['shortname' => 'teacher']);
$categorycontext = \context_coursecat::instance($object->categoryid);
$this->getDataGenerator()->role_assign($teacherrole->id, $user->id, $categorycontext->id);
$output = $object->has_capability_in_context($capability, $categorycontext);
$this->assertTrue($output);
}
public function test_get_errormessage(): void {
$this->resetAfterTest();
// Variables.
$courseid = 0;
$categoryid = 2;
$tab = 'tab';
$page = 3;
$perpage = 4;
$url = 'url';
$object = new filter();
$output = $object->get_errormessage();
$this->assertNull($output);
$object = new filter($courseid, $categoryid, $tab, $page, $perpage);
$object->validate_filters();
$output = $object->get_errormessage();
$this->assertEquals($output, 'Invalid category, please check your input');
$category = $this->getDataGenerator()->create_category();
$object = new filter($courseid, $category->id, $tab, $page, $perpage);
$object->validate_filters();
$output = $object->get_errormessage();
$this->assertEquals($output, 'No courses found for category ' . $category->id);
}
/**
* Create a filter object and return it.
* @return filter
*/
private function create_object() {
// Variables.
$courseid = 1;
$categoryid = 2;
$tab = 'tab';
$page = 3;
$perpage = 4;
$url = 'url';
$object = new filter($courseid, $categoryid, $tab, $page, $perpage);
return $object;
}
/**
* Create a filter object with some parameters and return it.
* @return filter
*/
private function create_object_with_params() {
// Variables.
$tab = 'tab';
$page = 3;
$perpage = 4;
$url = 'url';
$category = $this->getDataGenerator()->create_category();
$course = $this->getDataGenerator()->create_course((object)['category' => $category->id]);
$object = new filter($course->id, $category->id, $tab, $page, $perpage);
return $object;
}
}
@@ -0,0 +1,70 @@
<?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/>.
/**
* PHPUnit tool_brickfield tests
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Mike Churchward (mike@brickfieldlabs.ie)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield;
defined('MOODLE_INTERNAL') || die();
/**
* Mock brickfield connect.
*/
class mock_brickfieldconnect extends brickfieldconnect {
/**
* Valid api key.
*/
const VALIDAPIKEY = '123456789012345678901234567890ab';
/**
* Valid secret key.
*/
const VALIDSECRETKEY = 'ab123456789012345678901234567890';
/** @var string api key. */
protected $apikey = '';
/** @var string Secret key. */
protected $secretkey = '';
/**
* Is registered.
* @return bool is registered
*/
public function is_registered(): bool {
return ($this->apikey == self::VALIDAPIKEY) && ($this->secretkey == self::VALIDSECRETKEY);
}
/**
* Update Registration.
* @param string $apikey
* @param string $secretkey
* @return bool
*/
public function update_registration(string $apikey, string $secretkey): bool {
$this->apikey = $apikey;
$this->secretkey = $secretkey;
return $this->is_registered();
}
}
@@ -0,0 +1,72 @@
<?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/>.
/**
* PHPUnit tool_brickfield tests
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Mike Churchward (mike@brickfieldlabs.ie)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/admin/tool/brickfield/tests/generator/mock_brickfieldconnect.php');
/**
* Mock registration.
*/
class mock_registration extends registration {
/**
* Get registration connection.
* @return brickfieldconnect
*/
protected function get_registration_connection(): brickfieldconnect {
return new mock_brickfieldconnect();
}
/**
* Is not entered.
* @return bool
*/
public function is_not_entered() {
return $this->status_is_not_entered();
}
/**
* Invalidate validation time.
* @return int
* @throws \dml_exception
*/
public function invalidate_validation_time() {
$this->set_validation_time(time() - (7 * 24 * 60 * 60));
return $this->get_validation_time();
}
/**
* Invalidate summary time.
* @return int
* @throws \dml_exception
*/
public function invalidate_summary_time() {
$this->set_summary_time(time() - (7 * 24 * 60 * 60) - 1);
return $this->get_summary_time();
}
}
@@ -0,0 +1,191 @@
<?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/>.
namespace tool_brickfield\local\areas\core_question;
/**
* Tests for questionanswer.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class questionanswers_test extends \advanced_testcase {
/**
* Set up before class.
*/
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
}
/**
* Test find course areas.
*/
public function test_find_course_areas(): void {
$this->resetAfterTest();
$this->setAdminUser();
$category = $this->getDataGenerator()->create_category();
$course = $this->getDataGenerator()->create_course(['category' => $category->id]);
$coursecontext = \context_course::instance($course->id);
$catcontext = \context_coursecat::instance($category->id);
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat1 = $generator->create_question_category(['contextid' => $coursecontext->id]);
$question1 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
$question2 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
$questionanswers = new questionanswers();
$rs = $questionanswers->find_course_areas($course->id);
$this->assertNotNull($rs);
// Each multichoice question generated has four answers. So there should be eight records.
$count = 0;
foreach ($rs as $rec) {
$count++;
$this->assertEquals($coursecontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
if ($count <= 4) {
$this->assertEquals($question1->id, $rec->refid);
} else {
$this->assertEquals($question2->id, $rec->refid);
}
}
$rs->close();
$this->assertEquals(8, $count);
// Add a question to a quiz in the course.
$quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id, 'name' => 'Quiz1']);
$quizmodule = get_coursemodule_from_instance('quiz', $quiz->id, $course->id);
$quizcontext = \context_module::instance($quizmodule->id);
// Add a question to the quiz context.
$cat2 = $generator->create_question_category(['contextid' => $quizcontext->id]);
$question3 = $generator->create_question('multichoice', null, ['category' => $cat2->id]);
$rs2 = $questionanswers->find_course_areas($course->id);
$this->assertNotNull($rs2);
// Each multichoice question generated has four answers. So there should be twelve records now.
$count = 0;
foreach ($rs2 as $rec) {
$count++;
if ($count <= 4) {
$this->assertEquals($coursecontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
$this->assertEquals($question1->id, $rec->refid);
} else if ($count <= 8) {
$this->assertEquals($coursecontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
$this->assertEquals($question2->id, $rec->refid);
} else {
$this->assertEquals($quizcontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
$this->assertEquals($question3->id, $rec->refid);
}
}
$rs2->close();
$this->assertEquals(12, $count);
// Add a question to the category context.
$cat3 = $generator->create_question_category(['contextid' => $catcontext->id]);
$question4 = $generator->create_question('multichoice', null, ['category' => $cat3->id]);
$rs3 = $questionanswers->find_course_areas($course->id);
$this->assertNotNull($rs3);
// The category level questions should not be found.
$count = 0;
foreach ($rs3 as $rec) {
$count++;
if ($count > 8) {
$this->assertEquals($quizcontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
$this->assertEquals($question3->id, $rec->refid);
}
}
$rs2->close();
$this->assertEquals(12, $count);
}
/**
* Test find relevant areas.
*/
public function test_find_relevant_areas(): void {
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$coursecontext = \context_course::instance($course->id);
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat1 = $generator->create_question_category(['contextid' => $coursecontext->id]);
$question1 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
$question2 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
$questionanswers = new questionanswers();
$event = \core\event\question_updated::create_from_question_instance($question1,
\context_course::instance($course->id));
$rs = $questionanswers->find_relevant_areas($event);
$this->assertNotNull($rs);
// Each multichoice question generated has four answers.
$count = 0;
foreach ($rs as $rec) {
$count++;
$this->assertEquals($coursecontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
$this->assertEquals($question1->id, $rec->refid);
}
$rs->close();
$this->assertEquals(4, $count);
}
/**
* Test find system areas.
*/
public function test_find_system_areas(): void {
$this->resetAfterTest();
$this->setAdminUser();
$category = $this->getDataGenerator()->create_category();
$catcontext = \context_coursecat::instance($category->id);
$systemcontext = \context_system::instance();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category(['contextid' => $catcontext->id]);
$cat2 = $generator->create_question_category(['contextid' => $systemcontext->id]);
$question = $generator->create_question('multichoice', null, ['category' => $cat2->id]);
$question2 = $generator->create_question('multichoice', null, ['category' => $cat->id]);
$questionanswers = new questionanswers();
$rs = $questionanswers->find_system_areas();
$this->assertNotNull($rs);
// Each multichoice question generated has four answers.
$count = 0;
foreach ($rs as $rec) {
$count++;
if ($count <= 4) {
$this->assertEquals($systemcontext->id, $rec->contextid);
$this->assertEquals(1, $rec->courseid);
$this->assertEquals(0, $rec->categoryid);
$this->assertEquals($question->id, $rec->refid);
} else {
$this->assertEquals($catcontext->id, $rec->contextid);
$this->assertEquals(1, $rec->courseid);
$this->assertEquals($category->id, $rec->categoryid);
$this->assertEquals($question2->id, $rec->refid);
}
}
$rs->close();
$this->assertEquals(8, $count);
}
}
@@ -0,0 +1,222 @@
<?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/>.
namespace tool_brickfield\local\areas\core_question;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/admin/tool/brickfield/tests/area_test_base.php');
use tool_brickfield\area_test_base;
/**
* Tests for questiontext.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \tool_brickfield\local\areas\core_question\base
*/
class questiontext_test extends area_test_base {
/**
* Set up before class.
*/
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
}
/**
* Test find course areas.
*/
public function test_find_course_areas(): void {
$this->resetAfterTest();
$this->setAdminUser();
$category = $this->getDataGenerator()->create_category();
$course = $this->getDataGenerator()->create_course(['category' => $category->id]);
$coursecontext = \context_course::instance($course->id);
$catcontext = \context_coursecat::instance($category->id);
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat1 = $generator->create_question_category(['contextid' => $coursecontext->id]);
$question1 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
$question2 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
$questiontext = new questiontext();
$rs = $questiontext->find_course_areas($course->id);
$this->assertNotNull($rs);
$count = 0;
foreach ($rs as $rec) {
$count++;
$this->assertEquals($coursecontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
if ($count <= 1) {
$this->assertEquals($question1->id, $rec->itemid);
} else {
$this->assertEquals($question2->id, $rec->itemid);
}
}
$rs->close();
$this->assertEquals(2, $count);
// Add a question to a quiz in the course.
$quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id, 'name' => 'Quiz1']);
$quizmodule = get_coursemodule_from_instance('quiz', $quiz->id, $course->id);
$quizcontext = \context_module::instance($quizmodule->id);
// Add a question to the quiz context.
$cat2 = $generator->create_question_category(['contextid' => $quizcontext->id]);
$question3 = $generator->create_question('multichoice', null, ['category' => $cat2->id]);
$rs2 = $questiontext->find_course_areas($course->id);
$this->assertNotNull($rs2);
$count = 0;
foreach ($rs2 as $rec) {
$count++;
if ($count <= 1) {
$this->assertEquals($coursecontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
$this->assertEquals($question1->id, $rec->itemid);
} else if ($count <= 2) {
$this->assertEquals($coursecontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
$this->assertEquals($question2->id, $rec->itemid);
} else {
$this->assertEquals($quizcontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
$this->assertEquals($question3->id, $rec->itemid);
}
}
$rs2->close();
$this->assertEquals(3, $count);
// Add a question to the category context.
$cat3 = $generator->create_question_category(['contextid' => $catcontext->id]);
$question4 = $generator->create_question('multichoice', null, ['category' => $cat3->id]);
$rs3 = $questiontext->find_course_areas($course->id);
$this->assertNotNull($rs3);
// The category level questions should not be found.
$count = 0;
foreach ($rs3 as $rec) {
$count++;
if ($count > 2) {
$this->assertEquals($quizcontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
$this->assertEquals($question3->id, $rec->itemid);
}
}
$rs2->close();
$this->assertEquals(3, $count);
}
/**
* Test find relevant areas.
*/
public function test_find_relevant_areas(): void {
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$coursecontext = \context_course::instance($course->id);
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat1 = $generator->create_question_category(['contextid' => $coursecontext->id]);
$question1 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
$question2 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
$questiontext = new questiontext();
$event = \core\event\question_updated::create_from_question_instance($question1,
\context_course::instance($course->id));
$rs = $questiontext->find_relevant_areas($event);
$this->assertNotNull($rs);
$count = 0;
foreach ($rs as $rec) {
$count++;
$this->assertEquals($coursecontext->id, $rec->contextid);
$this->assertEquals($course->id, $rec->courseid);
$this->assertEquals($question1->id, $rec->itemid);
}
$rs->close();
$this->assertEquals(1, $count);
}
/**
* Test find system areas.
*/
public function test_find_system_areas(): void {
$this->resetAfterTest();
$this->setAdminUser();
$category = $this->getDataGenerator()->create_category();
$catcontext = \context_coursecat::instance($category->id);
$systemcontext = \context_system::instance();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$component = 'core_question';
$cat = $generator->create_question_category(['contextid' => $catcontext->id]);
$cat2 = $generator->create_question_category(['contextid' => $systemcontext->id]);
$question = $generator->create_question('multichoice', null, ['category' => $cat2->id]);
$question2 = $generator->create_question('multichoice', null, ['category' => $cat->id]);
$questiontext = new questiontext();
$areas = $this->array_from_recordset($questiontext->find_system_areas());
// Assert the core_question area exists for the individual question's context, courseid and categoryid.
$this->assert_area_in_array(
$areas,
$component,
$systemcontext->id,
$question->id,
SITEID,
null
);
$this->assert_area_in_array(
$areas,
$component,
$catcontext->id,
$question2->id,
SITEID,
$category->id
);
}
/**
* Test get course and category.
*
* @covers ::get_course_and_category
*/
public function test_get_course_and_category(): void {
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$coursecontext = \context_course::instance($course->id);
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat1 = $generator->create_question_category(['contextid' => $coursecontext->id]);
$question1 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
$event = \core\event\question_updated::create_from_question_instance($question1,
\context_course::instance($course->id));
$rs = base::get_course_and_category(CONTEXT_COURSE, $event->objectid);
$this->assertNotNull($rs);
$this->assertEquals(CONTEXT_COURSE, $rs->contextlevel);
$this->assertNotEquals(CONTEXT_MODULE, $rs->contextlevel);
// Invalid objectid.
$rs = base::get_course_and_category(CONTEXT_COURSE, 0);
$this->assertFalse($rs);
// Incorrect objectid.
$rs = base::get_course_and_category(CONTEXT_COURSE, 100);
$this->assertFalse($rs);
}
}
@@ -0,0 +1,122 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class a_links_dont_open_new_window_testcase
*/
class a_links_dont_open_new_window_test extends all_checks {
/** @var string Check type */
protected $checktype = 'a_links_dont_open_new_window';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>A links must not open a new tab or window</title>
</head>
<body>
<a href="www.google.com" target="_blank">This is google</a>
</body>
</html>
EOD;
/** @var string Html pass 1 */
private $htmlpass1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>A links must not open a new tab or window</title>
</head>
<body>
<a href="www.google.com" target="_self">This is google</a>
</body>
</html>
EOD;
/** @var string Html pass 2 */
private $htmlpass2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>A links must not open a new tab or window</title>
</head>
<body>
<a href="www.youtube.com" target="_parent">This is youtube</a>
</body>
</html>
EOD;
/** @var string Html pass 3 */
private $htmlpass3 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>A links must not open a new tab or window</title>
</head>
<body>
<a href="www.youtube.com" target="_top">This is youtube</a>
</body>
</html>
EOD;
/** @var string Html pass 4 */
private $htmlpass4 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>A link can indicate that it will open in a new window</title>
</head>
<body>
<a href="www.youtube.com" target="_blank">This is youtube (opens in a new window)</a>
</body>
</html>
EOD;
/**
* Test for links opening a new tab or window
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'a');
$results = $this->get_checker_results($this->htmlpass1);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass2);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass3);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass4);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,74 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class a_must_contain_text_testcase
*/
class a_must_contain_text_test extends all_checks {
/** @var string Check type */
protected $checktype = 'a_must_contain_text';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Anchor tags must contain text</title>
</head>
<body>
<a href="www.youtube.com"></a>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Anchor tags must contain text</title>
</head>
<body>
<a href="www.youtube.com">This is youtube</a>
</body>
</html>
EOD;
/**
* Test for anchor tags containing text
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'a');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,106 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class a_suspicious_link_text
*/
class a_suspicious_link_text_test extends all_checks {
/** @var string Check type */
protected $checktype = 'a_suspicious_link_text';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Anchor tag text must be specific</title>
</head>
<body>
<a href="www.youtube.com">click here</a>
</body>
</html>
EOD;
/** @var string Html fail 2 */
private $htmlfail2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Anchor tag text must be specific</title>
</head>
<body>
<p><a href="https://www.bbc.com/">www.bbc.com</a></p>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Anchor tag text must be specific</title>
</head>
<body>
<a href="www.youtube.com">YouTube</a>
</body>
</html>
EOD;
/** @var string Html pass 2 */
private $htmlpass2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Anchor tag text must be specific</title>
</head>
<body>
<a href="www.youtube.com">http://www.google.com</a>
</body>
</html>
EOD;
/**
* Test for anchor tags not containing susplicious link text
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass2);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'a');
$results = $this->get_checker_results($this->htmlfail2);
$this->assertTrue($results[0]->element->tagName == 'a');
}
}
@@ -0,0 +1,42 @@
<?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/>.
namespace tool_brickfield\local\htmlchecker\common\checks;
use tool_brickfield\local\htmlchecker\brickfield_accessibility;
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class all_checks extends \advanced_testcase {
// Extending class must define this.
/** @var string Check type */
protected $checktype;
/**
* Parent function to be called in every check testcase
* @param string $html
*/
public function get_checker_results(string $html) {
$checker = new brickfield_accessibility($html, 'brickfield', 'string');
$checker->run_check();
return $checker->get_test($this->checktype);
}
}
@@ -0,0 +1,122 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class area_dont_open_new_window_testcase
*/
class area_dont_open_new_window_test extends all_checks {
/** @var string Check type */
protected $checktype = 'area_dont_open_new_window';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Area tags must not open new window without warning</title>
</head>
<body>
<area target="_blank"></area>
</body>
</html>
EOD;
/** @var string Html pass 1 */
private $htmlpass1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Area tags must not open new window without warning</title>
</head>
<body>
<area target="_self"></area>
</body>
</html>
EOD;
/** @var string Html pass 2 */
private $htmlpass2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Area tags must not open new window without warning</title>
</head>
<body>
<area target="_parent"></area>
</body>
</html>
EOD;
/** @var string Html pass 3 */
private $htmlpass3 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Area tags must not open new window without warning</title>
</head>
<body>
<area target="_top"></area>
</body>
</html>
EOD;
/** @var string Html pass 4 */
private $htmlpass4 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>A link can indicate that it will open in a new window</title>
</head>
<body>
<area target="_blank" alt="(opens in a new window)"></area>
</body>
</html>
EOD;
/**
* Test Area tags opening new window without warning
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'area');
$results = $this->get_checker_results($this->htmlpass1);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass2);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass3);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass4);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,74 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class area_has_alt_value_testcase
*/
class area_has_alt_value_test extends all_checks {
/** @var string Check type */
protected $checktype = 'area_has_alt_value';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Area tags must have an alt value</title>
</head>
<body>
<area shape="rect">
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Area tags must have an alt value</title>
</head>
<body>
<area shape="rect" alt="this is alt text">
</body>
</html>
EOD;
/**
* Test for area tags containing an alt value
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'area');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,74 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class basefont_is_not_used_testcase
*/
class basefont_is_not_used_test extends all_checks {
/** @var string Check type */
protected $checktype = 'basefont_is_not_used';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Basefont tags must not be used</title>
</head>
<body>
<basefont>This is a basefont tag></basefont>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Basefont tags must not be used</title>
</head>
<body>
<p>This is not a basefont tag</p>
</body>
</html>
EOD;
/**
* Test for basefont tags being used
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'basefont');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,74 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class blink_is_not_used_testcase
*/
class blink_is_not_used_test extends all_checks {
/** @var string Check type */
protected $checktype = 'blink_is_not_used';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Blink tags must not be used</title>
</head>
<body>
<blink>This text is blinking</blink>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Blink tags must not be used</title>
</head>
<body>
<p>This text does not blink</p>
</body>
</html>
EOD;
/**
* Test for blink tags being used
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'blink');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,76 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class bold_is_not_used_testcase
*/
class bold_is_not_used_test extends all_checks {
/** @var string Check type */
protected $checktype = 'bold_is_not_used';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>b tags must not be used</title>
</head>
<body>
<b>This text is bold</b>
<b style="color: red">This text is also bold</b>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>b tags must not be used</title>
</head>
<body>
<strong>This text is strong</strong>
</body>
</html>
EOD;
/**
* Test for b tags being used
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'b');
$this->assertTrue($results[1]->element->tagName == 'b');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,137 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class content_too_long_testcase
*/
class content_too_long_test extends all_checks {
/** @var string Check type */
protected $checktype = 'content_too_long';
/** @var string Html fail */
private $htmlfail = <<<EOD
<p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent accumsan, ante varius viverra aliquam, dolor risus
scelerisque massa, ut lacinia ipsum felis id est. Nullam convallis odio ante, in commodo elit fermentum sed. Vivamus ullamcorper
tincidunt sagittis. Sed et semper sapien. Quisque malesuada lacus nec libero cursus, aliquam malesuada neque ultricies. Cras sit
amet enim vel orci tristique porttitor a vitae urna. Suspendisse mi leo, hendrerit et eleifend a, mollis at ex. Maecenas eget
magna nec sem dignissim pharetra vel nec ex. Donec in porta lectus. Aenean porttitor euismod lectus, sodales eleifend ex egestas
in. Donec sed metus sodales, lobortis velit quis, dictum arcu.</span></p>
<p><span>Praesent mollis urna eget odio cursus, sit amet sollicitudin ante aliquam. Integer nec massa nec ipsum tincidunt
laoreet in vitae metus.
Integer massa lacus, elementum quis dui sed, eleifend fringilla turpis. In hac habitasse platea dictumst. Phasellus
efficitur quis felis non eleifend. Sed et mauris vel lorem ultrices porta. Mauris commodo condimentum felis, vel dictum ex
laoreet sit amet. Duis venenatis ut lacus non ultrices. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
inceptos himenaeos. Nam nunc magna, semper feugiat feugiat a, pellentesque vel nulla.
Sed lacinia nunc lobortis, vestibulum nisi dictum, pulvinar tellus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed
sodales, mauris vitae vulputate porttitor, urna tellus tempor turpis, sed hendrerit metus turpis at est. Etiam augue purus,
blandit eget elit sit amet, suscipit mollis ligula. Suspendisse rutrum sem ex, eu commodo nisi aliquam sit amet. Fusce ut felis
justo. Sed a quam at lectus consectetur vulputate. Proin elementum dui nisi, in condimentum diam porttitor eget. Donec vehicula
condimentum velit vel semper. Mauris vehicula tortor lectus, quis convallis erat aliquet vel. In dictum nunc ac posuere porta.
Sed vel leo aliquam, volutpat ligula ac, blandit diam. Donec nec ligula lacus.</span></p>
<p><span>Mauris ac libero vel ex fringilla fringilla. Ut vehicula justo eu nunc imperdiet ultricies. Sed interdum ligula at nisi
rhoncus auctor.
Sed tempus tellus eget risus placerat, et viverra dolor gravida. Sed ultricies neque id ex tempor viverra. Ut imperdiet
pharetra magna sed tristique. Pellentesque blandit elit ac neque lacinia finibus. Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Donec vel auctor dolor. Morbi id elit mollis ante mattis semper eu ac lectus. Integer elit turpis, facilisis
vel metus eget, blandit tempus arcu. Pellentesque eget magna eu ex eleifend tincidunt. Curabitur sit amet congue nisi.
Cras mauris risus, malesuada egestas dapibus et, pharetra in ante. Aenean sit amet augue non ligula tempor scelerisque eget ac
turpis. Aenean tincidunt tristique dui, pretium lacinia felis posuere vel. Donec massa ligula, luctus vitae enim nec, sagittis
hendrerit lorem. In consequat sodales metus vel porttitor. Aenean fringilla fringilla risus, vitae interdum turpis egestas quis.
Aenean volutpat arcu leo, ut dictum purus consectetur id. Cras enim ipsum, tincidunt vitae mi vel, varius convallis ex. Fusce
pretium porttitor tempus.</span></p>
<p>Morbi laoreet dapibus lectus ut efficitur. Donec at hendrerit nunc. Vivamus venenatis augue non nulla finibus vestibulum. Nam
nunc magna, hendrerit a ipsum nec, pulvinar imperdiet augue. Fusce vel metus maximus, mattis magna at, egestas enim. Suspendisse
et nisl at enim mollis scelerisque. Duis ut ipsum vel turpis eleifend aliquet a a ante. Nam lacinia purus vulputate purus
tincidunt, aliquet sagittis nisi sagittis. Pellentesque efficitur massa non ex sodales pretium. Cras convallis vitae ex et
dignissim. Nunc suscipit bibendum aliquam. Maecenas interdum tellus varius, laoreet velit sed, ornare arcu. Nunc pulvinar
elementum sem eget scelerisque. Duis volutpat tellus ut risus finibus, nec molestie erat fermentum
</p>
EOD;
/** @var string Multibyte html falure */
private $htmlfail2 = <<<EOD
<p><span>ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル ブルース カンベッル
</span></p>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<p>Nice and short text</p>
EOD;
/**
* Test for checking the length of the content
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->message == '<p id=\'wc\'>Word Count: 578</p>');
$results = $this->get_checker_results($this->htmlfail2);
$this->assertTrue($results[0]->message == '<p id=\'wc\'>Word Count: 504</p>');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,461 @@
<?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/>.
/**
* Class test_css_text_has_contrast test
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class test_css_text_has_contrast_test
* @covers \tool_brickfield\local\htmlchecker\brickfield_accessibility
*/
class css_text_has_contrast_test extends all_checks {
/** @var string The check type. */
protected $checktype = 'css_text_has_contrast';
/** @var string HTML that should get flagged. */
private $htmlfail1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color:#333333; background-color:#000000; font-weight: bold;">This is not contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML that should get flagged. */
private $htmlfail2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color:#333333; background-color:#000000; font-size: 18px;">This is not contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML that should get flagged. */
private $htmlfail3 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color:#333333; background-color:#000000; font-size: 18%;">This is not contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML that should get flagged. */
private $htmlfail4 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color:#333333; background-color:#000000; font-size: 18em;">This is not contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML that should get flagged. */
private $htmlfail5 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color:#333333; background-color:#000000; font-size: 18ex;">This is not contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML that should get flagged. */
private $htmlfail6 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color:#333333; background-color:#000000;">This is not contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML that should not get flagged. */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color:#333333; background-color:#ffffff;">This is contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML that should get flagged. */
private $namecolours = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color: red; background-color: blue;">This is not contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML with invalid colour names. */
private $invalidcolours = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color: grog; background-color: numpi;">This is not contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML with invalid colour numeric values. */
private $invalidvalue = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color: 10000500; background-color: -10234;">This is not contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML with empty colour values. */
private $emptyvalue = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>OAC Testfile - Check #6 - Positive</title>
</head>
<body>
<p style="color:; background-color:;">This is not contrasty enough.</p>
</body>
</html>
EOD;
/** @var string HTML with px18 fail colour values. */
private $px18 = <<<EOD
<body><p style="color:#EF0000; background-color:white; font-size: 18px">
This is not contrasty enough.</p></body>
EOD;
/** @var string HTML with px19bold pass colour values. */
private $px19bold = <<<EOD
<body><p style="color:#EF0000; background-color:white; font-size: 19px; font-weight: bold;">
This is contrasty enough.</p></body>
EOD;
/** @var string HTML with px18 pass colour values. */
private $px18pass = <<<EOD
<body><p style="color:#E60000; background-color:white; font-size: 18px">
This is contrasty enough.</p></body>
EOD;
/** @var string HTML with medium size colour values. */
private $mediumfail = <<<EOD
<body><p style="color:#EF0000; background-color:white; font-size: medium">
This is not contrasty enough.</p></body>
EOD;
/** @var string HTML with px18 colour values. */
private $mediumpass = <<<EOD
<body><p style="color:#E60000; background-color:white; font-size: medium">
This is contrasty enough.</p></body>
EOD;
/** @var string HTML with larger fail colour values. */
private $largerfail = <<<EOD
<body><p style="color:#FF6161; background-color:white; font-size: larger">
This is not contrasty enough.</p></body>
EOD;
/** @var string HTML with px18 colour values. */
private $largerpass = <<<EOD
<body><p style="color:#FF5C5C; background-color:white; font-size: larger;">
This is contrasty enough.</p></body>
EOD;
/** @var string HTML with px18 colour values. */
private $largerboldpass = <<<EOD
<body><p style="color:#FF5C5C; background-color:white; font-size: larger; font-weight: bold;">
This is contrasty enough.</p></body>
EOD;
/**
* Test for the area assign intro
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail1);
$this->assertTrue($results[0]->element->tagName == 'p');
$results = $this->get_checker_results($this->htmlfail2);
$this->assertTrue($results[0]->element->tagName == 'p');
$results = $this->get_checker_results($this->htmlfail3);
$this->assertTrue($results[0]->element->tagName == 'p');
$results = $this->get_checker_results($this->htmlfail4);
$this->assertTrue($results[0]->element->tagName == 'p');
$results = $this->get_checker_results($this->htmlfail5);
$this->assertTrue($results[0]->element->tagName == 'p');
$results = $this->get_checker_results($this->htmlfail6);
$this->assertTrue($results[0]->element->tagName == 'p');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
/**
* Test with valid colour names.
*/
public function test_check_for_namedcolours(): void {
$results = $this->get_checker_results($this->namecolours);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test with invalid colour names.
*/
public function test_check_for_invalidcolours(): void {
$results = $this->get_checker_results($this->invalidcolours);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test with invalid colour numeric values.
*/
public function test_check_for_invalidvalues(): void {
$results = $this->get_checker_results($this->invalidvalue);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test with empty colour values.
*/
public function test_check_for_emptyvalues(): void {
$results = $this->get_checker_results($this->emptyvalue);
$this->assertEmpty($results);
}
/**
* Test for text px18 with insufficient contrast of 4.49.
*/
public function test_check_for_px18_fail(): void {
$results = $this->get_checker_results($this->px18);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for text px19 bold with sufficient contrast of 4.49.
*/
public function test_check_for_px19bold_pass(): void {
$results = $this->get_checker_results($this->px19bold);
$this->assertEmpty($results);
}
/**
* Test for text px18 with sufficient contrast of 4.81.
*/
public function test_check_for_px18_pass(): void {
$results = $this->get_checker_results($this->px18pass);
$this->assertEmpty($results);
}
/**
* Test for medium (12pt) text with insufficient contrast of 4.49.
*/
public function test_check_for_medium_fail(): void {
$results = $this->get_checker_results($this->mediumfail);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for medium (12pt) text with sufficient contrast of 4.81.
*/
public function test_check_for_medium_pass(): void {
$results = $this->get_checker_results($this->mediumpass);
$this->assertEmpty($results);
}
/**
* Test for larger (14pt) text with insufficient contrast of 2.94.
*/
public function test_check_for_larger_fail(): void {
$results = $this->get_checker_results($this->largerfail);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for larger (14pt) text with insufficient contrast of 3.02.
*/
public function test_check_for_larger_pass(): void {
$results = $this->get_checker_results($this->largerpass);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for larger (14pt) bold text with sufficient contrast of 3.02.
*/
public function test_check_for_largerbold_pass(): void {
$results = $this->get_checker_results($this->largerboldpass);
$this->assertEmpty($results);
}
/**
* Test for rgb colors with insufficient contrast.
*/
public function test_bad_rgbcolor(): void {
$html = '<body><p style="color:rgb(255, 255, 255); background-color:rgb(204, 204, 204);">
This is not contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for rgb colors with sufficient contrast.
*/
public function test_good_rgbcolor(): void {
$html = '<body><p style="color:rgb(255, 255, 255); background-color:rgb(0, 0, 0);">
This is contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertEmpty($results);
}
/**
* Test for named colors with insufficient contrast.
*/
public function test_bad_namedcolor2(): void {
$html = '<body><p style="color:lightcyan; background-color:lavender;">
This is not contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for named colors with sufficient contrast.
*/
public function test_good_namedcolor2(): void {
$html = '<body><p style="color:linen; background-color:darkslategray;">
This is contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertEmpty($results);
}
/**
* Test for background value with insufficient contrast.
*/
public function test_bad_backgroundcss(): void {
$html = '<body><p style="color:lightcyan; background:fixed lavender center;">
This is not contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for background value with sufficient contrast.
*/
public function test_good_backgroundcss(): void {
$html = '<body><p style="color:linen; background:fixed darkslategray center;">
This is contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertEmpty($results);
}
/**
* Test for background value with rgb with insufficient contrast.
*/
public function test_bad_backgroundcssrgb(): void {
$html = '<body><p style="color:rgb(255, 255, 255); background:fixed rgb(204, 204, 204) center;">
This is not contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for background value with rgb with sufficient contrast.
*/
public function test_good_backgroundcssrgb(): void {
$html = '<body><p style="color:rgb(255, 255, 255); background:fixed rgb(0, 0, 0) center;">
This is contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertEmpty($results);
}
/**
* Test for text with insufficient contrast of 4.3.
*/
public function test_bad_contrastrounding(): void {
$html = '<body><p style="color:#F50000; background-color:white; font-size: 12px">
This is not contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for background value with rgba with insufficient contrast.
*/
public function test_bad_backgroundcssrgba(): void {
$html = '<body><p style="color:rgba(255, 255, 255, 0.5); background:fixed rgba(0, 204, 204, 0.5) center;">
This is not contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for background value with rgba with sufficient contrast.
*/
public function test_good_backgroundcssrgba(): void {
$html = '<body><p style="color:rgba(255, 255, 255, 0.75); background:fixed rgba(0, 0, 0, 0.75) center;">
This is contrasty enough.</p></body>';
$results = $this->get_checker_results($html);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,94 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class embed_has_associated_no_embed_testcase
*/
class embed_has_associated_no_embed_test extends all_checks {
/** @var string Check type */
protected $checktype = 'embed_has_associated_no_embed';
/** @var string Html fail 1 */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Embed tags must have a noembed child tag</title>
</head>
<body>
<embed type="text/html" src="snippet.html" width="500" height="200">
</body>
</html>
EOD;
/** @var string Html fail 2 */
private $htmlfail2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Embed tags must have a noembed child tag</title>
</head>
<body>
<embed type="text/html" src="snippet.html" width="500" height="200">
</embed>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>Embed tags must have a noembed child tag</title>
</head>
<body>
<embed type="text/html" src="snippet.html" width="500" height="200">
<noembed> <img src = "yourimage.gif" alt = "Alternative Media" ></noembed>
</embed>
</body>
</html>
EOD;
/**
* Test for noembed child tags
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'embed');
$results = $this->get_checker_results($this->htmlfail2);
$this->assertTrue($results[0]->element->tagName == 'embed');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,144 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class header_h3_testcase
*/
class header_h3_test extends all_checks {
/** @var string Check type */
protected $checktype = 'header_h3';
/** @var string Html fail 1 */
private $htmlfail1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>The header following an h3 must be h1, h2, h3 or h4.</title>
</head>
<body>
<h3>This is h3</h3>
<h5>This is h5</h5>
</body>
</html>
EOD;
/** @var string Html fail 2 */
private $htmlfail2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>The header following an h3 must be h1, h2, h3 or h4.</title>
</head>
<body>
<h3>This is h3</h3>
<h6>This is h6</h6>
</body>
</html>
EOD;
/** @var string Html pass 1 */
private $htmlpass1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>The header following an h3 must be h1, h2, h3 or h4.</title>
</head>
<body>
<h3>This is h3</h3>
<h1>This is h1</h1>
</body>
</html>
EOD;
/** @var string Html pass 2 */
private $htmlpass2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>The header following an h3 must be h1, h2, h3 or h4.</title>
</head>
<body>
<h3>This is h3</h3>
<h2>This is h2</h2>
</body>
</html>
EOD;
/** @var string Html pass 3 */
private $htmlpass3 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>The header following an h3 must be h1, h2, h3 or h4.</title>
</head>
<body>
<h3>This is h3</h3>
<h3>This is h3</h3>
</body>
</html>
EOD;
/** @var string Html pass 4 */
private $htmlpass4 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>The header following an h3 must be h1, h2, h3 or h4.</title>
</head>
<body>
<h3>This is h3</h3>
<h4>This is h4</h4>
</body>
</html>
EOD;
/**
* Test the header following an h3 must be h1, h2, h3 or h4.
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail1);
$this->assertTrue($results[0]->element->tagName == 'h5');
$results = $this->get_checker_results($this->htmlfail2);
$this->assertTrue($results[0]->element->tagName == 'h6');
$results = $this->get_checker_results($this->htmlpass1);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass3);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass3);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass4);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,86 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class headers_have_text_testcase
*/
class headers_have_text_test extends all_checks {
/** @var string Check type */
protected $checktype = 'headers_have_text';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Header has text - Fail</title>
</head>
<body>
<h1>This is a correct header</h1>
<p>Intrinsicly actualize web-enabled users and cross functional growth strategies. Monotonectally simplify B2B opportunities
vis-a-vis top-line processes.</p>
<h2></h2>
<p>Globally synergize ethical process improvements before go forward technology. Synergistically seize backward-compatible
quality vectors through magnetic sources. Distinctively reintermediate virtual "outside the box" thinking without market
positioning supply chains.</p>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Header has text - Fail</title>
</head>
<body>
<h1>This is a correct header</h1>
<p>Intrinsicly actualize web-enabled users and cross functional growth strategies. Monotonectally simplify B2B opportunities
vis-a-vis top-line processes.</p>
<h2>This header is also OK.</h2>
<p>Globally synergize ethical process improvements before go forward technology. Synergistically seize backward-compatible
quality vectors through magnetic sources. Distinctively reintermediate virtual "outside the box" thinking without market
positioning supply chains.</p>
</body>
</html>
EOD;
/**
* Test for headers not containing text
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'h2');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,74 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class i_is_not_used_testcase
*/
class i_is_not_used_test extends all_checks {
/** @var string Check type */
protected $checktype = 'i_is_not_used';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>i tags must not be used</title>
</head>
<body>
<i>This text is italicized</i>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>i tags must not be used</title>
</head>
<body>
<p>This text is not</p>
</body>
</html>
EOD;
/**
* Test for i tags being used
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'i');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,74 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class img_alt_is_different_testcase
*/
class img_alt_is_different_test extends all_checks {
/** @var string Check type */
protected $checktype = 'img_alt_is_different';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes need to be specified - fail</title>
</head>
<body>
<img src="rex.jpg" alt="rex.jpg">
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes need to be specified - fail</title>
</head>
<body>
<img src="rex.jpg" alt="this is an image of rex">
</body>
</html>
EOD;
/**
* Test for img alt attributes matching the src attribute
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'img');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,78 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class img_alt_is_too_long_testcase
*/
class img_alt_is_too_long_test extends all_checks {
/** @var string Check type */
protected $checktype = 'img_alt_is_too_long';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes must not be too long</title>
</head>
<body>
<img src="rex.jpg" alt="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent accumsan, ante varius viverra aliquam,
dolor risus scelerisque massa, ut lacinia ipsum felis id est. Nullam convallis odio ante, in commodo elit fermentum sed.
Vivamus ullamcorper tincidunt sagittis. Sed et semper sapien. Quisque malesuada lacus nec libero cursus, aliquam malesuada
neque ultricies. Cras sit amet enim vel orci tristique porttitor a vitae urna. Suspendisse mi leo, hendrerit et eleifend a,
mollis at ex. Maecenas eget magna nec sem dignissim pharetra vel nec ex. Donec in porta lectus. Aenean porttitor euismod
lectus, sodales eleifend ex egestas in. Donec sed metus sodales, lobortis velit quis, dictum arcu.">
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes must not be too long</title>
</head>
<body>
<img src="rex.jpg" alt="this is an image of rex">
</body>
</html>
EOD;
/**
* Test for image alt attributes being too long
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'img');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,73 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class img_alt_not_empty_in_anchor_testcase
*/
class img_alt_not_empty_in_anchor_test extends all_checks {
/** @var string Check type */
protected $checktype = 'img_alt_not_empty_in_anchor';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Anchor tags containing a nested img tag, must not have an empty alt attribute</title>
</head>
<body>
<a href="http://google.com"><img src="rex.jpg" alt=""></a>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Anchor tags containing a nested img tag, must not have an empty alt attribute</title>
</head>
<body>
<a href="http://google.com"><img src="rex.jpg" alt="Picture of Rex"></a>
</body>
</html>
EOD;
/**
* Test for >Anchor tags containing a nested img tag, must not have an empty alt attribute
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'img');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,163 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class img_alt_not_placeholder_testcase
*/
class img_alt_not_place_holder_test extends all_checks {
/** @var string Check type */
protected $checktype = 'img_alt_not_place_holder';
/** @var string Html fail 1 */
private $htmlfail1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
</head>
<body>
<img src="rex.jpg" alt="nbsp">
</body>
</html>
EOD;
/** @var string Html fail 2 */
private $htmlfail2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
</head>
<body>
<img src="rex.jpg" alt="&nbsp;">
</body>
</html>
EOD;
/** @var string Html fail 3 */
private $htmlfail3 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
</head>
<body>
<img src="rex.jpg" alt="spacer">
</body>
</html>
EOD;
/** @var string Html fail 4 */
private $htmlfail4 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
</head>
<body>
<img src="rex.jpg" alt="image">
</body>
</html>
EOD;
/** @var string Html fail 5 */
private $htmlfail5 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
</head>
<body>
<img src="rex.jpg" alt="img">
</body>
</html>
EOD;
/** @var string Html fail 6 */
private $htmlfail6 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
</head>
<body>
<img src="rex.jpg" alt="photo">
</body>
</html>
EOD;
/** @var string Html pass 1 */
private $htmlpass1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes must not match the string array specified in imgAltNotPlaceHolder - pass</title>
</head>
<body>
<img src="rex.jpg" alt="A mountian with a sunset">
</body>
</html>
EOD;
/**
* Notes: espacio & imagen & foto within the 'es' lang_string, all pass - they shouldn't.
*/
/**
* Test for the each en string specified in $strings - line 43 in imgAltNotPlaceHolder.
*/
public function test_failcheck(): void {
$results = $this->get_checker_results($this->htmlfail1);
$this->assertTrue($results[0]->element->tagName == 'img');
$results = $this->get_checker_results($this->htmlfail2);
$this->assertTrue($results[0]->element->tagName == 'img');
$results = $this->get_checker_results($this->htmlfail3);
$this->assertTrue($results[0]->element->tagName == 'img');
$results = $this->get_checker_results($this->htmlfail4);
$this->assertTrue($results[0]->element->tagName == 'img');
$results = $this->get_checker_results($this->htmlfail5);
$this->assertTrue($results[0]->element->tagName == 'img');
$results = $this->get_checker_results($this->htmlfail6);
$this->assertTrue($results[0]->element->tagName == 'img');
}
/**
* Test with alt that was not specified in the $strings array.
*/
public function test_passcheck1(): void {
$results = $this->get_checker_results($this->htmlpass1);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,94 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class test_css_text_has_contrast_testcase
*/
class img_has_alt_test extends all_checks {
/** @var string Check type */
public $checktype = 'img_has_alt';
/** @var string Html fail 1 */
private $htmlfail1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes need to be specified - fail</title>
</head>
<body>
<img src="rex.jpg" alt="">
</body>
</html>
EOD;
/** @var string Html fail 2 */
private $htmlfail2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes need to be specified - fail</title>
</head>
<body>
<img src="rex.jpg">
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image alt attributes need to be specified - fail</title>
</head>
<body>
<img src="rex.jpg" alt="this is an image of rex">
</body>
</html>
EOD;
/**
* Test for missing image alt text.
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail1);
$this->assertTrue($results[0]->element->tagName == 'img');
$results = $this->get_checker_results($this->htmlfail2);
$this->assertTrue($results[0]->element->tagName == 'img');
}
/**
* Test for present image alt text.
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass);
$this->assertTrue(count($results) == 0);
}
}
@@ -0,0 +1,81 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class img_with_map_has_use_map_test
*/
class img_with_map_has_use_map_test extends all_checks {
/** @var string Check type */
public $checktype = 'img_with_map_has_use_map';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Usemap cannot be used without a matching map - fail</title>
</head>
<body>
<img src="rex.jpg" usemap="#nousemap">
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Usemap with a matching map can be used - pass</title>
</head>
<body>
<img src="rex.jpg" usemap="#validmap">
<map id="validmap">
<area shape="shape1">
</map>
</body>
</html>
EOD;
/**
* Test for usemap attribute.
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'img');
}
/**
* Test for ismap attribute.
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,94 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class legend_text_not_empty_test
*/
class legend_text_not_empty_test extends all_checks {
/** @var string Check type */
public $checktype = 'legend_text_not_empty';
/** @var string Html fail 1 */
private $htmlfail1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Legend is empty - fail</title>
</head>
<body>
<legend></legend>
</body>
</html>
EOD;
/** @var string Html pass 2 */
private $htmlfail2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Legend contains only white space - fail</title>
</head>
<body>
<legend> </legend>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Legend containts text - pass</title>
</head>
<body>
<legend>This is a very descriptive legend</legend>
</body>
</html>
EOD;
/**
* Test for if legend is empty or only has white spaces.
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail1);
$this->assertTrue($results[0]->element->tagName == 'legend');
$results = $this->get_checker_results($this->htmlfail2);
$this->assertTrue($results[0]->element->tagName == 'legend');
}
/**
* Test for if legend has text.
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,81 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class marquee_is_not_used_test
*
* This check test does not currently exist
*/
class marquee_is_not_used_test extends all_checks {
/** @var string Check type */
public $checktype = 'marquee_is_not_used';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Marquee is used - fail</title>
</head>
<body>
<marquee>This should not work</marquee>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Marquee is not used - pass</title>
</head>
<body>
</body>
</html>
EOD;
/**
* Test for if marquee does exist.
*/
public function test_check_fail() {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'marquee');
}
/**
* Test for if marquee does not exist.
*/
public function test_check_pass() {
$results = $this->get_checker_results($this->htmlpass);
$this->assertTrue($results[0]->element->tagName == 'marquee');
}
}
@@ -0,0 +1,285 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class no_headings_test
*/
class no_headings_test extends all_checks {
/** @var string Check type */
public $checktype = 'no_headings';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Doc does not contain any h tag and has more than 1800 characters - fail</title>
</head>
<body>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut varius elit, vel euismod neque. Nunc vulputate elit at
lacus tincidunt tempus eget non urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Duis vel ipsum commodo, egestas erat ac, finibus orci. Nunc massa est, convallis at libero et, convallis rhoncus turpis.
Aliquam eu ipsum egestas, blandit odio quis, mattis enim. Sed libero ante, condimentum ut sodales eget, viverra vitae dolor.
Nulla venenatis, enim ut hendrerit placerat, neque tellus ultricies erat, a congue odio elit ac lorem. Duis quis nisl
placerat, pulvinar ipsum nec, pretium urna. Sed id hendrerit felis. Aliquam sit amet dui justo. Donec in quam sit amet
lectus mollis sodales. Etiam turpis purus, suscipit vel luctus quis, scelerisque id nisl. Cras elit mauris, ultricies ac
facilisis vitae, lacinia at purus.
Fusce pellentesque, turpis non tempus malesuada, lectus risus mollis metus, a gravida urna est sit amet diam. Fusce ut
sapien tempus, rutrum nisi in, consequat lacus. Aliquam pretium libero dignissim tempus scelerisque. Cras eget consequat
purus. Ut ultricies est urna, non euismod sem faucibus eget. Suspendisse venenatis iaculis augue, imperdiet sollicitudin
metus. Fusce vitae nisl arcu. Proin fermentum sollicitudin libero eu rutrum.
Praesent consequat hendrerit aliquam. Nunc sem turpis, vehicula et dui ac, gravida consequat quam. Sed vestibulum, risus et
sodales condimentum, purus nunc consectetur dolor, in tempor mi ex et ligula. Sed volutpat orci nisl, at scelerisque mauris
interdum ac. Maecenas sed sodales dui. Integer sed elit cursus, tincidunt neque sed, lobortis erat. Sed feugiat id nulla
quis auctor. Donec in rhoncus nunc. Vestibulum in sagittis sem. Aenean ut iaculis nisi.
</p>
</body>
</html>
EOD;
/** @var string Html pass 1 */
private $htmlpass1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Doc contains more than 1800 characters within a p tag and a h1 tag - pass</title>
</head>
<body>
<h1>This a h1 heading</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut varius elit, vel euismod neque. Nunc vulputate elit at
lacus tincidunt tempus eget non urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Duis vel ipsum commodo, egestas erat ac, finibus orci. Nunc massa est, convallis at libero et, convallis rhoncus turpis.
Aliquam eu ipsum egestas, blandit odio quis, mattis enim. Sed libero ante, condimentum ut sodales eget, viverra vitae dolor.
Nulla venenatis, enim ut hendrerit placerat, neque tellus ultricies erat, a congue odio elit ac lorem. Duis quis nisl
placerat, pulvinar ipsum nec, pretium urna. Sed id hendrerit felis. Aliquam sit amet dui justo. Donec in quam sit amet
lectus mollis sodales. Etiam turpis purus, suscipit vel luctus quis, scelerisque id nisl. Cras elit mauris, ultricies ac
facilisis vitae, lacinia at purus.
Fusce pellentesque, turpis non tempus malesuada, lectus risus mollis metus, a gravida urna est sit amet diam. Fusce ut
sapien tempus, rutrum nisi in, consequat lacus. Aliquam pretium libero dignissim tempus scelerisque. Cras eget consequat
purus. Ut ultricies est urna, non euismod sem faucibus eget. Suspendisse venenatis iaculis augue, imperdiet sollicitudin
metus. Fusce vitae nisl arcu. Proin fermentum sollicitudin libero eu rutrum.
Praesent consequat hendrerit aliquam. Nunc sem turpis, vehicula et dui ac, gravida consequat quam. Sed vestibulum, risus et
sodales condimentum, purus nunc consectetur dolor, in tempor mi ex et ligula. Sed volutpat orci nisl, at scelerisque mauris
interdum ac. Maecenas sed sodales dui. Integer sed elit cursus, tincidunt neque sed, lobortis erat. Sed feugiat id nulla
quis auctor. Donec in rhoncus nunc. Vestibulum in sagittis sem. Aenean ut iaculis nisi.
</p>
</body>
</html>
EOD;
/** @var string Html pass 2 */
private $htmlpass2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Doc contains more than 1800 characters within a p tag and a h2 tag - pass</title>
</head>
<body>
<h2>This a h2 heading</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut varius elit, vel euismod neque. Nunc vulputate elit at
lacus tincidunt tempus eget non urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Duis vel ipsum commodo, egestas erat ac, finibus orci. Nunc massa est, convallis at libero et, convallis rhoncus turpis.
Aliquam eu ipsum egestas, blandit odio quis, mattis enim. Sed libero ante, condimentum ut sodales eget, viverra vitae dolor.
Nulla venenatis, enim ut hendrerit placerat, neque tellus ultricies erat, a congue odio elit ac lorem. Duis quis nisl
placerat, pulvinar ipsum nec, pretium urna. Sed id hendrerit felis. Aliquam sit amet dui justo. Donec in quam sit amet
lectus mollis sodales. Etiam turpis purus, suscipit vel luctus quis, scelerisque id nisl. Cras elit mauris, ultricies ac
facilisis vitae, lacinia at purus.
Fusce pellentesque, turpis non tempus malesuada, lectus risus mollis metus, a gravida urna est sit amet diam. Fusce ut
sapien tempus, rutrum nisi in, consequat lacus. Aliquam pretium libero dignissim tempus scelerisque. Cras eget consequat
purus. Ut ultricies est urna, non euismod sem faucibus eget. Suspendisse venenatis iaculis augue, imperdiet sollicitudin
metus. Fusce vitae nisl arcu. Proin fermentum sollicitudin libero eu rutrum.
Praesent consequat hendrerit aliquam. Nunc sem turpis, vehicula et dui ac, gravida consequat quam. Sed vestibulum, risus et
sodales condimentum, purus nunc consectetur dolor, in tempor mi ex et ligula. Sed volutpat orci nisl, at scelerisque mauris
interdum ac. Maecenas sed sodales dui. Integer sed elit cursus, tincidunt neque sed, lobortis erat. Sed feugiat id nulla
quis auctor. Donec in rhoncus nunc. Vestibulum in sagittis sem. Aenean ut iaculis nisi.
</p>
</body>
</html>
EOD;
/** @var string Html pass 3 */
private $htmlpass3 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Doc contains more than 1800 characters within a p tag and a h3 tag - pass</title>
</head>
<body>
<h3>This a h3 heading</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut varius elit, vel euismod neque. Nunc vulputate elit at
lacus tincidunt tempus eget non urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Duis vel ipsum commodo, egestas erat ac, finibus orci. Nunc massa est, convallis at libero et, convallis rhoncus turpis.
Aliquam eu ipsum egestas, blandit odio quis, mattis enim. Sed libero ante, condimentum ut sodales eget, viverra vitae dolor.
Nulla venenatis, enim ut hendrerit placerat, neque tellus ultricies erat, a congue odio elit ac lorem. Duis quis nisl
placerat, pulvinar ipsum nec, pretium urna. Sed id hendrerit felis. Aliquam sit amet dui justo. Donec in quam sit amet
lectus mollis sodales. Etiam turpis purus, suscipit vel luctus quis, scelerisque id nisl. Cras elit mauris, ultricies ac
facilisis vitae, lacinia at purus.
Fusce pellentesque, turpis non tempus malesuada, lectus risus mollis metus, a gravida urna est sit amet diam. Fusce ut
sapien tempus, rutrum nisi in, consequat lacus. Aliquam pretium libero dignissim tempus scelerisque. Cras eget consequat
purus. Ut ultricies est urna, non euismod sem faucibus eget. Suspendisse venenatis iaculis augue, imperdiet sollicitudin
metus. Fusce vitae nisl arcu. Proin fermentum sollicitudin libero eu rutrum.
Praesent consequat hendrerit aliquam. Nunc sem turpis, vehicula et dui ac, gravida consequat quam. Sed vestibulum, risus et
sodales condimentum, purus nunc consectetur dolor, in tempor mi ex et ligula. Sed volutpat orci nisl, at scelerisque mauris
interdum ac. Maecenas sed sodales dui. Integer sed elit cursus, tincidunt neque sed, lobortis erat. Sed feugiat id nulla
quis auctor. Donec in rhoncus nunc. Vestibulum in sagittis sem. Aenean ut iaculis nisi.
</p>
</body>
</html>
EOD;
/** @var string Html pass 4 */
private $htmlpass4 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Doc contains more than 1800 characters within a p tag and a h4 tag - pass</title>
</head>
<body>
<h4>This a h4 heading</h4>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut varius elit, vel euismod neque. Nunc vulputate elit at
lacus tincidunt tempus eget non urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Duis vel ipsum commodo, egestas erat ac, finibus orci. Nunc massa est, convallis at libero et, convallis rhoncus turpis.
Aliquam eu ipsum egestas, blandit odio quis, mattis enim. Sed libero ante, condimentum ut sodales eget, viverra vitae dolor.
Nulla venenatis, enim ut hendrerit placerat, neque tellus ultricies erat, a congue odio elit ac lorem. Duis quis nisl
placerat, pulvinar ipsum nec, pretium urna. Sed id hendrerit felis. Aliquam sit amet dui justo. Donec in quam sit amet
lectus mollis sodales. Etiam turpis purus, suscipit vel luctus quis, scelerisque id nisl. Cras elit mauris, ultricies ac
facilisis vitae, lacinia at purus.
Fusce pellentesque, turpis non tempus malesuada, lectus risus mollis metus, a gravida urna est sit amet diam. Fusce ut
sapien tempus, rutrum nisi in, consequat lacus. Aliquam pretium libero dignissim tempus scelerisque. Cras eget consequat
purus. Ut ultricies est urna, non euismod sem faucibus eget. Suspendisse venenatis iaculis augue, imperdiet sollicitudin
metus. Fusce vitae nisl arcu. Proin fermentum sollicitudin libero eu rutrum.
Praesent consequat hendrerit aliquam. Nunc sem turpis, vehicula et dui ac, gravida consequat quam. Sed vestibulum, risus et
sodales condimentum, purus nunc consectetur dolor, in tempor mi ex et ligula. Sed volutpat orci nisl, at scelerisque mauris
interdum ac. Maecenas sed sodales dui. Integer sed elit cursus, tincidunt neque sed, lobortis erat. Sed feugiat id nulla
quis auctor. Donec in rhoncus nunc. Vestibulum in sagittis sem. Aenean ut iaculis nisi.
</p>
</body>
</html>
EOD;
/** @var string Html pass 5 */
private $htmlpass5 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Doc contains more than 1800 characters within a p tag and a h5 tag - pass</title>
</head>
<body>
<h5>This a h5 heading</h5>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut varius elit, vel euismod neque. Nunc vulputate elit at
lacus tincidunt tempus eget non urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Duis vel ipsum commodo, egestas erat ac, finibus orci. Nunc massa est, convallis at libero et, convallis rhoncus turpis.
Aliquam eu ipsum egestas, blandit odio quis, mattis enim. Sed libero ante, condimentum ut sodales eget, viverra vitae dolor.
Nulla venenatis, enim ut hendrerit placerat, neque tellus ultricies erat, a congue odio elit ac lorem. Duis quis nisl
placerat, pulvinar ipsum nec, pretium urna. Sed id hendrerit felis. Aliquam sit amet dui justo. Donec in quam sit amet
lectus mollis sodales. Etiam turpis purus, suscipit vel luctus quis, scelerisque id nisl. Cras elit mauris, ultricies ac
facilisis vitae, lacinia at purus.
Fusce pellentesque, turpis non tempus malesuada, lectus risus mollis metus, a gravida urna est sit amet diam. Fusce ut
sapien tempus, rutrum nisi in, consequat lacus. Aliquam pretium libero dignissim tempus scelerisque. Cras eget consequat
purus. Ut ultricies est urna, non euismod sem faucibus eget. Suspendisse venenatis iaculis augue, imperdiet sollicitudin
metus. Fusce vitae nisl arcu. Proin fermentum sollicitudin libero eu rutrum.
Praesent consequat hendrerit aliquam. Nunc sem turpis, vehicula et dui ac, gravida consequat quam. Sed vestibulum, risus et
sodales condimentum, purus nunc consectetur dolor, in tempor mi ex et ligula. Sed volutpat orci nisl, at scelerisque mauris
interdum ac. Maecenas sed sodales dui. Integer sed elit cursus, tincidunt neque sed, lobortis erat. Sed feugiat id nulla
quis auctor. Donec in rhoncus nunc. Vestibulum in sagittis sem. Aenean ut iaculis nisi.
</p>
</body>
</html>
EOD;
/** @var string Html pass 6 */
private $htmlpass6 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Doc contains more than 1800 characters within a p tag and a h6 tag - pass</title>
</head>
<body>
<h6>This a h6 heading</h6>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut varius elit, vel euismod neque. Nunc vulputate elit at
lacus tincidunt tempus eget non urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Duis vel ipsum commodo, egestas erat ac, finibus orci. Nunc massa est, convallis at libero et, convallis rhoncus turpis.
Aliquam eu ipsum egestas, blandit odio quis, mattis enim. Sed libero ante, condimentum ut sodales eget, viverra vitae dolor.
Nulla venenatis, enim ut hendrerit placerat, neque tellus ultricies erat, a congue odio elit ac lorem. Duis quis nisl
placerat, pulvinar ipsum nec, pretium urna. Sed id hendrerit felis. Aliquam sit amet dui justo. Donec in quam sit amet
lectus mollis sodales. Etiam turpis purus, suscipit vel luctus quis, scelerisque id nisl. Cras elit mauris, ultricies ac
facilisis vitae, lacinia at purus.
Fusce pellentesque, turpis non tempus malesuada, lectus risus mollis metus, a gravida urna est sit amet diam. Fusce ut
sapien tempus, rutrum nisi in, consequat lacus. Aliquam pretium libero dignissim tempus scelerisque. Cras eget consequat
purus. Ut ultricies est urna, non euismod sem faucibus eget. Suspendisse venenatis iaculis augue, imperdiet sollicitudin
metus. Fusce vitae nisl arcu. Proin fermentum sollicitudin libero eu rutrum.
Praesent consequat hendrerit aliquam. Nunc sem turpis, vehicula et dui ac, gravida consequat quam. Sed vestibulum, risus et
sodales condimentum, purus nunc consectetur dolor, in tempor mi ex et ligula. Sed volutpat orci nisl, at scelerisque mauris
interdum ac. Maecenas sed sodales dui. Integer sed elit cursus, tincidunt neque sed, lobortis erat. Sed feugiat id nulla
quis auctor. Donec in rhoncus nunc. Vestibulum in sagittis sem. Aenean ut iaculis nisi.
</p>
</body>
</html>
EOD;
/**
* Test for if heading exists where doc length is above 1800
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertNotEmpty($results);
}
/**
* Test for if marquee does not exist.
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass1);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass2);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass3);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass4);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass5);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass6);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,81 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class object_must_have_embeded_test
*/
class object_must_have_embed_test extends all_checks {
/** @var string Check type */
public $checktype = 'object_must_have_embed';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Embed element does not exist - fail</title>
</head>
<body>
<object>
</object>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Embed element exists - pass</title>
</head>
<body>
<object>
<embed>
</object>
</body>
</html>
EOD;
/**
* Test for missing embed element within object element.
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'object');
}
/**
* Test for present embed element within object element.
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,78 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class object_must_have_title_test
*/
class object_must_have_title_test extends all_checks {
/** @var string Check type */
public $checktype = 'object_must_have_title';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Object does not have title attribute - fail</title>
</head>
<body>
<object></object>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Object has title attribute - pass</title>
</head>
<body>
<object title="Object title"></object>
</body>
</html>
EOD;
/**
* Test for missing title attribute within object element.
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'object');
}
/**
* Test for present title attribute within object element.
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,159 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class object_must_have_valid_title_test
*/
class object_must_have_valid_title_test extends all_checks {
/** @var string Check type */
public $checktype = 'object_must_have_valid_title';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Title attribute does not exist within string array - fail</title>
</head>
<body>
<object title="This is not a perfectly valid title" ></object>
</body>
</html>
EOD;
/** @var string Html pass 1 */
private $htmlpass1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Title attribute must exist within string array - pass</title>
</head>
<body>
<object title="nbsp" ></object>
</body>
</html>
EOD;
/** @var string Html pass 3 */
private $htmlpass3 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Title attribute must exist within string array - pass</title>
</head>
<body>
<object title="object" ></object>
</body>
</html>
EOD;
/** @var string Html pass 4 */
private $htmlpass4 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Title attribute must exist within string array - pass</title>
</head>
<body>
<object title="spacer" ></object>
</body>
</html>
EOD;
/** @var string Html pass 5 */
private $htmlpass5 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Title attribute must exist within string array - pass</title>
</head>
<body>
<object title="image" ></object>
</body>
</html>
EOD;
/** @var string Html pass 6 */
private $htmlpass6 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Title attribute must exist within string array - pass</title>
</head>
<body>
<object title="img" ></object>
</body>
</html>
EOD;
/** @var string Html pass 7 */
private $htmlpass7 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Title attribute must exist within string array - pass</title>
</head>
<body>
<object title="photo" ></object>
</body>
</html>
EOD;
/**
* Test that embed element within object element.
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'object');
}
/**
* Test for embed element within object element.
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass1);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass3);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass4);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass5);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass6);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass7);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,90 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class strike_is_not_used_testcase
*/
class strike_is_not_used_test extends all_checks {
/** @var string Check type */
public $checktype = 'strike_is_not_used';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>strike tags must not be used</title>
</head>
<body>
<strike>This text is using the strike tag</strike>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>strike tags must not be used</title>
</head>
<body>
<s>This text is using the s tag</s>
</body>
</html>
EOD;
/** @var string Html pass 1 */
private $htmlpass1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<title>strike tags must not be used</title>
</head>
<body>
<del>This text is using the del tag</del>
</body>
</html>
EOD;
/**
* Test for b tags being used
*/
public function test_check(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'strike');
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass1);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,138 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class table_data_should_have_th_test
*/
class table_data_should_have_th_test extends all_checks {
/** @var string Check type */
public $checktype = 'table_data_should_have_th';
/** @var string Html fail 1 */
private $htmlfail1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Table should have at least one th - fail</title>
</head>
<body>
<table>
<thead>
<tr>
</tr>
</thead>
<tbody>
<tr>
<td>This is a tables data</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;
/** @var string Html fail 2 */
private $htmlfail2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Table should have at least one th - fail</title>
</head>
<body>
<table>
<tr>
</tr>
<tr>
<td>This is a tables data</td>
</tr>
</table>
</body>
</html>
EOD;
/** @var string Html pass 1 */
private $htmlpass1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Table should have at least one th - pass</title>
</head>
<body>
<table>
<thead>
<tr><th>This is table heading</th></tr>
</thead>
<tbody>
<tr><td>This is a tables data</td></tr>
</tbody>
</table>
</body>
</html>
EOD;
/** @var string Html pass 2 */
private $htmlpass2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Table should have at least one th - pass</title>
</head>
<body>
<table>
<tr><th>This is table heading</th></tr>
<tr><td>This is a tables data</td></tr>
</table>
</body>
</html>
EOD;
/**
* Test that th does not exist
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail1);
$this->assertTrue($results[0]->element->tagName == 'table');
$results = $this->get_checker_results($this->htmlfail2);
$this->assertTrue($results[0]->element->tagName == 'table');
}
/**
* Test that th does exist
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass1);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass2);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,82 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class table_summary_does_not_duplicate_caption_test
*/
class table_summary_does_not_duplicate_caption_test extends all_checks {
/** @var string Check type */
public $checktype = 'table_summary_does_not_duplicate_caption';
/** @var string Html fail */
private $htmlfail = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Summary attribute and caption element contain the same text - fail</title>
</head>
<body>
<table summary="testing">
<caption>testing</caption>
</table>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Summary attribute and caption element contain different text - pass</title>
</head>
<body>
<table summary="testing a summary">
<caption>testing a caption</caption>
</table>
</body>
</html>
EOD;
/**
* Test that caption and summary are equal
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail);
$this->assertTrue($results[0]->element->tagName == 'table');
}
/**
* Test that caption and summary are not equal
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,143 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class table_td_should_not_merge_test
*/
class table_td_should_not_merge_test extends all_checks {
/** @var string Check type */
public $checktype = 'table_td_should_not_merge';
/** @var string Html fail 1 */
private $htmlfail1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Rowspan exists - fail</title>
</head>
<body>
<table>
<thead>
<tr>
<th>1</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td rowspan="2">3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;
/** @var string Html fail 2 */
private $htmlfail2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Colspan exists - fail</title>
</head>
<body>
<table>
<thead>
<tr>
<th>1</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td colspan="2">3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;
/** @var string Html pass */
private $htmlpass = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>colspan or rowspan do not exist - pass</title>
</head>
<body>
<table>
<thead>
<tr>
<th>1</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;
/**
* Test for rowspan and colspan
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail1);
$this->assertNotEmpty($results);
$results = $this->get_checker_results($this->htmlfail2);
$this->assertNotEmpty($results);
}
/**
* Test for rowspan and colspan
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,187 @@
<?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/>.
/**
* tool_brickfield check test.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield\local\htmlchecker\common\checks;
defined('MOODLE_INTERNAL') || die();
require_once('all_checks.php');
/**
* Class table_th_should_have_scope_test
*/
class table_th_should_have_scope_test extends all_checks {
/** @var string Check type */
public $checktype = 'table_th_should_have_scope';
/** @var string Html fail 1 */
private $htmlfail1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Scope exists whilst specifying "col" - fail</title>
</head>
<body>
<table>
<thead>
<tr>
<th></th>
<th scope="col">1</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;
/** @var string Html fail 2 */
private $htmlfail2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Scope exists whilst specifying "row" - fail</title>
</head>
<body>
<table>
<thead>
<tr>
<th scope="col">1</th>
<th scope="col">2</th>
<th scope="col">3</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>3</td>
<th>4</th>
</tr>
<tr>
<td>4</td>
<td>5</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;
/** @var string Html pass 1 */
private $htmlpass1 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Scope exists whilst specifying something that isn't "col" or "row" - pass</title>
</head>
<body>
<table>
<thead>
<tr>
<th scope="col">1</th>
<th scope="col">2</th>
<th scope="col">3</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;
/** @var string Html pass 2 */
private $htmlpass2 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Scope is not specified - pass</title>
</head>
<body>
<table>
<thead>
<tr>
<th scope="col">1</th>
<th scope="col">2</th>
<th scope="col">3</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>3</td>
<th scope="row">4</th>
</tr>
<tr>
<td>4</td>
<td>5</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;
/**
* Test that th has scope that is equal to col or row
*/
public function test_check_fail(): void {
$results = $this->get_checker_results($this->htmlfail1);
$this->assertEquals(2, count($results));
$this->assertTrue($results[0]->element->tagName == 'th');
$this->assertTrue($results[1]->element->tagName == 'th');
$results = $this->get_checker_results($this->htmlfail2);
$this->assertEquals(1, count($results));
$this->assertTrue($results[0]->element->tagName == 'th');
}
/**
* Test that th has scope but != col || row. Test that th has no scope
*/
public function test_check_pass(): void {
$results = $this->get_checker_results($this->htmlpass1);
$this->assertEmpty($results);
$results = $this->get_checker_results($this->htmlpass2);
$this->assertEmpty($results);
}
}
@@ -0,0 +1,66 @@
<?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/>.
namespace tool_brickfield\local\tool;
/**
* Unit tests for {@activityresults tool_brickfield\local\tool\activityresults\tool}.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Jay Churchward (jay.churchward@poetopensource.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activityresults_test extends \advanced_testcase {
public function test_toolname(): void {
$this->resetAfterTest();
$object = new activityresults();
$output = $object->toolname();
$this->assertEquals($output, 'Activity breakdown summary');
}
public function test_toolshortname(): void {
$this->resetAfterTest();
$object = new activityresults();
$output = $object->toolshortname();
$this->assertEquals($output, 'Activity breakdown');
}
public function test_pluginname(): void {
$this->resetAfterTest();
$object = new activityresults();
$output = $object->pluginname();
$this->assertEquals($output, 'activityresults');
}
public function test_get_output(): void {
$this->resetAfterTest();
$category = $this->getDataGenerator()->create_category();
$filter = new filter(1, $category->id, 'activityresults', 3, 4);
$filter->courseids = [];
$object = new activityresults();
$object->set_filter($filter);
$output = $object->get_output();
$this->assertIsString($output);
$this->assertStringContainsString('Results per activity:', $output);
}
}
@@ -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/>.
namespace tool_brickfield\local\tool;
/**
* Unit tests for {@checktyperesults tool_brickfield\local\tool\checktyperesults\tool}.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Jay Churchward (jay.churchward@poetopensource.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class checktyperesults_test extends \advanced_testcase {
public function test_toolname(): void {
$this->resetAfterTest();
$object = new checktyperesults();
$output = $object->toolname();
$this->assertEquals($output, 'Content types summary');
}
public function test_toolshortname(): void {
$this->resetAfterTest();
$object = new checktyperesults();
$output = $object->toolshortname();
$this->assertEquals($output, 'Content types');
}
public function test_pluginname(): void {
$this->resetAfterTest();
$object = new checktyperesults();
$output = $object->pluginname();
$this->assertEquals($output, 'checktyperesults');
}
public function test_get_output(): void {
$this->resetAfterTest();
$category = $this->getDataGenerator()->create_category();
$filter = new filter(1, $category->id, 'checktyperesults', 3, 4);
$filter->courseids = [];
$object = new checktyperesults();
$object->set_filter($filter);
$object->get_data();
$output = $object->get_output();
$this->assertIsString($output);
$this->assertStringContainsString('Results per content type:', $output);
}
}
@@ -0,0 +1,66 @@
<?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/>.
namespace tool_brickfield\local\tool;
/**
* Unit tests for {@errors tool_brickfield\local\tool\errors\tool}.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Jay Churchward (jay.churchward@poetopensource.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class errors_test extends \advanced_testcase {
public function test_toolname(): void {
$this->resetAfterTest();
$object = new errors();
$output = $object->toolname();
$this->assertEquals($output, 'Error list summary');
}
public function test_toolshortname(): void {
$this->resetAfterTest();
$object = new errors();
$output = $object->toolshortname();
$this->assertEquals($output, 'Error list');
}
public function test_pluginname(): void {
$this->resetAfterTest();
$object = new errors();
$output = $object->pluginname();
$this->assertEquals($output, 'errors');
}
public function test_get_output(): void {
$this->resetAfterTest();
$category = $this->getDataGenerator()->create_category();
$filter = new filter(1, $category->id, 'errors', 3, 4);
$filter->courseids = [];
$object = new errors();
$object->set_filter($filter);
$output = $object->get_output();
$this->assertIsString($output);
$this->assertStringContainsString('Error details:', $output);
}
}
@@ -0,0 +1,106 @@
<?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/>.
namespace tool_brickfield\local\tool;
/**
* Unit tests for {@printable tool_brickfield\local\tool\printable\tool}.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Jay Churchward (jay.churchward@poetopensource.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class printable_test extends \advanced_testcase {
/**
* Test tool name.
*/
public function test_toolname(): void {
$this->resetAfterTest();
$object = new printable();
$output = $object->toolname();
$this->assertEquals($output, 'Summary report');
}
/**
* Test tool short name.
*/
public function test_toolshortname(): void {
$this->resetAfterTest();
$object = new printable();
$output = $object->toolshortname();
$this->assertEquals($output, 'Summary report');
}
/**
* Test plugin name.
*/
public function test_pluginname(): void {
$this->resetAfterTest();
$object = new printable();
$output = $object->pluginname();
$this->assertEquals($output, 'printable');
}
/**
* Can access.
*/
public function can_access() {
$this->resetAfterTest();
$category = $this->getDataGenerator()->create_category();
$filter = new filter(1, $category->id, 'tab', 3, 4);
$filter->courseids = [];
$object = new printable();
$output = $object->can_access($filter);
$this->assertFalse($output);
}
/**
* Test get output.
*/
public function test_get_output(): void {
$this->resetAfterTest();
$category = $this->getDataGenerator()->create_category();
$filter = new filter(1, $category->id, 'printable', 3, 4);
$filter->courseids = [];
$filter->target = 'html';
$object = new printable();
$object->set_filter($filter);
$output = $object->get_output();
$this->assertStringContainsString('<h3>Course PHPUnit test site</h3><div id=', $output);
$filter->target = '';
$object = new printable();
$object->set_filter($filter);
$output = $object->get_output();
$this->assertStringContainsString('<h3>Course PHPUnit test site</h3><a href=', $output);
$filter->target = 'html';
$object = new printable();
$object->set_filter($filter);
$output = $object->get_output();
$this->assertStringContainsString('<i class="icon fa fa-tachometer fa-fw " title="Total activities" '.
'role="img" aria-label="Total activities">', $output);
}
}
@@ -0,0 +1,41 @@
<?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/>.
namespace tool_brickfield;
/**
* Class tool_brickfield_manager_test
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manager_test extends \advanced_testcase {
/**
* Tests for the function manager::get_all_areas()
*/
public function test_get_areas(): void {
$this->resetAfterTest();
$areas = manager::get_all_areas();
$areaclassnames = array_map('get_class', $areas);
// Make sure the list of areas contains some known areas.
$this->assertContains(\tool_brickfield\local\areas\mod_assign\intro::class, $areaclassnames);
$this->assertContains(\tool_brickfield\local\areas\core_question\questiontext::class, $areaclassnames);
$this->assertContains(\tool_brickfield\local\areas\mod_choice\option::class, $areaclassnames);
}
}
@@ -0,0 +1,187 @@
<?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/>.
/**
* PHPUnit tool_brickfield tests
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Mike Churchward (mike@brickfieldlabs.ie)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_brickfield;
/**
* Unit tests for {@registration tool_brickfield\registration.php}.
* @group tool_brickfield
*/
class registration_test extends \advanced_testcase {
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/admin/tool/brickfield/tests/generator/mock_registration.php');
require_once($CFG->dirroot . '/admin/tool/brickfield/tests/generator/mock_brickfieldconnect.php');
}
/**
* Tests the state of the registration system when first installed.
* @throws \dml_exception
*/
public function test_initial_state(): void {
$this->resetAfterTest();
$regobj = new mock_registration();
// Initial state of system.
$this->assertFalse($regobj->toolkit_is_active());
$this->assertFalse($regobj->validation_pending());
$this->assertFalse($regobj->validation_error());
$this->assertEmpty($regobj->get_api_key());
$this->assertEmpty($regobj->get_secret_key());
}
/**
* Test the various states for setting registration keys.
* @throws \dml_exception
*/
public function test_set_keys_for_registration(): void {
$this->resetAfterTest();
$regobj = new mock_registration();
// State when invalid format keys are sent.
$this->assertFalse($regobj->set_keys_for_registration('123', 'abc'));
$this->assertTrue($regobj->is_not_entered());
$this->assertFalse($regobj->validation_pending());
$this->assertEmpty($regobj->get_api_key());
$this->assertEmpty($regobj->get_secret_key());
// State when valid format keys are sent.
$this->assertTrue($regobj->set_keys_for_registration(mock_brickfieldconnect::VALIDAPIKEY,
mock_brickfieldconnect::VALIDSECRETKEY));
$this->assertTrue($regobj->validation_pending());
$this->assertEquals($regobj->get_api_key(), mock_brickfieldconnect::VALIDAPIKEY);
$this->assertEquals($regobj->get_secret_key(), mock_brickfieldconnect::VALIDSECRETKEY);
}
/**
* Test the validation system through its several states.
* @throws \dml_exception
*/
public function test_validation(): void {
$this->resetAfterTest();
$regobj = new mock_registration();
// Set invalid format keys and validate the system.
$this->assertFalse($regobj->set_keys_for_registration('123', 'abc'));
// Run validate function. State should end up as 'NOT_ENTERED'.
$this->assertFalse($regobj->validate());
$this->assertTrue($regobj->is_not_entered());
// Set valid keys and validate the system.
$this->assertTrue($regobj->set_keys_for_registration(mock_brickfieldconnect::VALIDAPIKEY,
mock_brickfieldconnect::VALIDSECRETKEY));
// Run validate function. State should end up as valid, 'VALIDATED'.
$this->assertTrue($regobj->validate());
$this->assertTrue($regobj->toolkit_is_active());
$this->assertFalse($regobj->validation_pending());
$this->assertFalse($regobj->validation_error());
// Set invalid keys and validate the system.
$this->assertTrue($regobj->set_keys_for_registration('123456789012345678901234567890cd',
'cd123456789012345678901234567890'));
// Run validate function. State should end up as valid, not validated, 'ERROR'.
$this->assertTrue($regobj->validate());
$this->assertTrue($regobj->toolkit_is_active());
$this->assertTrue($regobj->validation_pending());
$this->assertTrue($regobj->validation_error());
}
/**
* Tests the system after validation grace periods expire.
* @throws \dml_exception
*/
public function test_validation_time_expiry(): void {
$this->resetAfterTest();
$regobj = new mock_registration();
// Set valid keys and validate the system.
$this->assertTrue($regobj->set_keys_for_registration(mock_brickfieldconnect::VALIDAPIKEY,
mock_brickfieldconnect::VALIDSECRETKEY));
// Run validate function. State should end up as valid, 'VALIDATED'.
$this->assertTrue($regobj->validate());
$this->assertTrue($regobj->toolkit_is_active());
// Invalidate the validation time.
$regobj->invalidate_validation_time();
// Run validate function. State should end up as valid, 'VALIDATED'.
$this->assertTrue($regobj->validate());
$this->assertTrue($regobj->toolkit_is_active());
// Set invalid keys and validate the system.
$this->assertTrue($regobj->set_keys_for_registration('123456789012345678901234567890cd',
'cd123456789012345678901234567890'));
// Run validate function. State should end up as valid, not validated, 'ERROR'.
$this->assertTrue($regobj->validate());
$this->assertTrue($regobj->toolkit_is_active());
$this->assertTrue($regobj->validation_pending());
$this->assertTrue($regobj->validation_error());
// Invalidate the validation time.
$regobj->invalidate_validation_time();
// Run validate function. State should end up as not valid.
$this->assertFalse($regobj->validate());
$this->assertFalse($regobj->toolkit_is_active());
}
/**
* Tests the system after summary data time periods expire.
* @throws \dml_exception
*/
public function test_summary_time_expiry(): void {
$this->resetAfterTest();
$regobj = new mock_registration();
// Set valid keys and validate the system.
$this->assertTrue($regobj->set_keys_for_registration(mock_brickfieldconnect::VALIDAPIKEY,
mock_brickfieldconnect::VALIDSECRETKEY));
// Run validate function. State should end up as valid, 'VALIDATED'.
$this->assertTrue($regobj->validate());
$this->assertTrue($regobj->toolkit_is_active());
// Invalidate the summary time.
$regobj->invalidate_summary_time();
// Run validate function. State should end up as not valid.
$this->assertFalse($regobj->validate());
$this->assertFalse($regobj->toolkit_is_active());
// Set invalid keys and validate the system.
$this->assertTrue($regobj->set_keys_for_registration('123456789012345678901234567890cd',
'cd123456789012345678901234567890'));
// Run validate function. State should end up as invalid.
$this->assertFalse($regobj->validate());
$this->assertFalse($regobj->toolkit_is_active());
// Set invalid keys and validate the system.
$this->assertTrue($regobj->set_keys_for_registration('123456789012345678901234567890cd',
'cd123456789012345678901234567890'));
// Mark the summary data as sent, and revalidate the system.
$regobj->mark_summary_data_sent();
// Run validate function. State should end up as valid, not validated, 'ERROR'.
$this->assertTrue($regobj->validate());
$this->assertTrue($regobj->toolkit_is_active());
$this->assertTrue($regobj->validation_pending());
$this->assertTrue($regobj->validation_error());
}
}
@@ -0,0 +1,305 @@
<?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/>.
namespace tool_brickfield;
/**
* Unit tests for {@scheduler tool_brickfield\scheduler.php}.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Jay Churchward (jay@brickfieldlabs.ie)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scheduler_test extends \advanced_testcase {
public function test_request_analysis(): void {
$this->resetAfterTest();
// I believe there is a bug where the code won't work with the default constructor values.
// Can't find data record in database table course.
// (SELECT id,category FROM {course} WHERE id = ?[array (0 => 0,)])
// There is no course with an id of 0 so it throws an error, however it is never used like this in the current code.
$object = new scheduler(1);
$output = $object->request_analysis();
$this->assertTrue($output);
$object = new scheduler(1, 1);
$output = $object->request_analysis();
$this->assertTrue($output);
$object = new scheduler(0, 2);
$output = $object->request_analysis();
$this->assertTrue($output);
}
public function test_mark_analyzed(): void {
$this->resetAfterTest();
$object = new scheduler();
$output = $object->mark_analyzed();
$this->assertTrue($output);
$object = new scheduler(1, 1);
$output = $object->mark_analyzed();
$this->assertTrue($output);
}
public function test_create_schedule(): void {
global $DB;
$this->resetAfterTest();
$object = new scheduler();
$output = $object->create_schedule();
$record = $DB->get_record($object::DATA_TABLE, ['contextlevel' => 50]);
$this->assertTrue($output);
$this->assertEquals($record->instanceid, 0);
$object = new scheduler(1, 1);
$output = $object->mark_analyzed();
$record = $DB->get_record($object::DATA_TABLE, ['contextlevel' => 1]);
$this->assertTrue($output);
$this->assertEquals($record->instanceid, 1);
}
public function test_delete_schedule(): void {
global $DB;
// Call create_record() to insert a record into the table.
$this->resetAfterTest();
$object = new scheduler();
$object->create_schedule();
$record = $DB->get_record($object::DATA_TABLE, ['contextlevel' => 50]);
// Assert that the record is in the table.
$this->assertEquals($record->instanceid, 0);
// Assert that the record is deleted after calling delete_schedule().
$output = $object->delete_schedule();
$record = $DB->get_record($object::DATA_TABLE, ['contextlevel' => 50]);
$this->assertTrue($output);
$this->assertFalse($record);
}
public function test_is_in_schedule(): void {
$this->resetAfterTest();
// This should assert to false as no record has been inserted.
$object = new scheduler();
$output = $object->is_in_schedule();
$this->assertFalse($output);
// This should assert to true because create_schedule inserts a record to the table.
$object->create_schedule();
$output = $object->is_in_schedule();
$this->assertTrue($output);
}
public function test_is_scheduled(): void {
$this->resetAfterTest();
// This should assert to false as no record has been inserted.
$object = new scheduler(1, 1);
$output = $object->is_scheduled();
$this->assertFalse($output);
// This should assert to false because the record has been created but not requested.
$object->create_schedule();
$output = $object->is_scheduled();
$this->assertFalse($output);
// This should assert to true because the record has been created and requested.
$object->create_schedule();
$object->request_analysis();
$output = $object->is_scheduled();
$this->assertTrue($output);
}
public function test_is_submitted(): void {
$this->resetAfterTest();
// This should assert to false as no record has been inserted.
$object = new scheduler(1, 1);
$output = $object->is_submitted();
$this->assertFalse($output);
// This should assert to false because the record has been created but not submitted.
$object->create_schedule();
$output = $object->is_submitted();
$this->assertFalse($output);
// This should assert to true because the record has been created and submitted.
$object->create_schedule();
$object->mark_analyzed();
$output = $object->is_submitted();
$this->assertTrue($output);
}
public function test_is_analyzed(): void {
$this->resetAfterTest();
// This should assert to false as no record has been inserted.
$object = new scheduler(1, 1);
$output = $object->is_analyzed();
$this->assertFalse($output);
// This should assert to false because the record has been created but not submitted.
$object->create_schedule();
$output = $object->is_analyzed();
$this->assertFalse($output);
// This should assert to true because the record has been created and submitted.
$object->create_schedule();
$object->mark_analyzed();
$output = $object->is_analyzed();
$this->assertTrue($output);
}
// Can't test because it's a protected function.
public function test_standard_search_params(): void {
}
// Can't test because it's a protected function.
public function test_get_contextid(): void {
}
public function test_get_datarecord(): void {
$this->resetAfterTest();
$object = new scheduler();
$output = $object->get_datarecord();
$this->assertEquals($output->contextlevel, 50);
$this->assertEquals($output->instanceid, 0);
$this->assertEquals($output->status, 0);
$object = new scheduler(1, 1);
$output = $object->get_datarecord(2);
$this->assertEquals($output->contextlevel, 1);
$this->assertEquals($output->instanceid, 1);
$this->assertEquals($output->status, 2);
$object = new scheduler(10, 143);
$output = $object->get_datarecord(5);
$this->assertEquals($output->contextlevel, 143);
$this->assertEquals($output->instanceid, 10);
$this->assertEquals($output->status, 5);
}
// No return statement.
public function test_process_scheduled_requests(): void {
}
public function test_initialize_schedule(): void {
global $DB;
$this->resetAfterTest();
$output = scheduler::initialize_schedule();
$record = $DB->get_record(scheduler::DATA_TABLE, ['contextlevel' => 50]);
$this->assertTrue($output);
$this->assertEquals($record->contextlevel, 50);
$output = scheduler::initialize_schedule(20);
$record = $DB->get_record(scheduler::DATA_TABLE, ['contextlevel' => 20]);
$this->assertTrue($output);
$this->assertEquals($record->contextlevel, 20);
}
public function test_request_course_analysis(): void {
$this->resetAfterTest();
$output = scheduler::request_course_analysis(1);
$this->assertTrue($output);
}
public function test_create_course_schedule(): void {
global $DB;
$this->resetAfterTest();
$output = scheduler::create_course_schedule(1);
$record = $DB->get_record(scheduler::DATA_TABLE, ['contextlevel' => 50]);
$this->assertTrue($output);
$this->assertEquals($record->instanceid, 1);
}
public function test_delete_course_schedule(): void {
global $DB;
$this->resetAfterTest();
scheduler::create_course_schedule(1);
$record = $DB->get_record(scheduler::DATA_TABLE, ['contextlevel' => 50]);
$this->assertEquals($record->instanceid, 1);
$output = scheduler::delete_course_schedule(1);
$record = $DB->get_record(scheduler::DATA_TABLE, ['contextlevel' => 50]);
$this->assertTrue($output);
$this->assertFalse($record);
}
public function test_is_course_in_schedule(): void {
$this->resetAfterTest();
// This should assert to false as no record has been inserted.
$output = scheduler::is_course_in_schedule(1);
$this->assertFalse($output);
// This should assert to true because create_schedule inserts a record to the table.
scheduler::create_course_schedule(1);
$output = scheduler::is_course_in_schedule(1);
$this->assertTrue($output);
}
public function test_is_course_scheduled(): void {
$this->resetAfterTest();
// This should assert to false as no record has been inserted.
$output = scheduler::is_course_scheduled(1);
$this->assertFalse($output);
// This should assert to false because the record has been created but not requested.
scheduler::create_course_schedule(1);
$output = scheduler::is_course_scheduled(1);
$this->assertFalse($output);
// This should assert to true because the record has been created and requested.
scheduler::create_course_schedule(1);
scheduler::request_course_analysis(1);
$output = scheduler::is_course_scheduled(1);
$this->assertTrue($output);
}
public function test_is_course_analyzed(): void {
$this->resetAfterTest();
$object = new scheduler(10, 1);
// This should assert to false as no record has been inserted.
$output = scheduler::is_course_analyzed(10);
$this->assertFalse($output);
// This should assert to false because the record has been created but not submitted.
scheduler::create_course_schedule(10);
$output = scheduler::is_course_analyzed(10);
$this->assertFalse($output);
// This should assert to true because the record has been created and submitted.
$object->create_schedule();
$object->mark_analyzed();
$output = $object->is_analyzed();
$this->assertTrue($output);
}
}
+168
View File
@@ -0,0 +1,168 @@
<?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/>.
namespace tool_brickfield;
use tool_brickfield\local\tool\filter;
use tool_brickfield\local\tool\tool;
/**
* Unit tests for {@tool tool_brickfield\local\tool\tool}.
*
* @package tool_brickfield
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @author Jay Churchward (jay.churchward@poetopensource.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_test extends \advanced_testcase {
/** @var string base 64 image */
protected $base64img = <<<EOF
<img src="data:image/gif;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P+goOXMv8+fhw/v739/f+8PD98fH/
8mJl+fn/9ZWb8/PzWlwv///6wWGbImAPgTEMImIN9gUFCEm/gDALULDN8PAD6atYdCTX9gUNKlj8wZAKUsAOzZz+UMAOsJAP/Z2ccMDA8PD/95eX5N
WvsJCOVNQPtfX/8zM8+QePLl38MGBr8JCP+zs9myn/8GBqwpAP/GxgwJCPny78lzYLgjAJ8vAP9fX/+MjMUcAN8zM/9wcM8ZGcATEL+QePdZWf/29u
c/P9cmJu9MTDImIN+/r7+/vz8/P8VNQGNugV8AAF9fX8swMNgTAFlDOICAgPNSUnNWSMQ5MBAQEJE3QPIGAM9AQMqGcG9vb6MhJsEdGM8vLx8fH98A
ANIWAMuQeL8fABkTEPPQ0OM5OSYdGFl5jo+Pj/+pqcsTE78wMFNGQLYmID4dGPvd3UBAQJmTkP+8vH9QUK+vr8ZWSHpzcJMmILdwcLOGcHRQUHxwcK9
PT9DQ0O/v70w5MLypoG8wKOuwsP/g4P/Q0IcwKEswKMl8aJ9fX2xjdOtGRs/Pz+Dg4GImIP8gIH0sKEAwKKmTiKZ8aB/f39Wsl+LFt8dgUE9PT5x5aH
BwcP+AgP+WltdgYMyZfyywz78AAAAAAAD///8AAP9mZv///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAKgALAAAAAA9AEQAAAj/AFEJHEiwoMGDCBMqXMiwocAbBww4nEhxoYkUpz
JGrMixogkfGUNqlNixJEIDB0SqHGmyJSojM1bKZOmyop0gM3Oe2liTISKMOoPy7GnwY9CjIYcSRYm0aVKSLmE6nfq05QycVLPuhDrxBlCtYJUqNAq2b
NWEBj6ZXRuyxZyDRtqwnXvkhACDV+euTeJm1Ki7A73qNWtFiF+/gA95Gly2CJLDhwEHMOUAAuOpLYDEgBxZ4GRTlC1fDnpkM+fOqD6DDj1aZpITp0dt
GCDhr+fVuCu3zlg49ijaokTZTo27uG7Gjn2P+hI8+PDPERoUB318bWbfAJ5sUNFcuGRTYUqV/3ogfXp1rWlMc6awJjiAAd2fm4ogXjz56aypOoIde4O
E5u/F9x199dlXnnGiHZWEYbGpsAEA3QXYnHwEFliKAgswgJ8LPeiUXGwedCAKABACCN+EA1pYIIYaFlcDhytd51sGAJbo3onOpajiihlO92KHGaUXGw
WjUBChjSPiWJuOO/LYIm4v1tXfE6J4gCSJEZ7YgRYUNrkji9P55sF/ogxw5ZkSqIDaZBV6aSGYq/lGZplndkckZ98xoICbTcIJGQAZcNmdmUc210hs3
5nCyJ58fgmIKX5RQGOZowxaZwYA+JaoKQwswGijBV4C6SiTUmpphMspJx9unX4KaimjDv9aaXOEBteBqmuuxgEHoLX6Kqx+yXqqBANsgCtit4FWQAEk
rNbpq7HSOmtwag5w57GrmlJBASEU18ADjUYb3ADTinIttsgSB1oJFfA63bduimuqKB1keqwUhoCSK374wbujvOSu4QG6UvxBRydcpKsav++Ca6G8A6P
r1x2kVMyHwsVxUALDq/krnrhPSOzXG1lUTIoffqGR7Goi2MAxbv6O2kEG56I7CSlRsEFKFVyovDJoIRTg7sugNRDGqCJzJgcKE0ywc0ELm6KBCCJo8D
IPFeCWNGcyqNFE06ToAfV0HBRgxsvLThHn1oddQMrXj5DyAQgjEHSAJMWZwS3HPxT/QMbabI/iBCliMLEJKX2EEkomBAUCxRi42VDADxyTYDVogV+wS
ChqmKxEKCDAYFDFj4OmwbY7bDGdBhtrnTQYOigeChUmc1K3QTnAUfEgGFgAWt88hKA6aCRIXhxnQ1yg3BCayK44EWdkUQcBByEQChFXfCB776aQsG0B
IlQgQgE8qO26X1h8cEUep8ngRBnOy74E9QgRgEAC8SvOfQkh7FDBDmS43PmGoIiKUUEGkMEC/PJHgxw0xH74yx/3XnaYRJgMB8obxQW6kL9QYEJ0FIF
gByfIL7/IQAlvQwEpnAC7DtLNJCKUoO/w45c44GwCXiAFB/OXAATQryUxdN4LfFiwgjCNYg+kYMIEFkCKDs6PKAIJouyGWMS1FSKJOMRB/BoIxYJIUX
FUxNwoIkEKPAgCBZSQHQ1A2EWDfDEUVLyADj5AChSIQW6gu10bE/JG2VnCZGfo4R4d0sdQoBAHhPjhIB94v/wRoRKQWGRHgrhGSQJxCS+0pCZbEhAAO
w==" alt="This is a bus." />';
EOF;
public function test_build_all_accessibilitytools(): void {
$tools = tool::build_all_accessibilitytools();
$this->assertEquals($tools['errors']::toolshortname(), 'Error list');
$this->assertEquals($tools['activityresults']::toolshortname(), 'Activity breakdown');
$this->assertEquals($tools['checktyperesults']::toolshortname(), 'Content types');
$this->assertEquals($tools['printable']::toolshortname(), 'Summary report');
$this->assertEquals($tools['advanced']::toolshortname(), 'Advanced');
}
public function test_data_is_valid(): void {
$object = $this->getMockForAbstractClass(tool::class);
$object->set_filter(new filter());
$output = $object->data_is_valid();
$this->assertFalse($output);
}
public function test_can_access(): void {
$this->resetAfterTest();
$category = $this->getDataGenerator()->create_category();
$filter = new filter(1, $category->id, 'tab', 3, 4);
$tool = $this->getMockForAbstractClass(tool::class);
$output = $tool->can_access($filter);
$this->assertFalse($output);
}
public function test_get_error_message(): void {
$tool = $this->getMockForAbstractClass(tool::class);
$output = $tool->get_error_message();
$this->assertEquals($output, '');
}
public function test_get_module_label(): void {
$output = tool::get_module_label('core_course');
$this->assertEquals($output, 'Course');
$output = tool::get_module_label('mod_book');
$this->assertEquals($output, 'Book');
}
public function test_toplevel_arguments(): void {
$this->resetAfterTest();
$category = $this->getDataGenerator()->create_category();
$filter = new filter(1, $category->id, 'tab', 3, 4);
$output = tool::toplevel_arguments();
$this->assertEmpty($output);
$output = tool::toplevel_arguments($filter);
$this->assertEquals($output['courseid'], 1);
$this->assertEquals($output['categoryid'], $category->id);
}
/**
* Base64 image provider.
* @return array
*/
public function base64_img_provider(): array {
$img = '<img src="myimage.jpg" />';
return [
'Image tag alone (base64)' => [
$this->base64img,
true,
],
'Image tag alone (link)' => [
$img,
false,
],
'Image tag in string (base64)' => [
"This is my image {$this->base64img}.",
true,
],
'Image tag in string (link)' => [
"This is my image {$img}.",
false,
],
'Image tag with string base64 in alt' => [
"<img src='myimage.jpg' alt='base64'/>",
false,
],
'base64 string in text' => [
"An example base 64 format string is 'data:image/gif;base64'./>",
false,
],
];
}
/**
* Test base 64 image provider.
* @dataProvider base64_img_provider
* @param string $content
* @param bool $expectation
*/
public function test_base64_img_detected(string $content, bool $expectation): void {
$this->assertEquals(
$expectation,
tool::base64_img_detected($content)
);
}
public function test_truncate_base64(): void {
$truncated = tool::truncate_base64($this->base64img);
$this->assertStringContainsString('<img src="data:image/gif;base64..."', $truncated);
}
}