Minor test updates for more complete test coverage

The main motivation here is to cover the fallback code that was moved
in I20c814d. At some point we might touch this code again.

Bug: T238194
Change-Id: I0ab8a34b09790f42b10376eb3730c3b3c4ef53d2
This commit is contained in:
Thiemo Kreuz 2019-11-13 11:19:56 +01:00 committed by Thiemo Kreuz (WMDE)
parent 668ad80c58
commit d50c169612
2 changed files with 82 additions and 5 deletions

View file

@ -7,6 +7,7 @@ use ApiQuery;
use ApiQueryReferences;
use IContextSource;
use Title;
use Wikimedia\AtEase\AtEase;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\TestingAccessWrapper;
@ -40,7 +41,21 @@ class ApiQueryReferencesTest extends \MediaWikiUnitTestCase {
/**
* @covers ::recursiveFetchRefsFromDB
*/
public function testRecursiveFetchRefsFromDB() {
public function testRecursiveFetchRefsFromDB_fails() {
$api = $this->newApiQueryReferences();
$title = $this->createMock( Title::class );
$dbr = $this->createMock( IDatabase::class );
$dbr->method( 'selectField' )
->willReturn( false );
$this->assertFalse( $api->recursiveFetchRefsFromDB( $title, $dbr ) );
}
/**
* @covers ::recursiveFetchRefsFromDB
*/
public function testRecursiveFetchRefsFromDB_firstTry() {
$api = $this->newApiQueryReferences();
$title = $this->createMock( Title::class );
@ -51,6 +66,26 @@ class ApiQueryReferencesTest extends \MediaWikiUnitTestCase {
$this->assertSame( [ 'refs' => [] ], $api->recursiveFetchRefsFromDB( $title, $dbr ) );
}
/**
* @covers ::recursiveFetchRefsFromDB
*/
public function testRecursiveFetchRefsFromDB_secondTry() {
$api = $this->newApiQueryReferences();
$title = $this->createMock( Title::class );
$dbr = $this->createMock( IDatabase::class );
$dbr->expects( $this->exactly( 2 ) )
->method( 'selectField' )
->willReturnOnConsecutiveCalls( '', gzencode( '{"refs":{}}' ) );
// Code relies on gzdecode() returning false, but that reports an error now
AtEase::suppressWarnings();
$refs = $api->recursiveFetchRefsFromDB( $title, $dbr );
AtEase::restoreWarnings();
$this->assertSame( [ 'refs' => [] ], $refs );
}
/**
* @return ApiQueryReferences
*/

View file

@ -28,13 +28,31 @@ class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
CiteParserTagHooks::initialize( $parser );
}
/**
* @covers ::ref
*/
public function testRef_fails() {
$cite = $this->createMock( Cite::class );
$cite->method( 'ref' )
->willReturn( false );
$parser = $this->createMock( Parser::class );
$parser->extCite = $cite;
$frame = $this->createMock( PPFrame::class );
$html = CiteParserTagHooks::ref( null, [], $parser, $frame );
$this->assertSame( '<ref></ref>', $html );
}
/**
* @covers ::ref
*/
public function testRef() {
$cite = $this->createMock( Cite::class );
$cite->expects( $this->once() )
->method( 'ref' );
->method( 'ref' )
->willReturn( '<HTML>' );
$parserOutput = $this->createMock( ParserOutput::class );
$parserOutput->expects( $this->once() )
@ -47,7 +65,27 @@ class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
->willReturn( $parserOutput );
$parser->extCite = $cite;
CiteParserTagHooks::ref( null, [], $parser, $this->createMock( PPFrame::class ) );
$frame = $this->createMock( PPFrame::class );
$html = CiteParserTagHooks::ref( null, [], $parser, $frame );
$this->assertSame( '<HTML>', $html );
}
/**
* @covers ::references
*/
public function testReferences_fails() {
$cite = $this->createMock( Cite::class );
$cite->method( 'references' )
->willReturn( false );
$parser = $this->createMock( Parser::class );
$parser->extCite = $cite;
$frame = $this->createMock( PPFrame::class );
$html = CiteParserTagHooks::references( null, [], $parser, $frame );
$this->assertSame( '&lt;references/&gt;', $html );
}
/**
@ -56,12 +94,16 @@ class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
public function testReferences() {
$cite = $this->createMock( Cite::class );
$cite->expects( $this->once() )
->method( 'references' );
->method( 'references' )
->willReturn( '<HTML>' );
$parser = $this->createMock( Parser::class );
$parser->extCite = $cite;
CiteParserTagHooks::references( null, [], $parser, $this->createMock( PPFrame::class ) );
$frame = $this->createMock( PPFrame::class );
$html = CiteParserTagHooks::references( null, [], $parser, $frame );
$this->assertSame( '<HTML>', $html );
}
}