1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Tests\Assert; |
4
|
|
|
|
5
|
|
|
use Wikibase\DataModel\Assert\RepositoryNameAssert; |
6
|
|
|
use Wikimedia\Assert\ParameterAssertionException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \Wikibase\DataModel\Assert\RepositoryNameAssert |
10
|
|
|
* |
11
|
|
|
* @license GPL-2.0+ |
12
|
|
|
*/ |
13
|
|
|
class RepositoryNameAssertTest extends \PHPUnit_Framework_TestCase { |
14
|
|
|
|
15
|
|
|
public function provideInvalidRepositoryNames() { |
16
|
|
|
return [ |
17
|
|
|
[ 'fo:o' ], |
18
|
|
|
[ 'foo:' ], |
19
|
|
|
[ ':foo' ], |
20
|
|
|
[ ':' ], |
21
|
|
|
[ 'fo.o' ], |
22
|
|
|
[ 'foo.' ], |
23
|
|
|
[ '.foo' ], |
24
|
|
|
[ '.' ], |
25
|
|
|
[ 123 ], |
26
|
|
|
[ null ], |
27
|
|
|
[ false ], |
28
|
|
|
[ [ 'foo' ] ], |
29
|
|
|
]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @dataProvider provideInvalidRepositoryNames |
34
|
|
|
*/ |
35
|
|
|
public function testGivenInvalidValue_assertParameterIsValidRepositoryNameFails( $value ) { |
36
|
|
|
$this->expectException( ParameterAssertionException::class ); |
37
|
|
|
RepositoryNameAssert::assertParameterIsValidRepositoryName( $value, 'test' ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function provideValidRepositoryNames() { |
41
|
|
|
return [ |
42
|
|
|
[ '' ], |
43
|
|
|
[ 'foo' ], |
44
|
|
|
[ '123' ], |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @dataProvider provideValidRepositoryNames |
50
|
|
|
*/ |
51
|
|
|
public function testGivenValidValue_assertParameterIsValidRepositoryNamePasses( $value ) { |
52
|
|
|
RepositoryNameAssert::assertParameterIsValidRepositoryName( $value, 'test' ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function provideInvalidRepositoryNameIndexedArrays() { |
56
|
|
|
return [ |
57
|
|
|
[ 'foo' ], |
58
|
|
|
[ [ 0 => 'foo' ] ], |
59
|
|
|
[ [ 'fo:0' => 'bar' ] ], |
60
|
|
|
[ [ 'foo:' => 'bar' ] ], |
61
|
|
|
[ [ ':foo' => 'bar' ] ], |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider provideInvalidRepositoryNameIndexedArrays |
67
|
|
|
*/ |
68
|
|
|
public function testGivenInvalidValue_assertParameterKeysAreValidRepositoryNamesFails( $values ) { |
69
|
|
|
$this->expectException( ParameterAssertionException::class ); |
70
|
|
|
RepositoryNameAssert::assertParameterKeysAreValidRepositoryNames( $values, 'test' ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function provideValidRepositoryNameIndexedArrays() { |
74
|
|
|
return [ |
75
|
|
|
[ [ 'foo' => 'bar' ] ], |
76
|
|
|
[ [ '' => 'bar' ] ], |
77
|
|
|
[ [ '' => 'bar', 'foo' => 'baz' ] ], |
78
|
|
|
[ [] ], |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @dataProvider provideValidRepositoryNameIndexedArrays |
84
|
|
|
*/ |
85
|
|
|
public function testGivenValidValue_assertParameterKeysAreValidRepositoryNamesPasses( array $values ) { |
86
|
|
|
RepositoryNameAssert::assertParameterKeysAreValidRepositoryNames( $values, 'test' ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|