Legoktm has uploaded a new change for review.

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

Change subject: Add some basic tests for LocalGadgetRepo
......................................................................

Add some basic tests for LocalGadgetRepo

Change-Id: I1e901ba832e262a2aa5cefbd9375257ca7137422
---
A tests/backend/LocalGadgetRepoTest.php
1 file changed, 70 insertions(+), 0 deletions(-)


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

diff --git a/tests/backend/LocalGadgetRepoTest.php 
b/tests/backend/LocalGadgetRepoTest.php
new file mode 100644
index 0000000..2f82134
--- /dev/null
+++ b/tests/backend/LocalGadgetRepoTest.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * @group Database
+ */
+class LocalGadgetRepoTest extends MediaWikiTestCase {
+
+       public function setUp() {
+               parent::setUp();
+               // Disable all object caching
+               $this->setMwGlobals( 'wgMemc', new EmptyBagOStuff() );
+               $this->createGadgets();
+       }
+
+       /**
+        * Puts some fake gadgets in the database
+        */
+       private function createGadgets() {
+               $rows = array(
+                       array(
+                               'gd_id' => 'unittestgadget1',
+                               'gd_blob' => 
'{"settings":{"rights":[],"default":false,"hidden":true,"shared":false,"category":"","skins":true},"module":{"scripts":["Foobar.js"],"styles":["Foobar.css"],"dependencies":["mediawiki.notification"],"messages":[],"position":"bottom"}}',
+                               'gd_timestamp' => '20140915102257',
+                               'gd_shared' => '0',
+                       ),
+                       array(
+                               'gd_id' => 'sharedgadget1',
+                               'gd_blob' => 
'{"settings":{"rights":[],"default":false,"hidden":true,"shared":true,"category":"","skins":true},"module":{"scripts":["Foobar.js"],"styles":["Foobar.css"],"dependencies":[],"messages":[],"position":"top"}}',
+                               'gd_timestamp' => '20120915102257',
+                               'gd_shared' => '1',
+                       ),
+               );
+
+               $dbw = wfGetDB( DB_MASTER );
+               // Clear out anything in the unittest_gadgets table...
+               $dbw->delete( 'gadgets', '*', __METHOD__ );
+
+               wfGetDB( DB_MASTER )->insert( 'gadgets', $rows, __METHOD__ );
+       }
+
+       /**
+        * @covers LocalGadgetRepo::__construct
+        */
+       public function testConstructor() {
+               // Takes no arguments
+               $r = new LocalGadgetRepo();
+               $this->assertInstanceOf( 'LocalGadgetRepo', $r );
+       }
+
+       /**
+        * @covers LocalGadgetRepo::loadAllData
+        */
+       public function testLoadAllData() {
+               $r = new LocalGadgetRepo();
+               $this->assertEquals( array( 'sharedgadget1', 'unittestgadget1' 
), $r->getGadgetIds() );
+       }
+
+       /**
+        * @covers LocalGadgetRepo::loadDataFor
+        */
+       public function testLoadDataFor() {
+               $r = new LocalGadgetRepo();
+               $g = $r->getGadget( 'unittestgadget1' );
+               $this->assertTrue( $g->isHidden() );
+               $this->assertFalse( $g->isShared() );
+               $this->assertEquals( array( 'mediawiki.notification' ), 
$g->getDependencies() );
+
+               $this->assertNull( $r->getGadget( 'thisdoesntexist' ) );
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1e901ba832e262a2aa5cefbd9375257ca7137422
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gadgets
Gerrit-Branch: RL2
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to