Debian Codegraph @

vendor/wikimedia/parsoid/tests/phpunit/Parsoid/Config/EnvTest.php

raw
1 <?php
2
3 namespace Test\Parsoid\Config;
4
5 use Wikimedia\Parsoid\Mocks\MockEnv;
6 use Wikimedia\Parsoid\Mocks\MockPageConfig;
7 use Wikimedia\Parsoid\Mocks\MockPageContent;
8 use Wikimedia\Parsoid\Mocks\MockSiteConfig;
9 use Wikimedia\Parsoid\Utils\Title;
10
11 /**
12 * @covers \Wikimedia\Parsoid\Config\Env
13 */
14 class EnvTest extends \PHPUnit\Framework\TestCase {
15
16 /**
17 * @dataProvider provideResolveTitle
18 */
19 public function testResolveTitle( $args, $expect, $ns = 4, $titleString = 'Wikipedia:Foo/bar/baz' ) {
20 $siteConfig = $this->getMockBuilder( MockSiteConfig::class )
21 ->setConstructorArgs( [ [] ] )
22 ->onlyMethods( [ 'namespaceHasSubpages' ] )
23 ->getMock();
24 $siteConfig->method( 'namespaceHasSubpages' )->willReturnCallback( static function ( $ns ) {
25 return $ns !== 0;
26 } );
27
28 $title = Title::newFromText( $titleString, $siteConfig );
29 $pageConfig = $this->getMockBuilder( MockPageConfig::class )
30 ->setConstructorArgs( [ $siteConfig, [], null ] )
31 ->onlyMethods( [ 'getLinkTarget', 'getRevisionContent' ] )
32 ->getMock();
33 $pageConfig->method( 'getLinkTarget' )->willReturn( $title );
34 $pageConfig->method( 'getRevisionContent' )->willReturn(
35 new MockPageContent( [ 'main' => 'bogus' ] )
36 );
37
38 $env = new MockEnv( [ 'pageConfig' => $pageConfig, 'siteConfig' => $siteConfig ] );
39 $this->assertSame( $expect, $env->resolveTitle( ...$args ) );
40 }
41
42 public function provideResolveTitle(): array {
43 return [
44 [ [ ' xxx ' ], 'xxx' ],
45 [ [ '#fragment' ], 'Wikipedia:Foo/bar/baz#fragment' ],
46 [ [ ':xxx' ], 'xxx' ],
47 [ [ '/abc' ], 'Wikipedia:Foo/bar/baz/abc' ],
48 [ [ '../abc' ], 'Wikipedia:Foo/bar/abc' ],
49 [ [ '../../abc' ], 'Wikipedia:Foo/abc' ],
50 [ [ '../../../abc' ], '../../../abc' ],
51
52 [ [ ':xxx' ], 'xxx', 0, 'Foo/bar/baz' ],
53 [ [ 'xxx///' ], 'xxx///', 0, 'Foo/bar/baz' ],
54 [ [ '/abc' ], '/abc', 0, 'Foo/bar/baz' ],
55 [ [ '../abc' ], '../abc', 0, 'Foo/bar/baz' ],
56 [ [ '../../abc' ], '../../abc', 0, 'Foo/bar/baz' ],
57 [ [ '../../../abc' ], '../../../abc', 0, 'Foo/bar/baz' ],
58
59 [ [ ':xxx', true ], ':xxx' ],
60 [ [ 'xxx///', true ], 'xxx///' ],
61 [ [ '/abc', true ], '/abc' ],
62 [ [ '../abc', true ], '../abc' ],
63 [ [ '../../abc', true ], '../../abc' ],
64 [ [ '../../../abc', true ], '../../../abc' ],
65
66 [ [ 'xxx///' ], 'xxx///' ], // Is this right?
67 [ [ '/xxx///' ], 'Wikipedia:Foo/bar/baz/xxx' ],
68 [ [ '../xxx///' ], 'Wikipedia:Foo/bar/xxx' ],
69
70 [ [ 'xxx///' ], 'xxx///', 0, 'Foo/bar/baz' ],
71 [ [ '/xxx///' ], '/xxx///', 0, 'Foo/bar/baz' ],
72 [ [ '../xxx///' ], '../xxx///', 0, 'Foo/bar/baz' ],
73
74 [ [ 'xxx///', true ], 'xxx///' ],
75 [ [ '/xxx///', true ], '/xxx///' ],
76 [ [ '../xxx///', true ], '../xxx///' ],
77 ];
78 }
79
80 }