Merge "Allow partially blocked users to import images"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserFactoryIntegrationTest.php
1 <?php
2
3 /**
4 * @covers ParserFactory
5 */
6 class ParserFactoryIntegrationTest extends MediaWikiIntegrationTestCase {
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 $mocks = [
14 [ 'the plural of platypus...' ],
15 $this->createMock( 'MagicWordFactory' ),
16 $this->createMock( 'Language' ),
17 '...is platypodes',
18 $this->createMock( 'MediaWiki\Special\SpecialPageFactory' ),
19 $mockConfig,
20 $this->createMock( 'MediaWiki\Linker\LinkRendererFactory' ),
21 ];
22
23 yield 'args_without_namespace_info' => [
24 $mocks,
25 ];
26 yield 'args_with_namespace_info' => [
27 array_merge( $mocks, [ $this->createMock( 'NamespaceInfo' ) ] ),
28 ];
29 }
30
31 /**
32 * @dataProvider provideConstructorArguments
33 * @covers ParserFactory::__construct
34 */
35 public function testBackwardsCompatibleConstructorArguments( $args ) {
36 $this->hideDeprecated( 'ParserFactory::__construct with Config parameter' );
37 $factory = new ParserFactory( ...$args );
38 $parser = $factory->create();
39
40 // It is expected that these are not present on the parser.
41 unset( $args[5] );
42 unset( $args[0] );
43
44 foreach ( ( new ReflectionObject( $parser ) )->getProperties() as $prop ) {
45 $prop->setAccessible( true );
46 foreach ( $args as $idx => $mockTest ) {
47 if ( $prop->getValue( $parser ) === $mockTest ) {
48 unset( $args[$idx] );
49 }
50 }
51 }
52
53 $this->assertCount( 0, $args, 'Not all arguments to the ParserFactory constructor were ' .
54 'found in Parser member variables' );
55 }
56 }