Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / ParamValidator / TypeDefTest.php
1 <?php
2
3 namespace Wikimedia\ParamValidator;
4
5 /**
6 * @covers Wikimedia\ParamValidator\TypeDef
7 */
8 class TypeDefTest extends \PHPUnit\Framework\TestCase {
9
10 public function testMisc() {
11 $typeDef = $this->getMockBuilder( TypeDef::class )
12 ->setConstructorArgs( [ new SimpleCallbacks( [] ) ] )
13 ->getMockForAbstractClass();
14
15 $this->assertSame( [ 'foobar' ], $typeDef->normalizeSettings( [ 'foobar' ] ) );
16 $this->assertNull( $typeDef->getEnumValues( 'foobar', [], [] ) );
17 $this->assertSame( '123', $typeDef->stringifyValue( 'foobar', 123, [], [] ) );
18 }
19
20 public function testGetValue() {
21 $options = [ (object)[] ];
22
23 $callbacks = $this->getMockBuilder( Callbacks::class )->getMockForAbstractClass();
24 $callbacks->expects( $this->once() )->method( 'getValue' )
25 ->with(
26 $this->identicalTo( 'foobar' ),
27 $this->identicalTo( null ),
28 $this->identicalTo( $options )
29 )
30 ->willReturn( 'zyx' );
31
32 $typeDef = $this->getMockBuilder( TypeDef::class )
33 ->setConstructorArgs( [ $callbacks ] )
34 ->getMockForAbstractClass();
35
36 $this->assertSame(
37 'zyx',
38 $typeDef->getValue( 'foobar', [ ParamValidator::PARAM_DEFAULT => 'foo' ], $options )
39 );
40 }
41
42 public function testDescribeSettings() {
43 $typeDef = $this->getMockBuilder( TypeDef::class )
44 ->setConstructorArgs( [ new SimpleCallbacks( [] ) ] )
45 ->getMockForAbstractClass();
46
47 $this->assertSame(
48 [],
49 $typeDef->describeSettings(
50 'foobar',
51 [ ParamValidator::PARAM_TYPE => 'xxx' ],
52 []
53 )
54 );
55
56 $this->assertSame(
57 [
58 'default' => '123',
59 ],
60 $typeDef->describeSettings(
61 'foobar',
62 [ ParamValidator::PARAM_DEFAULT => 123 ],
63 []
64 )
65 );
66
67 $this->assertSame(
68 [
69 'default' => [ 'value' => '123' ],
70 ],
71 $typeDef->describeSettings(
72 'foobar',
73 [ ParamValidator::PARAM_DEFAULT => 123 ],
74 [ 'compact' => true ]
75 )
76 );
77 }
78
79 }