jenkins-bot has submitted this change and it was merged.

Change subject: Add unit tests for getParserFunctionTargets and getBaseUrl
......................................................................


Add unit tests for getParserFunctionTargets and getBaseUrl

Change-Id: Iccfd2b511098a1686de52cd570e9f00aa26e3f62
---
M MassMessage.hooks.php
M MassMessage.php
A tests/MassMessageTest.php
3 files changed, 80 insertions(+), 0 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/MassMessage.hooks.php b/MassMessage.hooks.php
index c943498..122a551 100644
--- a/MassMessage.hooks.php
+++ b/MassMessage.hooks.php
@@ -68,4 +68,11 @@
                $extraStats['massmessage-queued-count'] = $queued;
                return true;
        }
+       /**
+        * Load our unit tests
+        */
+       public static function onUnitTestsList( &$files ) {
+               $files += glob( __DIR__ . '/tests/*Test.php' );
+               return true;
+       }
 }
diff --git a/MassMessage.php b/MassMessage.php
index 52c43d8..2c6cb8b 100644
--- a/MassMessage.php
+++ b/MassMessage.php
@@ -64,6 +64,7 @@
 
 $wgHooks['ParserFirstCallInit'][] = 'MassMessageHooks::onParserFirstCallInit';
 $wgHooks['SpecialStatsAddExtra'][] = 
'MassMessageHooks::onSpecialStatsAddExtra';
+$wgHooks['UnitTestsList'][] = 'MassMessageHooks::onUnitTestsList';
 
 $wgResourceModules['ext.MassMessage.special'] = array(
        'scripts' => 'ext.MassMessage.special.js',
diff --git a/tests/MassMessageTest.php b/tests/MassMessageTest.php
new file mode 100644
index 0000000..ecadda3
--- /dev/null
+++ b/tests/MassMessageTest.php
@@ -0,0 +1,72 @@
+<?php
+
+class MassMessageTest extends MediaWikiTestCase {
+
+       protected function setUp() {
+               parent::setUp();
+               $this->title = Title::newfromText( 'Input list' );
+               $this->page = WikiPage::factory( $this->title );
+       }
+
+       protected function tearDown() {
+               parent::tearDown();
+       }
+       /**
+        * Updates $this->title with the provided text
+        * @param  string $text
+        */
+       public static function updatePage( $page, $text ) {
+               $user = new User();
+               $page->doEdit( $text, "summary", 0, false, $user );
+       }
+
+       /**
+        * First value is the page text to create
+        * Second is the values we should check in the first array
+        * @return array
+        */
+       public static function provideGetParserFunctionTargets() {
+               global $wgDBname;
+               return array(
+                       array( '{{#target:User talk:Example}}', array( 'dbname' 
=> $wgDBname, 'title' => 'User talk:Example' ), ),
+               );
+       }
+
+       /**
+        * Tests MassMessage::getParserFunctionTargets
+        * @dataProvider provideGetParserFunctionTargets
+        * @param  string $text  Text of the page to create
+        * @param  array $check Stuff to check against
+        */
+       public function testGetParserFunctionTargets( $text, $check ) {
+               self::updatePage( $this->page, $text );
+               $data = MassMessage::getParserFunctionTargets( $this->title, 
RequestContext::getMain() );
+               $data = $data[0]; // We're just testing the first value
+               foreach ( $check as $key => $value ) {
+                       $this->assertEquals( $data[$key], $value );
+               }
+       }
+
+       /**
+        * First parameter is the raw url to parse, second is expected output
+        * @return array
+        */
+       public static function provideGetBaseUrl() {
+               return array(
+                       array( 'http://en.wikipedia.org', 'en.wikipedia.org' ),
+                       array( 'https://en.wikipedia.org/wiki/Blah', 
'en.wikipedia.org' ),
+                       array( '//test.wikidata.org/wiki/User talk:Example', 
'test.wikidata.org' ),
+               );
+       }
+
+       /**
+        * Tests MassMessage::getBaseUrl
+        * @dataProvider provideGetBaseUrl
+        * @param  string $url      raw url to parse
+        * @param  string $expected expected value
+        */
+       public function testGetBaseUrl( $url, $expected ) {
+               $output = MassMessage::getBaseUrl( $url );
+               $this->assertEquals( $output, $expected );
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iccfd2b511098a1686de52cd570e9f00aa26e3f62
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: MZMcBride <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to