Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/160202

Change subject: Use a mock GadgetRepo instead of LocalGadgetRepo::singleton()
......................................................................

Use a mock GadgetRepo instead of LocalGadgetRepo::singleton()

Change-Id: Ib324ff6acc371be1f901c783a8ddaaadd63dd7dd
---
M tests/backend/GadgetTest.php
1 file changed, 23 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gadgets 
refs/changes/02/160202/1

diff --git a/tests/backend/GadgetTest.php b/tests/backend/GadgetTest.php
index 1817682..611854c 100644
--- a/tests/backend/GadgetTest.php
+++ b/tests/backend/GadgetTest.php
@@ -7,13 +7,20 @@
 class GadgetTest extends MediaWikiTestCase {
 
        /**
+        * @return PHPUnit_Framework_MockObject_MockObject|GadgetRepo
+        */
+       private function getMockRepo() {
+               return $this->getMock( 'GadgetRepo' );
+       }
+
+       /**
         * @covers Gadget::__construct
         */
        public function testConstructor() {
-               $gadget = new Gadget( 'unittest', new LocalGadgetRepo );
+               $gadget = new Gadget( 'unittest', $this->getMockRepo() );
                $this->assertInstanceOf( 'Gadget', $gadget );
                $this->setExpectedException( 'MWException' );
-               new Gadget( 'invalid||id', new LocalGadgetRepo );
+               new Gadget( 'invalid||id', $this->getMockRepo() );
        }
 
        /**
@@ -120,14 +127,15 @@
        public function testGetters() {
                $data = self::getBoilerplateData();
                $now = wfTimestampNow();
-               $g = new Gadget( 'GadgetTest', LocalGadgetRepo::singleton() );
+               $repo = $this->getMockRepo();
+               $g = new Gadget( 'GadgetTest', $repo );
                $g->setSettings( $data['settings'] );
                $g->setModuleData( $data['module'] );
                $g->setTimestamp( $now );
 
                $this->assertEquals( $data, $g->getMetadata(), 'getMetadata' );
                $this->assertEquals( 'GadgetTest', $g->getId(), 'getId' );
-               $this->assertEquals( LocalGadgetRepo::singleton(), 
$g->getRepo(), 'getRepo' );
+               $this->assertSame( $repo, $g->getRepo(), 'getRepo' );
                $this->assertEquals( $now, $g->getTimestamp(), 'getTimestamp' );
                $this->assertEquals( $data['settings']['category'], 
$g->getCategory(), 'getCategory' );
                $this->assertEquals( $data['settings']['default'], 
$g->isEnabledByDefault(), 'isEnabledByDefault' );
@@ -145,7 +153,7 @@
         */
        public function testGetJSON() {
                $data = self::getBoilerplateData();
-               $g = new Gadget( 'GadgetTest', LocalGadgetRepo::singleton() );
+               $g = new Gadget( 'GadgetTest', $this->getMockRepo() );
                $g->setSettings( $data['settings'] );
                $g->setModuleData( $data['module'] );
                $this->assertEquals( FormatJson::encode( $data ), 
$g->getJSON(), 'JSON round-trips cleanly' );
@@ -153,7 +161,7 @@
                $oldData = $data;
                $data['settings']['skins'] = array_reverse( 
$data['settings']['skins'] );
                $data['module']['messages'] = array_reverse( 
$data['module']['messages'] );
-               $g = new Gadget( 'GadgetTest', LocalGadgetRepo::singleton() );
+               $g = new Gadget( 'GadgetTest', $this->getMockRepo() );
                $g->setSettings( $data['settings'] );
                $g->setModuleData( $data['module'] );
                $this->assertEquals( FormatJson::encode( $oldData ), 
$g->getJSON(), 'getJSON returns sorted arrays' );
@@ -161,7 +169,7 @@
                $data['module']['messages'][] = 'january';
                $data['settings']['skins'][] = 'vector';
                $data['settings']['skins'][] = 'vector';
-               $g = new Gadget( 'GadgetTest', LocalGadgetRepo::singleton() );
+               $g = new Gadget( 'GadgetTest', $this->getMockRepo() );
                $g->setSettings( $data['settings'] );
                $g->setModuleData( $data['module'] );
                $this->assertEquals( FormatJson::encode( $oldData ), 
$g->getJSON(), 'getJSON removes duplicates from arrays' );
@@ -174,7 +182,7 @@
        public function testMessageFunctions() {
                global $wgLang;
 
-               $g = new Gadget( 'gadgettest1', LocalGadgetRepo::singleton() );
+               $g = new Gadget( 'gadgettest1', $this->getMockRepo() );
 
                $this->assertEquals( 'gadget-gadgettest1-title', 
$g->getTitleMessageKey(), 'getTitleMessageKey' );
                $this->assertEquals( 'gadget-gadgettest1-desc', 
$g->getDescriptionMessageKey(), 'getDescriptionMessageKey' );
@@ -196,7 +204,7 @@
                $this->assertEquals( wfMessage( 'gadget-gadgettest1-title' 
)->plain(), $g->getTitleMessage(), 'getTitleMessage for existing message' );
                $this->assertEquals( wfMessage( 'gadget-gadgettest1-desc' 
)->plain(), $g->getDescriptionMessage(), 'getDescriptionMessage for existing 
message' );
 
-               $g = new Gadget( 'gadgettest2', LocalGadgetRepo::singleton() );
+               $g = new Gadget( 'gadgettest2', $this->getMockRepo() );
                $titleMsgTitle = Title::newFromText( 
'MediaWiki:gadget-gadgettest2-title' );
                $descMsgTitle = Title::newFromText( 
'MediaWiki:gadget-gadgettest2-desc' );
                if ( !$titleMsgTitle->exists() ) {
@@ -254,11 +262,11 @@
        public function testIsEnabledForUser() {
                $defaultOff = self::buildPropertiesArray( array( 'settings' => 
array( 'default' => false ) ) );
                $defaultOn = self::buildPropertiesArray( array( 'settings' => 
array( 'default' => true ) ) );
-               $gOff = new Gadget( 'GadgetTestOffByDefault', 
LocalGadgetRepo::singleton() );
+               $gOff = new Gadget( 'GadgetTestOffByDefault', 
$this->getMockRepo() );
                $gOff->setSettings( $defaultOff['settings'] );
                $gOff->setModuleData( $defaultOff['module'] );
 
-               $gOn = new Gadget( 'GadgetTestOnByDefault', 
LocalGadgetRepo::singleton() );
+               $gOn = new Gadget( 'GadgetTestOnByDefault', 
$this->getMockRepo() );
                $gOn->setSettings( $defaultOn['settings'] );
                $gOn->setModuleData( $defaultOn['module'] );
 
@@ -285,7 +293,7 @@
         */
        public function testIsAllowed() {
                $data = self::buildPropertiesArray( array( 'settings' => array( 
'rights' => array( 'foo', 'bar' ) ) ) );
-               $g = new Gadget( 'GadgetTest', LocalGadgetRepo::singleton() );
+               $g = new Gadget( 'GadgetTest', $this->getMockRepo() );
                $g->setSettings( $data['settings'] );
                $g->setModuleData( $data['module'] );
 
@@ -307,7 +315,7 @@
         */
        public function testSupportsSkin() {
                $data = self::buildPropertiesArray( array( 'settings' => array( 
'skins' => array( 'monobook', 'modern' ) ) ) );
-               $g = new Gadget( 'GadgetTest', LocalGadgetRepo::singleton() );
+               $g = new Gadget( 'GadgetTest', $this->getMockRepo() );
                $g->setSettings( $data['settings'] );
                $g->setModuleData( $data['module'] );
 
@@ -317,7 +325,7 @@
                $this->assertFalse( $g->supportsSkin( 
'viosrtubulviurbhujvwkctuljvilubhyjvca' ), 'supportsSkin() returns false for 
nonexistent skin' );
 
                $data2 = self::buildPropertiesArray( array( 'settings' => 
array( 'skins' => true ) ) );
-               $g2 = new Gadget( 'GadgetTest', LocalGadgetRepo::singleton() );
+               $g2 = new Gadget( 'GadgetTest', $this->getMockRepo() );
                $g2->setSettings( $data2['settings'] );
                $g2->setModuleData( $data2['module'] );
 
@@ -327,7 +335,7 @@
                $this->assertTrue( $g2->supportsSkin( 
'viosrtubulviurbhujvwkctuljvilubhyjvca' ), 'supportsSkin() returns true for 
nonexistent skin if skins=true' );
 
                $data3 = self::buildPropertiesArray( array( 'settings' => 
array( 'skins' => array() ) ) );
-               $g3 = new Gadget( 'GadgetTest', LocalGadgetRepo::singleton() );
+               $g3 = new Gadget( 'GadgetTest', $this->getMockRepo() );
                $g3->setSettings( $data3['settings'] );
                $g3->setModuleData( $data3['module'] );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/160202
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib324ff6acc371be1f901c783a8ddaaadd63dd7dd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gadgets
Gerrit-Branch: RL2
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to