2008-03-22 21:06:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-03-22 21:06:55 +00:00
|
|
|
protected function expectValidationException($msg) {
|
|
|
|
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
protected function makeAtom($value) {
|
2008-03-22 21:06:55 +00:00
|
|
|
$obj = new stdClass();
|
|
|
|
$obj->property = $value;
|
|
|
|
// Note that 'property' and 'context' are magic wildcard values
|
|
|
|
return new HTMLPurifier_ConfigSchema_ValidatorAtom('context', $obj, 'property');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertIsString() {
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom('foo')->assertIsString();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertIsStringFail() {
|
2008-03-23 01:06:35 +00:00
|
|
|
$this->expectValidationException("Property in context must be a string");
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom(3)->assertIsString();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertNotNull() {
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom('foo')->assertNotNull();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertNotNullFail() {
|
2008-03-23 01:06:35 +00:00
|
|
|
$this->expectValidationException("Property in context must not be null");
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom(null)->assertNotNull();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertAlnum() {
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom('foo2')->assertAlnum();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertAlnumFail() {
|
2008-03-23 01:06:35 +00:00
|
|
|
$this->expectValidationException("Property in context must be alphanumeric");
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom('%a')->assertAlnum();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertAlnumFailIsString() {
|
2008-03-23 01:06:35 +00:00
|
|
|
$this->expectValidationException("Property in context must be a string");
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom(3)->assertAlnum();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertNotEmpty() {
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom('foo')->assertNotEmpty();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertNotEmptyFail() {
|
2008-03-23 01:06:35 +00:00
|
|
|
$this->expectValidationException("Property in context must not be empty");
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom('')->assertNotEmpty();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertIsBool() {
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->makeAtom(false)->assertIsBool();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertIsBoolFail() {
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->expectValidationException("Property in context must be a boolean");
|
|
|
|
$this->makeAtom('0')->assertIsBool();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertIsArray() {
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->makeAtom(array())->assertIsArray();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertIsArrayFail() {
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->expectValidationException("Property in context must be an array");
|
|
|
|
$this->makeAtom('asdf')->assertIsArray();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertIsLookup() {
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->makeAtom(array('foo' => true))->assertIsLookup();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertIsLookupFail() {
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->expectValidationException("Property in context must be a lookup array");
|
|
|
|
$this->makeAtom(array('foo' => 4))->assertIsLookup();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAssertIsLookupFailIsArray() {
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->expectValidationException("Property in context must be an array");
|
|
|
|
$this->makeAtom('asdf')->assertIsLookup();
|
|
|
|
}
|
2008-03-22 21:06:55 +00:00
|
|
|
}
|