2008-03-22 21:06:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
protected function expectValidationException($msg)
|
|
|
|
{
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testAssertIsString()
|
|
|
|
{
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom('foo')->assertIsString();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testAssertNotNull()
|
|
|
|
{
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom('foo')->assertNotNull();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testAssertAlnum()
|
|
|
|
{
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom('foo2')->assertAlnum();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testAssertNotEmpty()
|
|
|
|
{
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->makeAtom('foo')->assertNotEmpty();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testAssertIsBool()
|
|
|
|
{
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->makeAtom(false)->assertIsBool();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testAssertIsArray()
|
|
|
|
{
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->makeAtom(array())->assertIsArray();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testAssertIsLookup()
|
|
|
|
{
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->makeAtom(array('foo' => true))->assertIsLookup();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
}
|
2008-12-06 09:24:59 +00:00
|
|
|
|
|
|
|
// vim: et sw=4 sts=4
|