jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/349783 )
Change subject: Mock Api request results based on other extensions
......................................................................
Mock Api request results based on other extensions
The extensions arebn't loaded during tests, and the test should not
expect, that these extensions are installed. The result of the required
method is now mocked. However, because it was private before, it is now
protected to make it testable. Not the best solution, but it's ok for this
method and the easiest solution here.
Bug: T163631
Change-Id: I128719efe1b67d36d72a23d47b40188a1e62440a
---
M includes/QuickSearchLookup.php
M tests/phpunit/QuickSearchLookupTest.php
2 files changed, 26 insertions(+), 4 deletions(-)
Approvals:
Florianschmidtwelzow: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/QuickSearchLookup.php b/includes/QuickSearchLookup.php
index 426bdda..6cc11f9 100644
--- a/includes/QuickSearchLookup.php
+++ b/includes/QuickSearchLookup.php
@@ -258,7 +258,7 @@
* @param String $title The title to lookup
* @return array The page meta data
*/
- private function getPageMeta( $title ) {
+ protected function getPageMeta( $title ) {
if ( !$this->metadata ) {
$params = new DerivativeRequest(
$this->getRequest(),
diff --git a/tests/phpunit/QuickSearchLookupTest.php
b/tests/phpunit/QuickSearchLookupTest.php
index d76185d..f133c08 100644
--- a/tests/phpunit/QuickSearchLookupTest.php
+++ b/tests/phpunit/QuickSearchLookupTest.php
@@ -5,6 +5,19 @@
* @group Database
*/
class QuickSearchLooupTest extends MediaWikiTestCase {
+ private $apiResult = [
+ 'pageid' => 4,
+ 'ns' => 0,
+ 'title' => 'Test',
+ 'extract' => 'Test',
+ 'thumbnail' => [
+ 'source' =>
'https://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/test.png',
+ 'width' => 800,
+ 'height' => 649
+ ],
+ 'pageimage' => 'test.png'
+ ];
+
protected function setUp() {
parent::setUp();
QuickSearchLookup::setInstance( new MockQuickLookupTest() );
@@ -26,7 +39,16 @@
$context = new DerivativeContext( RequestContext::getMain() );
$context->setRequest( $request );
$context->setOutput( new OutputPage( $context ) );
- return new QuickSearchLookup( $context );
+ $mock = $this->getMockBuilder( QuickSearchLookup::class )
+ ->setConstructorArgs( [ $context ] )
+ ->setMethods( [ 'getPageMeta' ] )
+ ->getMock();
+ $mock->expects( $this->any() )
+ ->method( 'getPageMeta' )
+ ->withAnyParameters()
+ ->will( $this->returnValue( $this->apiResult ) );
+
+ return $mock;
}
/**
@@ -34,7 +56,7 @@
*/
public function testSetFirstResult( $title, $result ) {
$qsl = $this->makeQSL();
- $this->assertEquals( $qsl->setFirstResult( $title ), $result );
+ $this->assertEquals( $result, $qsl->setFirstResult( $title ) );
}
/**
@@ -43,7 +65,7 @@
public function testNeedsFirstResult( $title, $result ) {
$qsl = $this->makeQSL();
$qsl->setFirstResult( $title );
- $this->assertEquals( $qsl->needsFirstResult(), !$result );
+ $this->assertEquals( !$result, $qsl->needsFirstResult() );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/349783
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I128719efe1b67d36d72a23d47b40188a1e62440a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/QuickSearchLookup
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits