Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserTest.php
1 <?php
2
3 /**
4 * @covers Parser::__construct
5 */
6 class ParserTest extends MediaWikiTestCase {
7 public function provideConstructorArguments() {
8 // Create a mock Config object that will satisfy ServiceOptions::__construct
9 $mockConfig = $this->createMock( 'Config' );
10 $mockConfig->method( 'has' )->willReturn( true );
11 $mockConfig->method( 'get' )->willReturn( 'I like otters.' );
12
13 $newArgs = [
14 $this->createMock( 'MediaWiki\Config\ServiceOptions' ),
15 $this->createMock( 'MagicWordFactory' ),
16 $this->createMock( 'Language' ),
17 $this->createMock( 'ParserFactory' ),
18 'a snail can sleep for three years',
19 $this->createMock( 'MediaWiki\Special\SpecialPageFactory' ),
20 $this->createMock( 'MediaWiki\Linker\LinkRendererFactory' ),
21 $this->createMock( 'NamespaceInfo' )
22 ];
23
24 $oldArgs = [
25 [],
26 $this->createMock( 'MagicWordFactory' ),
27 $this->createMock( 'Language' ),
28 $this->createMock( 'ParserFactory' ),
29 'a snail can sleep for three years',
30 $this->createMock( 'MediaWiki\Special\SpecialPageFactory' )
31 ];
32
33 yield 'current_args_without_namespace_info' => [
34 $newArgs,
35 ];
36
37 yield 'backward_compatible_args_minimal' => [
38 array_merge( $oldArgs ),
39 ];
40
41 yield 'backward_compatible_args_with_config' => [
42 array_merge( $oldArgs, [ $mockConfig ] ),
43 ];
44
45 yield 'backward_compatible_args_with_link_renderer' => [
46 array_merge( $oldArgs, [
47 $mockConfig,
48 $this->createMock( 'MediaWiki\Linker\LinkRendererFactory' )
49 ] ),
50 ];
51
52 yield 'backward_compatible_args_with_ns_info' => [
53 array_merge( $oldArgs, [
54 $mockConfig,
55 $this->createMock( 'MediaWiki\Linker\LinkRendererFactory' ),
56 $this->createMock( 'NamespaceInfo' )
57 ] ),
58 ];
59 }
60
61 /**
62 * @dataProvider provideConstructorArguments
63 * @covers Parser::__construct
64 */
65 public function testBackwardsCompatibleConstructorArguments( $args ) {
66 $parser = new Parser( ...$args );
67
68 $refObject = new ReflectionObject( $parser );
69
70 // If testing backwards compatibility, test service options separately
71 if ( is_array( $args[0] ) ) {
72 $svcOptionsProp = $refObject->getProperty( 'svcOptions' );
73 $svcOptionsProp->setAccessible( true );
74 $this->assertType( 'MediaWiki\Config\ServiceOptions',
75 $svcOptionsProp->getValue( $parser )
76 );
77 unset( $args[0] );
78
79 // If a Config is passed, the fact that we were able to create a ServiceOptions
80 // instance without error from it proves that this argument works.
81 if ( isset( $args[6] ) ) {
82 unset( $args[6] );
83 }
84 }
85
86 foreach ( $refObject->getProperties() as $prop ) {
87 $prop->setAccessible( true );
88 foreach ( $args as $idx => $mockTest ) {
89 if ( $prop->getValue( $parser ) === $mockTest ) {
90 unset( $args[$idx] );
91 }
92 }
93 }
94
95 $this->assertCount( 0, $args, 'Not all arguments to the Parser constructor were ' .
96 'found on the Parser object' );
97 }
98 }