5 use MediaWikiCoversValidator;
7 use Wikimedia\TestingAccessWrapper;
16 use MediaWikiCoversValidator;
17 use \PHPUnit4And6Compat;
20 $config = new \HashConfig( [
24 $context = $this->createMock( \IContextSource::class );
26 ->willReturn( $config );
28 $main = $this->createMock( \ApiMain::class );
29 $main->expects( $this->once() )
30 ->method(
'getContext' )
33 $query = $this->createMock( \ApiQuery::class );
34 $query->expects( $this->once() )
36 ->willReturn( $main );
44 $title = $this->createMock( \Title::class );
45 $title->method(
'getPageLanguage' )
46 ->willReturn( $this->createMock( \Language::class ) );
48 $page = $this->createMock( \WikiPage::class );
49 $page->method(
'getTitle' )
52 $text =
'Text to cache';
55 $instance = TestingAccessWrapper::newFromObject( $this->
newInstance() );
56 $this->assertFalse( $instance->getFromCache( $page,
false ),
'is not cached yet' );
57 $instance->setCache( $page, $text );
58 $this->assertSame( $text, $instance->getFromCache( $page,
false ) );
63 $instance = TestingAccessWrapper::newFromObject( $this->
newInstance() );
65 $this->assertInternalType(
'string', $instance->getCacheMode( [] ) );
66 $this->assertNotEmpty( $instance->getExamplesMessages() );
67 $this->assertInternalType(
'string', $instance->getHelpUrls() );
69 $params = $instance->getAllowedParams();
70 $this->assertInternalType(
'array', $params );
87 $instance = TestingAccessWrapper::newFromObject( $this->
newInstance() );
89 $this->assertSame( $expected, $instance->getFirstSection( $text, $isPlainText ) );
94 'Plain text match' => [
95 "First\nsection \1\2... \1\2...",
99 'Plain text without a match' => [
106 "First\nsection <h1>...<h2>...",
110 'HTML without a match' => [
123 $instance = TestingAccessWrapper::newFromObject( $this->
newInstance() );
124 $instance->params = [
'sectionformat' => $format ];
126 $this->assertSame( $expected, $instance->doSections( $text ) );
131 $marker =
"\1\2$level\2\1";
135 "$marker Headline\t\nNext line",
137 "$marker Headline\t\nNext line",
140 "$marker Headline\t\nNext line",
142 "\n=== Headline ===\nNext line",
145 "$marker Headline\t\nNext line",
147 "\nHeadline\nNext line",
150 'Multiple matches' => [
151 "${marker}First\n${marker}Second",
153 "\n=== First ===\n\n=== Second ===",