DomainTest::testValidateInvalidBeginning()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 1
c 1
b 1
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Test for the domain definitions
5
 *
6
 * @author Sam Stenvall <[email protected]>
7
 * @copyright Copyright &copy; Sam Stenvall 2014-
8
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
9
 */
10
class DomainTest extends DefinitionTest
11
{
12
13
	/**
14
	 * @expectedException InvalidArgumentException
15
	 */
16
	public function testEmptyDefinition()
17
	{
18
		$this->_definition = new Whitelist\Definition\Domain('');
19
	}
20
	
21
	public function testValidate()
22
	{
23
		// do nothing here
24
	}
25
26
	/**
27
	 * @expectedException InvalidArgumentException
28
	 */
29
	public function testValidateInvalidCharacters()
30
	{
31
		$this->_definition = new Whitelist\Definition\Domain('ag*');
32
	}
33
	
34
	/**
35
	 * @expectedException InvalidArgumentException
36
	 */
37
	public function testValidateInvalidBeginning()
38
	{
39
		$this->_definition = new Whitelist\Definition\Domain('-otherwise-valid.com');
40
	}
41
	
42
	/**
43
	 * @expectedException InvalidArgumentException
44
	 */
45
	public function testValidateInvalidEnd()
46
	{
47
		$this->_definition = new Whitelist\Definition\Domain('otherwise-valid-.com');
48
	}
49
50
	/**
51
	 * @dataProvider provider
52
	 */
53
	public function testMatch($expected, $definition, $value)
54
	{
55
		$this->assertEquals($expected, $definition->match($value));
56
	}
57
58
	public function provider()
59
	{
60
		return array(
61
			array(true,  new Whitelist\Definition\WildcardDomain('*.example.com'), 'sub.example.com'),
62
			array(true,  new Whitelist\Definition\WildcardDomain('*.example.com'), 'anothersub.example.com'),
63
			array(false,  new Whitelist\Definition\WildcardDomain('*.example.com'), 'sub.example.net'),
64
			array(false,  new Whitelist\Definition\WildcardDomain('*.example.com'), 'sub.anotherexample.com'),
65
			array(false,  new Whitelist\Definition\WildcardDomain('*.example.com'), 'localhost'),
66
			array(true,  new Whitelist\Definition\Domain('localhost'), 'localhost'),
67
			array(true,  new Whitelist\Definition\Domain('example.com'), 'example.com'),
68
			array(false, new Whitelist\Definition\Domain('example.com'), 'sub.example.com'),
69
			array(false, new Whitelist\Definition\Domain('example.com'), 'example2.com'),
70
		);
71
	}
72
73
}
74