EBernhardson has uploaded a new change for review.

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

Change subject: Test: Add test for watching topics via api
......................................................................

Test: Add test for watching topics via api

Change-Id: I77e3f8b167b5c51c086def8076f283f11a09a3cb
---
M autoload.php
M tests/phpunit/api/ApiFlowLockTopicTest.php
A tests/phpunit/api/ApiTestCase.php
A tests/phpunit/api/ApiWatchTopicTest.php
4 files changed, 132 insertions(+), 43 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/96/168696/1

diff --git a/autoload.php b/autoload.php
index 2a2b93f..da98980 100644
--- a/autoload.php
+++ b/autoload.php
@@ -1,5 +1,7 @@
 <?php
 
+// This file was automatically generated by gen-autoload.php -- do not edit!
+
 $wgAutoloadClasses['ApiFlow'] = __DIR__ . '/includes/api/ApiFlow.php';
 $wgAutoloadClasses['ApiFlowBase'] = __DIR__ . '/includes/api/ApiFlowBase.php';
 $wgAutoloadClasses['ApiFlowBaseGet'] = __DIR__ . 
'/includes/api/ApiFlowBaseGet.php';
@@ -217,6 +219,7 @@
 $wgAutoloadClasses['Flow\\TemplateHelper'] = __DIR__ . 
'/includes/TemplateHelper.php';
 $wgAutoloadClasses['Flow\\Templating'] = __DIR__ . '/includes/Templating.php';
 $wgAutoloadClasses['Flow\\Tests\\Api\\ApiFlowLockTopicTest'] = __DIR__ . 
'/tests/phpunit/api/ApiFlowLockTopicTest.php';
+$wgAutoloadClasses['Flow\\Tests\\Api\\ApiTestCase'] = __DIR__ . 
'/tests/phpunit/api/ApiTestCase.php';
 $wgAutoloadClasses['Flow\\Tests\\BlockFactoryTest'] = __DIR__ . 
'/tests/phpunit/BlockFactoryTest.php';
 $wgAutoloadClasses['Flow\\Tests\\BufferedBagOStuffTest'] = __DIR__ . 
'/tests/phpunit/Data/BagOStuff/BufferedBagOStuffTest.php';
 $wgAutoloadClasses['Flow\\Tests\\BufferedCacheTest'] = __DIR__ . 
'/tests/phpunit/Data/BufferedCacheTest.php';
@@ -239,6 +242,7 @@
 $wgAutoloadClasses['Flow\\Tests\\FlowTestCase'] = __DIR__ . 
'/tests/phpunit/FlowTestCase.php';
 $wgAutoloadClasses['Flow\\Tests\\Formatter\\FormatterTest'] = __DIR__ . 
'/tests/phpunit/Formatter/FormatterTest.php';
 $wgAutoloadClasses['Flow\\Tests\\HookTest'] = __DIR__ . 
'/tests/phpunit/HookTest.php';
+$wgAutoloadClasses['Flow\\Tests\\Integration\\ApiWatchTopicTest'] = __DIR__ . 
'/tests/phpunit/Integration/WatchTopicTest.php';
 $wgAutoloadClasses['Flow\\Tests\\LinksTableTest'] = __DIR__ . 
'/tests/phpunit/LinksTableTest.php';
 $wgAutoloadClasses['Flow\\Tests\\LocalBufferedBagOStuffTest'] = __DIR__ . 
'/tests/phpunit/Data/BagOStuff/LocalBufferedBagOStuffTest.php';
 $wgAutoloadClasses['Flow\\Tests\\Model\\PostRevisionTest'] = __DIR__ . 
'/tests/phpunit/Model/PostRevisionTest.php';
diff --git a/tests/phpunit/api/ApiFlowLockTopicTest.php 
b/tests/phpunit/api/ApiFlowLockTopicTest.php
index cb0cc71..9c3810a 100644
--- a/tests/phpunit/api/ApiFlowLockTopicTest.php
+++ b/tests/phpunit/api/ApiFlowLockTopicTest.php
@@ -10,35 +10,11 @@
  * @group Flow
  * @group medium
  */
