.
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;
public function test_build_all_accessibilitytools() {
$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() {
$object = $this->getMockForAbstractClass(tool::class);
$object->set_filter(new filter());
$output = $object->data_is_valid();
$this->assertFalse($output);
}
public function test_can_access() {
$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() {
$tool = $this->getMockForAbstractClass(tool::class);
$output = $tool->get_error_message();
$this->assertEquals($output, '');
}
public function test_get_module_label() {
$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() {
$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 = '
';
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' => [
"
",
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) {
$this->assertEquals(
$expectation,
tool::base64_img_detected($content)
);
}
public function test_truncate_base64() {
$truncated = tool::truncate_base64($this->base64img);
$this->assertStringContainsString('