* Remove redundant getContent() cases that were all testing the same.
The redirect logic should indeed be tested, but exists in getContentObj(),
not getContent(). This test was also mocking getContentObj() thus not
actually testing what the case claims to test.
Fortunately, the right test already exists (testGetContentForRedirects),
so this is redundant.
* Add actual coverage of successful outcomes for getContent (previously
they were all error/null cases), with JS content, and with CSS content.
* Fix broken test case for "Bad content model". This was not working because
it mocked out getContentObj, thus it wasn't actually testing "bad content model",
but rather pointlessly duplicated the previous test case.
Fix it by actually making it use a WikitextContent object, which makes it
test the branch that handles incompatible content models.
Change-Id: I59af5318e536c730755352e9be8f995df1f56a86
protected static function fetchTitleInfo( IDatabase $db, array $pages, $fname = __METHOD__ ) {
$titleInfo = [];
$batch = new LinkBatch;
protected static function fetchTitleInfo( IDatabase $db, array $pages, $fname = __METHOD__ ) {
$titleInfo = [];
$batch = new LinkBatch;
public static function provideGetContent() {
yield 'Bad title' => [ null, '[x]' ];
public static function provideGetContent() {
yield 'Bad title' => [ null, '[x]' ];
- yield 'Dead redirect' => [ null, [
- 'text' => 'Dead redirect',
- 'title' => 'Dead_redirect',
- 'redirect' => 1,
- ] ];
- yield 'Bad content model' => [ null, [
- 'text' => 'MediaWiki:Wikitext',
- 'ns' => NS_MEDIAWIKI,
- 'title' => 'Wikitext',
- ] ];
yield 'No JS content found' => [ null, [
yield 'No JS content found' => [ null, [
- 'text' => 'MediaWiki:Script.js',
+ 'text' => 'MediaWiki:Foo.js',
- 'title' => 'Script.js',
- yield 'No CSS content found' => [ null, [
- 'text' => 'MediaWiki:Styles.css',
+
+ yield 'JS content' => [ 'code;', [
+ 'text' => 'MediaWiki:Foo.js',
- 'title' => 'Script.css',
- ] ];
+ 'title' => 'Foo.js',
+ ], new JavaScriptContent( 'code;' ) ];
+
+ yield 'CSS content' => [ 'code {}', [
+ 'text' => 'MediaWiki:Foo.css',
+ 'ns' => NS_MEDIAWIKI,
+ 'title' => 'Foo.css',
+ ], new CssContent( 'code {}' ) ];
+
+ yield 'Wikitext content' => [ null, [
+ 'text' => 'MediaWiki:Foo',
+ 'ns' => NS_MEDIAWIKI,
+ 'title' => 'Foo',
+ ], new WikitextContent( 'code;' ) ];
}
/**
* @dataProvider provideGetContent
*/
}
/**
* @dataProvider provideGetContent
*/
- public function testGetContent( $expected, $title ) {
+ public function testGetContent( $expected, $title, Content $contentObj = null ) {
$context = $this->getResourceLoaderContext( [], new EmptyResourceLoader );
$module = $this->getMockBuilder( ResourceLoaderWikiModule::class )
->setMethods( [ 'getContentObj' ] )->getMock();
$module->method( 'getContentObj' )
$context = $this->getResourceLoaderContext( [], new EmptyResourceLoader );
$module = $this->getMockBuilder( ResourceLoaderWikiModule::class )
->setMethods( [ 'getContentObj' ] )->getMock();
$module->method( 'getContentObj' )
+ ->willReturn( $contentObj );
if ( is_array( $title ) ) {
$title += [ 'ns' => NS_MAIN, 'id' => 1, 'len' => 1, 'redirect' => 0 ];
if ( is_array( $title ) ) {
$title += [ 'ns' => NS_MAIN, 'id' => 1, 'len' => 1, 'redirect' => 0 ];