PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / tests / HTMLPurifier / VarParser / FlexibleTest.php
blobea4469c72219ba24dbbc721c69b6f40cd028d284
1 <?php
3 class HTMLPurifier_VarParser_FlexibleTest extends HTMLPurifier_VarParserHarness
6 public function testValidate()
8 $this->assertValid('foobar', 'string');
9 $this->assertValid('foobar', 'text');
10 $this->assertValid('FOOBAR', 'istring', 'foobar');
11 $this->assertValid('FOOBAR', 'itext', 'foobar');
13 $this->assertValid(34, 'int');
15 $this->assertValid(3.34, 'float');
17 $this->assertValid(false, 'bool');
18 $this->assertValid(0, 'bool', false);
19 $this->assertValid(1, 'bool', true);
20 $this->assertValid('true', 'bool', true);
21 $this->assertValid('false', 'bool', false);
22 $this->assertValid('1', 'bool', true);
23 $this->assertInvalid(34, 'bool');
24 $this->assertInvalid(null, 'bool');
26 $this->assertValid(array('1', '2', '3'), 'list');
27 $this->assertValid('foo,bar, cow', 'list', array('foo', 'bar', 'cow'));
28 $this->assertValid('', 'list', array());
29 $this->assertValid("foo\nbar", 'list', array('foo', 'bar'));
30 $this->assertValid("foo\nbar,baz", 'list', array('foo', 'bar', 'baz'));
32 $this->assertValid(array('1' => true, '2' => true), 'lookup');
33 $this->assertValid(array('1', '2'), 'lookup', array('1' => true, '2' => true));
34 $this->assertValid('foo,bar', 'lookup', array('foo' => true, 'bar' => true));
35 $this->assertValid("foo\nbar", 'lookup', array('foo' => true, 'bar' => true));
36 $this->assertValid("foo\nbar,baz", 'lookup', array('foo' => true, 'bar' => true, 'baz' => true));
37 $this->assertValid('', 'lookup', array());
38 $this->assertValid(array(), 'lookup');
40 $this->assertValid(array('foo' => 'bar'), 'hash');
41 $this->assertValid(array(1 => 'moo'), 'hash');
42 $this->assertInvalid(array(0 => 'moo'), 'hash');
43 $this->assertValid('', 'hash', array());
44 $this->assertValid('foo:bar,too:two', 'hash', array('foo' => 'bar', 'too' => 'two'));
45 $this->assertValid("foo:bar\ntoo:two,three:free", 'hash', array('foo' => 'bar', 'too' => 'two', 'three' => 'free'));
46 $this->assertValid('foo:bar,too', 'hash', array('foo' => 'bar'));
47 $this->assertValid('foo:bar,', 'hash', array('foo' => 'bar'));
48 $this->assertValid('foo:bar:baz', 'hash', array('foo' => 'bar:baz'));
50 $this->assertValid(23, 'mixed');
54 public function testValidate_withMagicNumbers()
56 $this->assertValid('foobar', HTMLPurifier_VarParser::STRING);
59 public function testValidate_null()
61 $this->assertIdentical($this->parser->parse(null, 'string', true), null);
62 $this->expectException('HTMLPurifier_VarParserException');
63 $this->parser->parse(null, 'string', false);
68 // vim: et sw=4 sts=4