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

Change subject: Refactor and add tests for MassMessageSubmitJob
......................................................................


Refactor and add tests for MassMessageSubmitJob

Change-Id: I6beb37b306bc0ed2c7c71f37721fffabe3c11c92
---
M includes/job/MassMessageSubmitJob.php
A tests/job/MassMessageSubmitJobTest.php
2 files changed, 75 insertions(+), 6 deletions(-)

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



diff --git a/includes/job/MassMessageSubmitJob.php 
b/includes/job/MassMessageSubmitJob.php
index 0032d06..41e806e 100644
--- a/includes/job/MassMessageSubmitJob.php
+++ b/includes/job/MassMessageSubmitJob.php
@@ -19,6 +19,19 @@
         * @return bool
         */
        public function run() {
+               $jobsByTarget = $this->getJobs();
+
+               foreach ( $jobsByTarget as $wiki => $jobs ) {
+                       JobQueueGroup::singleton( $wiki )->push( $jobs );
+               }
+
+               return true;
+       }
+
+       /**
+        * @return Job[][]
+        */
+       public function getJobs() {
                $data = $this->params['data'];
                $pages = $this->params['pages'];
                $jobsByTarget = array();
@@ -31,11 +44,6 @@
                        $jobsByTarget[$page['wiki']][] = new MassMessageJob( 
$title, $data );
                }
 
-               foreach ( $jobsByTarget as $wiki => $jobs ) {
-                       JobQueueGroup::singleton( $wiki )->push( $jobs );
-               }
-
-               return true;
+               return $jobsByTarget;
        }
-
 }
diff --git a/tests/job/MassMessageSubmitJobTest.php 
b/tests/job/MassMessageSubmitJobTest.php
new file mode 100644
index 0000000..a09766d
--- /dev/null
+++ b/tests/job/MassMessageSubmitJobTest.php
@@ -0,0 +1,61 @@
+<?php
+
+class MassMessageSubmitJobTest extends MediaWikiTestCase {
+
+       /**
+        * @covers MassMessageSubmitJob::getJobs
+        * @dataProvider provideGetJobs
+        */
+       public function testGetJobs( $data, $pages ) {
+               $params = array( 'data' => $data, 'pages' => $pages );
+               $job = new MassMessageSubmitJob(
+                       $this->getMock( 'Title' ),
+                       $params
+               );
+
+               $jobsByTarget = $job->getJobs();
+               $count = 0;
+               foreach ( $jobsByTarget as $wiki => $jobs ) {
+                       /** @var MassMessageJob $job */
+                       foreach ( $jobs as $job ) {
+                               $count++;
+                               $this->assertInstanceOf( 'MassMessageJob', $job 
);
+                               $params = $job->getParams();
+                               foreach ( $data as $key => $val ) {
+                                       $this->assertArrayHasKey( $key, $params 
);
+                                       $this->assertEquals( $val, 
$params[$key] );
+                               }
+
+                               $found = false;
+                               foreach ( $pages as $info ) {
+                                       if ( $info['wiki'] === $wiki && 
$info['title'] === $params['title'] ) {
+                                               $found = true;
+                                               break;
+                                       }
+                               }
+
+                               $this->assertTrue( $found );
+                       }
+               }
+
+               $this->assertEquals( count( $pages), $count );
+       }
+
+       public static function provideGetJobs() {
+               $data = array(
+                       'some data' => 'some value',
+                       'other key' => 'other value'
+               );
+
+               $pages = array( array(
+                       'wiki' => 'enwiki',
+                       'title' => 'Foo baz',
+               ) );
+
+               return array(
+                       array( $data, $pages ),
+                       array( $data, $pages + array( array( 'wiki' => 
'dewiki', 'title' => 'Baz foo' ) ) ),
+                       array( $data + array( 'message' => 'rar' ), $pages + 
array( array( 'wiki' => 'zzwiki', 'title' => 'Title!' ) ) ),
+               );
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6beb37b306bc0ed2c7c71f37721fffabe3c11c92
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: Wctaiwan <wctai...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to