Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / ParamValidator / TypeDef / EnumDefTest.php
1 <?php
2
3 namespace Wikimedia\ParamValidator\TypeDef;
4
5 use Wikimedia\ParamValidator\ParamValidator;
6 use Wikimedia\ParamValidator\ValidationException;
7
8 /**
9 * @covers Wikimedia\ParamValidator\TypeDef\EnumDef
10 */
11 class EnumDefTest extends TypeDefTestCase {
12
13 protected static $testClass = EnumDef::class;
14
15 public function provideValidate() {
16 $settings = [
17 ParamValidator::PARAM_TYPE => [ 'a', 'b', 'c', 'd' ],
18 EnumDef::PARAM_DEPRECATED_VALUES => [
19 'b' => [ 'not-to-be' ],
20 'c' => true,
21 ],
22 ];
23
24 return [
25 'Basic' => [ 'a', 'a', $settings ],
26 'Deprecated' => [ 'c', 'c', $settings, [], [ [ 'deprecated-value', 'flag' => true ] ] ],
27 'Deprecated with message' => [
28 'b', 'b', $settings, [],
29 [ [ 'deprecated-value', 'flag' => [ 'not-to-be' ] ] ],
30 ],
31 'Bad value, non-multi' => [
32 'x', new ValidationException( 'test', 'x', $settings, 'badvalue', [] ),
33 $settings,
34 ],
35 'Bad value, non-multi but looks like it' => [
36 'x|y', new ValidationException( 'test', 'x|y', $settings, 'notmulti', [] ),
37 $settings,
38 ],
39 'Bad value, multi' => [
40 'x|y', new ValidationException( 'test', 'x|y', $settings, 'badvalue', [] ),
41 $settings + [ ParamValidator::PARAM_ISMULTI => true ],
42 [ 'values-list' => [ 'x|y' ] ],
43 ],
44 ];
45 }
46
47 public function provideGetEnumValues() {
48 return [
49 'Basic test' => [
50 [ ParamValidator::PARAM_TYPE => [ 'a', 'b', 'c', 'd' ] ],
51 [ 'a', 'b', 'c', 'd' ],
52 ],
53 ];
54 }
55
56 public function provideStringifyValue() {
57 return [
58 'Basic test' => [ 123, '123' ],
59 'Array' => [ [ 1, 2, 3 ], '1|2|3' ],
60 'Array with pipes' => [ [ 1, 2, '3|4', 5 ], "\x1f1\x1f2\x1f3|4\x1f5" ],
61 ];
62 }
63
64 }