|
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
|
|
|
[ 123 ], |
|
22
|
|
|
[ null ], |
|
23
|
|
|
[ false ], |
|
24
|
|
|
[ [ 'foo' ] ], |
|
25
|
|
|
]; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @dataProvider provideInvalidRepositoryNames |
|
30
|
|
|
*/ |
|
31
|
|
|
public function testGivenInvalidValue_assertParameterIsValidRepositoryNameFails( $value ) { |
|
32
|
|
|
$this->setExpectedException( ParameterAssertionException::class ); |
|
33
|
|
|
RepositoryNameAssert::assertParameterIsValidRepositoryName( $value, 'test' ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function provideValidRepositoryNames() { |
|
37
|
|
|
return [ |
|
38
|
|
|
[ '' ], |
|
39
|
|
|
[ 'foo' ], |
|
40
|
|
|
[ '123' ], |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @dataProvider provideValidRepositoryNames |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testGivenValidValue_assertParameterIsValidRepositoryNamePasses( $value ) { |
|
48
|
|
|
RepositoryNameAssert::assertParameterIsValidRepositoryName( $value, 'test' ); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function provideInvalidRepositoryNameIndexedArrays() { |
|
52
|
|
|
return [ |
|
53
|
|
|
[ 'foo' ], |
|
54
|
|
|
[ [ 0 => 'foo' ] ], |
|
55
|
|
|
[ [ 'fo:0' => 'bar' ] ], |
|
56
|
|
|
[ [ 'foo:' => 'bar' ] ], |
|
57
|
|
|
[ [ ':foo' => 'bar' ] ], |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @dataProvider provideInvalidRepositoryNameIndexedArrays |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testGivenInvalidValue_assertParameterKeysAreValidRepositoryNamesFails( $values ) { |
|
65
|
|
|
$this->setExpectedException( ParameterAssertionException::class ); |
|
66
|
|
|
RepositoryNameAssert::assertParameterKeysAreValidRepositoryNames( $values, 'test' ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function provideValidRepositoryNameIndexedArrays() { |
|
70
|
|
|
return [ |
|
71
|
|
|
[ [ 'foo' => 'bar' ] ], |
|
72
|
|
|
[ [ '' => 'bar' ] ], |
|
73
|
|
|
[ [ '' => 'bar', 'foo' => 'baz' ] ], |
|
74
|
|
|
[ [] ], |
|
75
|
|
|
]; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @dataProvider provideValidRepositoryNameIndexedArrays |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testGivenValidValue_assertParameterKeysAreValidRepositoryNamesPasses( array $values ) { |
|
82
|
|
|
RepositoryNameAssert::assertParameterKeysAreValidRepositoryNames( $values, 'test' ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|