-class ApiFlowLockTopicTest extends \ApiTestCase {
+class ApiFlowLockTopicTest extends ApiTestCase {
        /**
         * @var array
         */
        protected $tablesUsed = array( 'flow_revision', 'flow_tree_revision' );
-
-       protected function setUp() {
-               $this->setMwGlobals( 'wgFlowOccupyPages', array( 'Talk:Flow QA' 
) );
-               parent::setUp();
-       }
-
-       protected function getEditToken() {
-               $tokens = $this->getTokenList( self::$users['sysop'] );
-               return $tokens['edittoken'];
-       }
-
-       protected function doApiRequest(
-               array $params,
-               array $session = null,
-               $appendModule = false,
-               User $user = null
-       ) {
-               // reset flow state before each request
-               FlowHooks::resetFlowExtension();
-               Container::reset();
-               $container = Container::getContainer();
-               $container['user'] = $user ?: self::$users['sysop']->user;
-               return parent::doApiRequest( $params, $session, $appendModule, 
$user );
-       }
 
        public function testLockTopic() {
                $workflowId = $this->createTopic();
@@ -103,23 +79,5 @@
                // Is this intentional? We don't display it by default
                // but perhaps it should still be in the api output.
                $this->assertArrayNotHasKey( 'moderateReason', $result );
-       }
-
-       protected function createTopic() {
-               $data = $this->doApiRequest( array(
-                       'page' => 'Talk:Flow QA',
-                       'token' => $this->getEditToken(),
-                       'action' => 'flow',
-                       'submodule' => 'new-topic',
-                       'nttopic' => 'Hi there!',
-                       'ntcontent' => '...',
-               ) );
-               $this->assertTrue(
-                       // @todo we should return the new id much more directly 
than this
-                       isset( 
$data[0]['flow']['new-topic']['result']['topiclist']['roots'][0] ),
-                       'Api response must contain new topic id'
-               );
-
-               return 
$data[0]['flow']['new-topic']['result']['topiclist']['roots'][0];
        }
 }
diff --git a/tests/phpunit/api/ApiTestCase.php 
b/tests/phpunit/api/ApiTestCase.php
new file mode 100644
index 0000000..e7ef437
--- /dev/null
+++ b/tests/phpunit/api/ApiTestCase.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace Flow\Tests\Api;
+
+use ApiTestCase as BaseApiTestCase;
+use Flow\Container;
+use FlowHooks;
+use TestUser;
+use User;
+
+/**
+ * @group Flow
+ * @group medium
+ */
+abstract class ApiTestCase extends BaseApiTestCase {
+       protected function setUp() {
+               $this->setMwGlobals( 'wgFlowOccupyPages', array( 'Talk:Flow QA' 
) );
+               parent::setUp();
+       }
+
+       protected function getEditToken( $user = null, $token = 'edittoken' ) {
+               $tokens = $this->getTokenList( $user ?: self::$users['sysop'] );
+               return $tokens[$token];
+       }
+
+       /**
+        * Ensures Flow is reset before passing control on
+        * to parent::doApiRequest. Defaults all requests to
+        * the sysop user if not specified.
+        */
+       protected function doApiRequest(
+               array $params,
+               array $session = null,
+               $appendModule = false,
+               User $user = null
+       ) {
+               if ( $user === null ) {
+                       $user = self::$users['sysop']->user;
+               }
+
+               // reset flow state before each request
+               FlowHooks::resetFlowExtension();
+               Container::reset();
+               $container = Container::getContainer();
+               $container['user'] = $user;
+               return parent::doApiRequest( $params, $session, $appendModule, 
$user );
+       }
+
+       /**
+        * Create a topic on a board using the default user
+        */
+       protected function createTopic( $return = '' ) {
+               $data = $this->doApiRequest( array(
+                       'page' => 'Talk:Flow QA',
+                       'token' => $this->getEditToken(),
+                       'action' => 'flow',
+                       'submodule' => 'new-topic',
+                       'nttopic' => 'Hi there!',
+                       'ntcontent' => '...',
+               ) );
+               $this->assertTrue(
+                       // @todo we should return the new id much more directly 
than this
+                       isset( 
$data[0]['flow']['new-topic']['result']['topiclist']['roots'][0] ),
+                       'Api response must contain new topic id'
+               );
+
+               if ( $return === 'all' ) {
+                       return $data;
+               } else {
+                       return 
$data[0]['flow']['new-topic']['result']['topiclist']['roots'][0];
+               }
+       }
+}
diff --git a/tests/phpunit/api/ApiWatchTopicTest.php 
b/tests/phpunit/api/ApiWatchTopicTest.php
new file mode 100644
index 0000000..f4320aa
--- /dev/null
+++ b/tests/phpunit/api/ApiWatchTopicTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Flow\Tests\Api;
+
+use Title;
+use WatchedItem;
+
+/**
+ * @group Flow
+ * @group medium
+ */
+class ApiWatchTopicTest extends ApiTestCase {
+
+       public function watchTopicProvider() {
+               return array(
+                       array(
+                               'Watch a topic',
+                               // expected key in api result
+                               'watched',
+                               // initialization
+                               function( WatchedItem $item ) { 
$item->removeWatch(); },
+                               // extra request parameters
+                               array(),
+                       ),
+                       array(
+                               'Unwatch a topic',
+                               // expected key in api result
+                               'unwatched',
+                               // initialization
+                               function( WatchedItem $item ) { 
$item->addWatch(); },
+                               // extra request parameters
+                               array( 'unwatch' => 1 ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider watchTopicProvider
+        */
+       public function testWatchTopic( $message, $expect, $init, array 
$request ) {
+               $topicWorkflowId = $this->createTopic();
+               $title = Title::newFromText( 'Topic:' . $topicWorkflowId );
+               $init( WatchedItem::fromUserTitle( self::$users['sysop']->user, 
$title, false ) );
+
+               // issue a watch api request
+               $data = $this->doApiRequest( $request + array(
+                               'action' => 'watch',
+                               'format' => 'json',
+                               'titles' => "Topic:$topicWorkflowId",
+                               'token' => $this->getEditToken( null, 
'watchtoken' ),
+               ) );
+               $this->assertArrayHasKey( $expect, $data[0]['watch'][0], 
$message );
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I77e3f8b167b5c51c086def8076f283f11a09a3cb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>

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

Reply via email to