Passed
Push — stringTitleTests ( 5b765d )
by no
02:13
created

TitleValidatorTest::titleProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 27
rs 8.8571
cc 1
eloc 21
nc 1
nop 0
1
<?php
2
3
namespace ValueValidators\Tests;
4
5
use PHPUnit_Framework_TestCase;
6
use ValueValidators\Error;
7
use ValueValidators\TitleValidator;
8
9
/**
10
 * @covers ValueValidators\TitleValidator
11
 *
12
 * @group ValueValidators
13
 * @group DataValueExtensions
14
 *
15
 * @licence GNU GPL v2+
16
 * @author Thiemo Mättig
17
 */
18
class TitleValidatorTest extends PHPUnit_Framework_TestCase {
19
20
	/**
21
	 * @dataProvider titleProvider
22
	 */
23
	public function testValidate( $value, $hasToExist, $expectedError ) {
24
		$validator = new TitleValidator();
25
		$validator->setOptions( array( 'hastoexist' => $hasToExist ) );
26
		$result = $validator->validate( $value );
27
28
		$this->assertEquals(
29
			$expectedError === null ? array() : array( $expectedError ),
30
			$result->getErrors()
31
		);
32
	}
33
34
	public function titleProvider() {
35
		$title = $this->getMockBuilder( 'Title' )
36
			->disableOriginalConstructor()
37
			->setMethods( array( 'exists' ) )
38
			->getMock();
39
		$title->expects( $this->any() )
40
			->method( 'exists' )
41
			->will( $this->returnValue( false ) );
42
43
		return array(
44
			array(
45
				'value' => null,
46
				'hasToExist' => false,
47
				'expectedErrors' => Error::newError( 'Not a title' )
48
			),
49
			array(
50
				'value' => $title,
51
				'hasToExist' => false,
52
				'expectedErrors' => null
53
			),
54
			array(
55
				'value' => $title,
56
				'hasToExist' => true,
57
				'expectedErrors' => Error::newError( 'Title does not exist' )
58
			),
59
		);
60
	}
61
62
}
63