[go: up one dir, main page]

Skip to content

Commit

Permalink
Move bad file tests to mediaParserTests
Browse files Browse the repository at this point in the history
Move resetting the bad file lookup service into addArticles, since it
needs to be reset whenever articles are added, and that happens in the
setUp of ParserTestFileSuite as well.

Bug: T75581
Change-Id: Iedc4cfe9b76762d64f9c0f9d813c64de5fb98dce
  • Loading branch information
arlolra committed Apr 25, 2022
1 parent 89767c4 commit baf72a9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 44 deletions.
16 changes: 6 additions & 10 deletions tests/parser/ParserTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,6 @@ public function setupDatabase( $nextTeardown = null ) {
* @return ScopedCallback The teardown object
*/
public function setupUploads( $nextTeardown = null ) {
$setup = [];
$teardown = [];

$this->checkSetupDone( 'setupDatabase' );
Expand Down Expand Up @@ -1698,15 +1697,6 @@ public function setupUploads( $nextTeardown = null ) {
$this->db->timestamp( '20010115123600' )
);

// The above calls to recordUpload3 call the bad file service which
// caches the wfMessage. Reset the service so that any
// "MediaWiki:bad image list" articles added get fetched
$setup[] = static function () {
MediaWikiServices::getInstance()->resetServiceForTesting( 'BadFileLookup' );
};

$teardown[] = $this->executeSetupSnippets( $setup );

return $this->createTeardownObject( $teardown, $nextTeardown );
}

Expand Down Expand Up @@ -1859,6 +1849,12 @@ public function addArticles(
// due to T144706
MediaWikiServices::getInstance()->getMainWANObjectCache()->clearProcessCache();

// Reset the service so that any "MediaWiki:bad image list" articles
// added get fetched
$teardown[] = static function () {
MediaWikiServices::getInstance()->resetServiceForTesting( 'BadFileLookup' );
};

$this->executeSetupSnippets( $teardown );

return $this->createTeardownObject( [ function () use ( $articles ) {
Expand Down
34 changes: 34 additions & 0 deletions tests/parser/legacyMediaParserTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ Template:test
This is a test template
!! endarticle

!! article
MediaWiki:bad image list
!! text
* [[File:Bad.jpg]] except [[Nasty page]]
!! endarticle

###
### Images
###
Expand Down Expand Up @@ -140,6 +146,34 @@ Image caption with pipe entity
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="20" width="180" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x"/></a><figcaption>one <i>two</i> <span typeof="mw:Entity">|</span> three</figcaption></figure>
!! end

!! test
Bad images - basic functionality
!! wikitext
[[File:Bad.jpg]]
!! html/php
<p><a href="/wiki/File:Bad.jpg" title="File:Bad.jpg">File:Bad.jpg</a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-badfile","message":"This image is on the bad file list."}]}'><a href="./Special:FilePath/Bad.jpg"><span class="mw-broken-media" resource="./File:Bad.jpg">File:Bad.jpg</span></a></span></p>
!! end

!! test
Bad images - T18039: text after bad image disappears
!! wikitext
Foo bar
[[File:Bad.jpg]]
Bar foo
!! html/php
<p>Foo bar
<a href="/wiki/File:Bad.jpg" title="File:Bad.jpg">File:Bad.jpg</a>
Bar foo
</p>
!! html/parsoid
<p>Foo bar
<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-badfile","message":"This image is on the bad file list."}]}'><a href="./Special:FilePath/Bad.jpg"><span class="mw-broken-media" resource="./File:Bad.jpg">File:Bad.jpg</span></a></span>
Bar foo</p>
!! end

!! test
Allow empty links in image captions (T62753)
!! options
Expand Down
38 changes: 38 additions & 0 deletions tests/parser/mediaParserTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ Template:test
This is a test template
!! endarticle

!! article
MediaWiki:bad image list
!! text
* [[File:Bad.jpg]] except [[Nasty page]]
!! endarticle

###
### Images
###
Expand Down Expand Up @@ -156,6 +162,38 @@ wgParserEnableLegacyMediaDOM=false
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="20" width="180" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x"/></a><figcaption>one <i>two</i> <span typeof="mw:Entity">|</span> three</figcaption></figure>
!! end

!! test
Bad images - basic functionality
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
[[File:Bad.jpg]]
!! html/php
<p><a href="/wiki/File:Bad.jpg" title="File:Bad.jpg">File:Bad.jpg</a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-badfile","message":"This image is on the bad file list."}]}'><a href="./Special:FilePath/Bad.jpg"><span class="mw-broken-media" resource="./File:Bad.jpg">File:Bad.jpg</span></a></span></p>
!! end

!! test
Bad images - T18039: text after bad image disappears
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
Foo bar
[[File:Bad.jpg]]
Bar foo
!! html/php
<p>Foo bar
<a href="/wiki/File:Bad.jpg" title="File:Bad.jpg">File:Bad.jpg</a>
Bar foo
</p>
!! html/parsoid
<p>Foo bar
<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-badfile","message":"This image is on the bad file list."}]}'><a href="./Special:FilePath/Bad.jpg"><span class="mw-broken-media" resource="./File:Bad.jpg">File:Bad.jpg</span></a></span>
Bar foo</p>
!! end

!! test
Allow empty links in image captions (T62753)
!! options
Expand Down
34 changes: 0 additions & 34 deletions tests/parser/parserTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ Template:=
<nowiki>=</nowiki>
!! endarticle

!!article
MediaWiki:bad image list
!!text
* [[File:Bad.jpg]] except [[Nasty page]]
!!endarticle

!! article
Template:inner list
!! text
Expand Down Expand Up @@ -22865,34 +22859,6 @@ comment
<a href="/index.php?title=ABC3D%25_%2B%2B&amp;action=edit&amp;redlink=1" class="new" title="ABC3D% ++ (page does not exist)">ABC3D% ++</a> <a href="/index.php?title=ABC3D%25_%2B%2B&amp;action=edit&amp;redlink=1" class="new" title="ABC3D% ++ (page does not exist)">+%20</a>
!! end

!! test
Bad images - basic functionality
!! wikitext
[[File:Bad.jpg]]
!! html/php
<p><a href="/wiki/File:Bad.jpg" title="File:Bad.jpg">File:Bad.jpg</a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-badfile","message":"This image is on the bad file list."}]}'><a href="./Special:FilePath/Bad.jpg"><span class="mw-broken-media" resource="./File:Bad.jpg">File:Bad.jpg</span></a></span></p>
!! end

!! test
Bad images - T18039: text after bad image disappears
!! wikitext
Foo bar
[[File:Bad.jpg]]
Bar foo
!! html/php
<p>Foo bar
<a href="/wiki/File:Bad.jpg" title="File:Bad.jpg">File:Bad.jpg</a>
Bar foo
</p>
!! html/parsoid
<p>Foo bar
<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-badfile","message":"This image is on the bad file list."}]}'><a href="./Special:FilePath/Bad.jpg"><span class="mw-broken-media" resource="./File:Bad.jpg">File:Bad.jpg</span></a></span>
Bar foo</p>
!! end

!! test
Verify that displaytitle works (T24501) no displaytitle
!! options
Expand Down

0 comments on commit baf72a9

Please sign in to comment.