themes: MDL-19077 start implementing moodle_core_renderer
Only a couple of methods implemented. Please review the API and tell me if you are not happy with the direction I am taking.
This commit is contained in:
@@ -135,6 +135,7 @@ class ArraysHaveSameValuesExpectation extends SimpleExpectation {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An Expectation that compares to objects, and ensures that for every field in the
|
||||
* expected object, there is a key of the same name in the actual object, with
|
||||
@@ -186,6 +187,72 @@ class CheckSpecifiedFieldsExpectation extends SimpleExpectation {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An Expectation that looks to see whether some HMTL contains a tag with a certain attribute.
|
||||
*
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class ContainsTagWithAttribute extends SimpleExpectation {
|
||||
const ATTRSREGEX = '(?:\s+\w+\s*=\s*["\'][^"\'>]*["\'])*';
|
||||
|
||||
protected $tag;
|
||||
protected $attribute;
|
||||
protected $value;
|
||||
|
||||
function __construct($tag, $attribute, $value, $message = '%s') {
|
||||
$this->SimpleExpectation($message);
|
||||
$this->tag = $tag;
|
||||
$this->attribute = $attribute;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
function test($html) {
|
||||
$regex = '/<' . preg_quote($this->tag) . self::ATTRSREGEX .
|
||||
'(?:\s+' . preg_quote($this->attribute) . '\s*=\s*["\']' . preg_quote($this->value) . '["\'])' .
|
||||
self::ATTRSREGEX . '\s*>/';
|
||||
return preg_match($regex, $html);
|
||||
}
|
||||
|
||||
function testMessage($html) {
|
||||
return 'Content [' . $html . '] does not contain the tag [' .
|
||||
$this->tag . '] with attribute [' . $this->attribute . '="' . $this->value . '"].';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An Expectation that looks to see whether some HMTL contains a tag with a certain text inside it.
|
||||
*
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class ContainsTagWithContents extends SimpleExpectation {
|
||||
const ATTRSREGEX = '(?:\s+\w+\s*=\s*["\'][^"\'>]*["\'])*';
|
||||
|
||||
protected $tag;
|
||||
protected $content;
|
||||
|
||||
function __construct($tag, $content, $message = '%s') {
|
||||
$this->SimpleExpectation($message);
|
||||
$this->tag = $tag;
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
function test($html) {
|
||||
$regex = '/<' . preg_quote($this->tag) . self::ATTRSREGEX . '\s*>' . preg_quote($this->content) .
|
||||
'<\/' . preg_quote($this->tag) . '>/';
|
||||
return preg_match($regex, $html);
|
||||
}
|
||||
|
||||
function testMessage($html) {
|
||||
return 'Content [' . $html . '] does not contain the tag [' .
|
||||
$this->tag . '] with contents [' . $this->content . '].';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class lets you write unit tests that access a separate set of test
|
||||
* tables with a different prefix. Only those tables you explicitly ask to
|
||||
@@ -419,6 +486,7 @@ class UnitTestCaseUsingDatabase extends UnitTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @package moodlecore
|
||||
* @subpackage simpletestex
|
||||
|
||||
Reference in New Issue
Block a user