jenkins-bot has submitted this change and it was merged.
Change subject: Test: Add very basic tests for a variety of API methods
......................................................................
Test: Add very basic tests for a variety of API methods
There does seem to be a bit of code duplication between these
tests, could probably still work to make helper assertions and
DRY this up, but it already seems like a good start and good
to have some tests here.
Change-Id: Icc31d684cd4ad5dec0b6c67a69c72b6ddd0ccca7
---
M autoload.php
M includes/Repository/TreeRepository.php
A tests/phpunit/api/ApiFlowEditHeaderTest.php
A tests/phpunit/api/ApiFlowEditPostTest.php
A tests/phpunit/api/ApiFlowEditTitleTest.php
A tests/phpunit/api/ApiFlowEditTopicSummary.php
A tests/phpunit/api/ApiFlowModeratePostTest.php
A tests/phpunit/api/ApiFlowModerateTopicTest.php
A tests/phpunit/api/ApiFlowReplyTest.php
A tests/phpunit/api/ApiFlowViewHeaderTest.php
M tests/phpunit/api/ApiTestCase.php
11 files changed, 459 insertions(+), 28 deletions(-)
Approvals:
Matthias Mullie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/autoload.php b/autoload.php
index da98980..f1ab6f8 100644
--- a/autoload.php
+++ b/autoload.php
@@ -218,8 +218,17 @@
$wgAutoloadClasses['Flow\\TalkpageManager'] = __DIR__ .
'/includes/TalkpageManager.php';
$wgAutoloadClasses['Flow\\TemplateHelper'] = __DIR__ .
'/includes/TemplateHelper.php';
$wgAutoloadClasses['Flow\\Templating'] = __DIR__ . '/includes/Templating.php';
+$wgAutoloadClasses['Flow\\Tests\\Api\\ApiFlowEditHeaderTest'] = __DIR__ .
'/tests/phpunit/api/ApiFlowEditHeaderTest.php';
+$wgAutoloadClasses['Flow\\Tests\\Api\\ApiFlowEditPostTest'] = __DIR__ .
'/tests/phpunit/api/ApiFlowEditPostTest.php';
+$wgAutoloadClasses['Flow\\Tests\\Api\\ApiFlowEditTitleTest'] = __DIR__ .
'/tests/phpunit/api/ApiFlowEditTitleTest.php';
+$wgAutoloadClasses['Flow\\Tests\\Api\\ApiFlowEditTopicSummaryTest'] = __DIR__
. '/tests/phpunit/api/ApiFlowEditTopicSummary.php';
$wgAutoloadClasses['Flow\\Tests\\Api\\ApiFlowLockTopicTest'] = __DIR__ .
'/tests/phpunit/api/ApiFlowLockTopicTest.php';
+$wgAutoloadClasses['Flow\\Tests\\Api\\ApiFlowModeratePostTest'] = __DIR__ .
'/tests/phpunit/api/ApiFlowModeratePostTest.php';
+$wgAutoloadClasses['Flow\\Tests\\Api\\ApiFlowModerateTopicTest'] = __DIR__ .
'/tests/phpunit/api/ApiFlowModerateTopicTest.php';
+$wgAutoloadClasses['Flow\\Tests\\Api\\ApiFlowReplyTest'] = __DIR__ .
'/tests/phpunit/api/ApiFlowReplyTest.php';
+$wgAutoloadClasses['Flow\\Tests\\Api\\ApiFlowViewHeaderTest'] = __DIR__ .
'/tests/phpunit/api/ApiFlowViewHeaderTest.php';
$wgAutoloadClasses['Flow\\Tests\\Api\\ApiTestCase'] = __DIR__ .
'/tests/phpunit/api/ApiTestCase.php';
+$wgAutoloadClasses['Flow\\Tests\\Api\\ApiWatchTopicTest'] = __DIR__ .
'/tests/phpunit/api/ApiWatchTopicTest.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';
@@ -242,7 +251,6 @@
$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/includes/Repository/TreeRepository.php
b/includes/Repository/TreeRepository.php
index ad54a81..549ebf2 100644
--- a/includes/Repository/TreeRepository.php
+++ b/includes/Repository/TreeRepository.php
@@ -121,36 +121,39 @@
__METHOD__
);
} catch( \DBQueryError $e ) {
- /*
- * insertSelect won't work on temporary tables
(as used for MW
- * unit tests), because it refers to the same
table twice, in
- * one query.
- * In this case, we'll do a separate select &
insert.
- *
- * @see
https://dev.mysql.com/doc/refman/5.0/en/temporary-table-problems.html
- * @see
http://dba.stackexchange.com/questions/45270/mysql-error-1137-hy000-at-line-9-cant-reopen-table-temp-table
- */
- if ( $dbw->lastErrno() === 1137 ) {
- // @todo: needs to be done for ALL
depths, not just one
- $rows = $dbw->select(
+ $res = false;
+ }
+ /*
+ * insertSelect won't work on temporary tables (as used
for MW
+ * unit tests), because it refers to the same table
twice, in
+ * one query.
+ * In this case, we'll do a separate select & insert.
This used
+ * to always be detected via the DBQueryError, but it
can also
+ * return false from insertSelect.
+ *
+ * @see
https://dev.mysql.com/doc/refman/5.0/en/temporary-table-problems.html
+ * @see
http://dba.stackexchange.com/questions/45270/mysql-error-1137-hy000-at-line-9-cant-reopen-table-temp-table
+ */
+ if ( !$res && $dbw->lastErrno() === 1137 ) {
+ // @todo: needs to be done for ALL depths, not
just one
+ $rows = $dbw->select(
+ $this->tableName,
+ array( 'tree_depth' ),
+ array( 'tree_descendant_id' =>
$ancestor->getBinary() ),
+ __METHOD__
+ );
+
+ $res = true;
+ foreach ( $rows as $row ) {
+ $res &= $dbw->insert(
$this->tableName,
- array( 'tree_depth' ),
- array( 'tree_descendant_id' =>
$ancestor->getBinary() ),
+ array(
+ 'tree_descendant_id' =>
$descendant->getBinary(),
+ 'tree_ancestor_id' =>
$ancestor->getBinary(),
+ 'tree_depth' =>
$row->tree_depth + 1,
+ ),
__METHOD__
);
-
- $res = true;
- foreach ( $rows as $row ) {
- $res &= $dbw->insert(
- $this->tableName,
- array(
-
'tree_descendant_id' => $descendant->getBinary(),
-
'tree_ancestor_id' => $ancestor->getBinary(),
- 'tree_depth' =>
$row->tree_depth + 1,
- ),
- __METHOD__
- );
- }
}
}
}
diff --git a/tests/phpunit/api/ApiFlowEditHeaderTest.php
b/tests/phpunit/api/ApiFlowEditHeaderTest.php
new file mode 100644
index 0000000..b69ac78
--- /dev/null
+++ b/tests/phpunit/api/ApiFlowEditHeaderTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Flow\Tests\Api;
+
+use Flow\Container;
+use FlowHooks;
+use User;
+
+/**
+ * @group Flow
+ * @group medium
+ */
+class ApiFlowEditHeaderTest extends ApiTestCase {
+
+ protected $tablesUsed = array( 'flow_revision' );
+
+ public function testEditHeader() {
+ $data = $this->doApiRequest( array(
+ 'page' => "Talk:Flow_QA",
+ 'token' => $this->getEditToken(),
+ 'action' => 'flow',
+ 'submodule' => 'edit-header',
+ 'ehprev_revision' => '',
+ 'ehcontent' => '(._.)'
+ ) );
+
+ $result = $data[0]['flow']['edit-header']['result']['header'];
+ $debug = json_encode( $result );
+ $this->assertArrayHasKey( 'errors', $result, $debug );
+ $this->assertCount( 0, $result['errors'], $result );
+
+ $this->assertArrayHasKey( 'revision', $result, $debug );
+ $revision = $result['revision'];
+ $this->assertArrayHasKey( 'changeType', $revision, $debug );
+ $this->assertEquals( 'create-header', $revision['changeType'],
$debug );
+ $this->assertEquals(
+ '(._.)',
+ trim( strip_tags( $revision['content']['content'] ) ),
+ $debug
+ );
+ $this->assertEquals( 'html', $revision['content']['format'],
$debug );
+ }
+}
diff --git a/tests/phpunit/api/ApiFlowEditPostTest.php
b/tests/phpunit/api/ApiFlowEditPostTest.php
new file mode 100644
index 0000000..57552ee
--- /dev/null
+++ b/tests/phpunit/api/ApiFlowEditPostTest.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace Flow\Tests\Api;
+
+use Flow\Container;
+use FlowHooks;
+use User;
+
+/**
+ * @group Flow
+ * @group medium
+ */
+class ApiFlowEditPostTest extends ApiTestCase {
+
+ protected $tablesUsed = array( 'flow_revision' );
+
+ public function testEditPost() {
+ $result = $this->createTopic( 'result' );
+ $workflowId = $result['roots'][0];
+ $topicRevisionId = $result['posts'][$workflowId][0];
+ $topic = $result['revisions'][$topicRevisionId];
+
+ $replyPostId = $topic['replies'][0];
+ $replyRevisionId = $result['posts'][$replyPostId][0];
+
+ $data = $this->doApiRequest( array(
+ 'page' => "Topic:$workflowId",
+ 'token' => $this->getEditToken(),
+ 'action' => 'flow',
+ 'submodule' => 'edit-post',
+ 'eppostId' => $replyPostId,
+ 'epprev_revision' => $replyRevisionId,
+ 'epcontent' => '⎛ ゚∩゚⎞⎛ ⍜⌒⍜⎞⎛ ゚⌒゚⎞'
+ ) );
+
+ $result = $data[0]['flow']['edit-post']['result']['topic'];
+ $debug = json_encode( $result );
+ $this->assertArrayHasKey( 'errors', $result, $debug );
+ $this->assertCount( 0, $result['errors'], $result );
+
+ $newRevisionId = $result['posts'][$replyPostId][0];
+ $revision = $result['revisions'][$newRevisionId];
+ $this->assertArrayHasKey( 'changeType', $revision, $debug );
+ $this->assertEquals( 'edit-post', $revision['changeType'],
$debug );
+ $this->assertEquals(
+ '⎛ ゚∩゚⎞⎛ ⍜⌒⍜⎞⎛ ゚⌒゚⎞',
+ trim( strip_tags( $revision['content']['content'] ) ),
+ $debug
+ );
+ $this->assertEquals( 'html', $revision['content']['format'],
$debug );
+ }
+}
diff --git a/tests/phpunit/api/ApiFlowEditTitleTest.php
b/tests/phpunit/api/ApiFlowEditTitleTest.php
new file mode 100644
index 0000000..2bc8549
--- /dev/null
+++ b/tests/phpunit/api/ApiFlowEditTitleTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Flow\Tests\Api;
+
+use Flow\Container;
+use FlowHooks;
+use User;
+
+/**
+ * @group Flow
+ * @group medium
+ */
+class ApiFlowEditTitleTest extends ApiTestCase {
+
+ protected $tablesUsed = array( 'flow_revision' );
+
+ public function testEditTitle() {
+ $result = $this->createTopic( 'result' );
+ $workflowId = $result['roots'][0];
+ $revisionId = $result['posts'][$workflowId][0];
+ $data = $this->doApiRequest( array(
+ 'page' => "Topic:$workflowId",
+ 'token' => $this->getEditToken(),
+ 'action' => 'flow',
+ 'submodule' => 'edit-title',
+ 'etprev_revision' => $revisionId,
+ 'etcontent' => '(ノ◕ヮ◕)ノ*:・ ゚ ゚ ゚ ゚ ゚ ゚ ゚ ゚✧'
+ ) );
+
+ $result = $data[0]['flow']['edit-title']['result']['topic'];
+
+ $this->assertArrayHasKey( 'errors', $result );
+ $this->assertCount( 0, $result['errors'], json_encode(
$result['errors'] ) );
+
+ $revisionId = $result['posts'][$workflowId][0];
+ $revision = $result['revisions'][$revisionId];
+ $debug = json_encode( $revision );
+ $this->assertArrayHasKey( 'changeType', $revision, $debug );
+ $this->assertEquals( 'edit-title', $revision['changeType'],
$debug );
+ $this->assertEquals( '(ノ◕ヮ◕)ノ*:・ ゚ ゚ ゚ ゚ ゚ ゚ ゚ ゚✧',
$revision['content']['content'], $debug );
+ $this->assertEquals( 'plaintext',
$revision['content']['format'], $debug );
+ }
+}
diff --git a/tests/phpunit/api/ApiFlowEditTopicSummary.php
b/tests/phpunit/api/ApiFlowEditTopicSummary.php
new file mode 100644
index 0000000..b952c56
--- /dev/null
+++ b/tests/phpunit/api/ApiFlowEditTopicSummary.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Flow\Tests\Api;
+
+use Flow\Container;
+use FlowHooks;
+use User;
+
+/**
+ * @group Flow
+ * @group medium
+ */
+class ApiFlowEditTopicSummaryTest extends ApiTestCase {
+
+ protected $tablesUsed = array( 'flow_revision' );
+
+ public function testEditTopicSummary() {
+ $workflowId = $this->createTopic();
+ $data = $this->doApiRequest( array(
+ 'page' => "Topic:$workflowId",
+ 'token' => $this->getEditToken(),
+ 'action' => 'flow',
+ 'submodule' => 'edit-topic-summary',
+ 'etsprev_revision' => '',
+ 'etssummary' => '( ●_●)-((⌼===((() ≍≍≍≍≍ ♒ ✺ ♒ ZAP!'
+ ) );
+
+ $result =
$data[0]['flow']['edit-topic-summary']['result']['topicsummary'];
+ $debug = json_encode( $result );
+ $this->assertArrayHasKey( 'errors', $result, $debug );
+ $this->assertCount( 0, $result['errors'], $result );
+
+ $revision = $result['revision'];
+ $this->assertArrayHasKey( 'changeType', $revision, $debug );
+ $this->assertEquals( 'create-topic-summary',
$revision['changeType'], $debug );
+ $this->assertEquals(
+ '( ●_●)-((⌼===((() ≍≍≍≍≍ ♒ ✺ ♒ ZAP!',
+ trim( strip_tags( $revision['content']['content'] ) ),
+ $debug
+ );
+ $this->assertEquals( 'html', $revision['content']['format'],
$debug );
+ }
+}
diff --git a/tests/phpunit/api/ApiFlowModeratePostTest.php
b/tests/phpunit/api/ApiFlowModeratePostTest.php
new file mode 100644
index 0000000..274627f
--- /dev/null
+++ b/tests/phpunit/api/ApiFlowModeratePostTest.php
@@ -0,0 +1,57 @@
+<?php
+
+namespace Flow\Tests\Api;
+
+use Flow\Container;
+use Flow\Model\AbstractRevision;
+use FlowHooks;
+use User;
+
+/**
+ * @group Flow
+ * @group medium
+ */
+class ApiFlowModeratePostTest extends ApiTestCase {
+
+ protected $tablesUsed = array( 'flow_revision' );
+
+ public function testModeratePost() {
+ $result = $this->createTopic( 'result' );
+ $workflowId = $result['roots'][0];
+ $topicRevisionId = $result['posts'][$workflowId][0];
+ $topic = $result['revisions'][$topicRevisionId];
+ $replyPostId = $topic['replies'][0];
+
+ $data = $this->doApiRequest( array(
+ 'page' => "Topic:$workflowId",
+ 'token' => $this->getEditToken(),
+ 'action' => 'flow',
+ 'submodule' => 'moderate-post',
+ 'mpmoderationState' =>
AbstractRevision::MODERATED_HIDDEN,
+ 'mppostId' => $replyPostId,
+ 'mpreason' => '<>&{};'
+ ) );
+
+ $result = $data[0]['flow']['moderate-post']['result']['topic'];
+ $debug = json_encode( $result );
+ $this->assertArrayHasKey( 'errors', $result );
+ $this->assertCount( 0, $result['errors'], json_encode(
$result['errors'] ) );
+
+ $newRevisionId = $result['posts'][$replyPostId][0];
+ $revision = $result['revisions'][$newRevisionId];
+ $debug = json_encode( $revision );
+ $this->assertArrayHasKey( 'changeType', $revision, $debug );
+ $this->assertEquals( 'hide-post', $revision['changeType'],
$debug );
+ $this->assertArrayHasKey( 'isModerated', $revision, $debug );
+ $this->assertTrue( $revision['isModerated'], $debug );
+ $this->assertArrayHasKey( 'actions', $revision, $debug );
+ $this->assertArrayHasKey( 'unhide', $revision['actions'],
$debug );
+ $this->assertArrayHasKey( 'moderateState', $revision, $debug );
+ $this->assertEquals( AbstractRevision::MODERATED_HIDDEN,
$revision['moderateState'], $debug );
+ $this->assertArrayHasKey( 'moderateReason', $revision, $debug );
+ $this->assertArrayHasKey( 'content',
$revision['moderateReason'], $debug );
+ $this->assertEquals( '<>&{};',
$revision['moderateReason']['content'], $debug );
+ $this->assertArrayHasKey( 'format',
$revision['moderateReason'], $debug );
+ $this->assertEquals( 'plaintext',
$revision['moderateReason']['format'], $debug );
+ }
+}
diff --git a/tests/phpunit/api/ApiFlowModerateTopicTest.php
b/tests/phpunit/api/ApiFlowModerateTopicTest.php
new file mode 100644
index 0000000..290115e
--- /dev/null
+++ b/tests/phpunit/api/ApiFlowModerateTopicTest.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Flow\Tests\Api;
+
+use Flow\Container;
+use Flow\Model\AbstractRevision;
+use FlowHooks;
+use User;
+
+/**
+ * @group Flow
+ * @group medium
+ */
+class ApiFlowModerateTopicTest extends ApiTestCase {
+
+ protected $tablesUsed = array( 'flow_revision' );
+
+ public function testModerateTopic() {
+ $workflowId = $this->createTopic();
+ $data = $this->doApiRequest( array(
+ 'page' => "Topic:$workflowId",
+ 'token' => $this->getEditToken(),
+ 'action' => 'flow',
+ 'submodule' => 'moderate-topic',
+ 'mtmoderationState' =>
AbstractRevision::MODERATED_HIDDEN,
+ 'mtreason' => '<>&{};'
+ ) );
+
+ $result = $data[0]['flow']['moderate-topic']['result']['topic'];
+ $debug = json_encode( $result );
+ $this->assertArrayHasKey( 'errors', $result );
+ $this->assertCount( 0, $result['errors'], json_encode(
$result['errors'] ) );
+
+ $newRevisionId = $result['posts'][$workflowId][0];
+ $revision = $result['revisions'][$newRevisionId];
+ $debug = json_encode( $revision );
+ $this->assertArrayHasKey( 'changeType', $revision, $debug );
+ $this->assertEquals( 'hide-topic', $revision['changeType'],
$debug );
+ $this->assertArrayHasKey( 'isModerated', $revision, $debug );
+ $this->assertTrue( $revision['isModerated'], $debug );
+ $this->assertArrayHasKey( 'actions', $revision, $debug );
+ $this->assertArrayHasKey( 'unhide', $revision['actions'],
$debug );
+ $this->assertArrayHasKey( 'moderateState', $revision, $debug );
+ $this->assertEquals( AbstractRevision::MODERATED_HIDDEN,
$revision['moderateState'], $debug );
+ $this->assertArrayHasKey( 'moderateReason', $revision, $debug );
+ $this->assertArrayHasKey( 'content',
$revision['moderateReason'], $debug );
+ $this->assertEquals( '<>&{};',
$revision['moderateReason']['content'], $debug );
+ $this->assertArrayHasKey( 'format',
$revision['moderateReason'], $debug );
+ $this->assertEquals( 'plaintext',
$revision['moderateReason']['format'], $debug );
+ }
+}
diff --git a/tests/phpunit/api/ApiFlowReplyTest.php
b/tests/phpunit/api/ApiFlowReplyTest.php
new file mode 100644
index 0000000..643c726
--- /dev/null
+++ b/tests/phpunit/api/ApiFlowReplyTest.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Flow\Tests\Api;
+
+use Flow\Container;
+use FlowHooks;
+use User;
+
+/**
+ * @group Flow
+ * @group medium
+ */
+class ApiFlowReplyTest extends ApiTestCase {
+
+ protected $tablesUsed = array( 'flow_revision', 'flow_tree_revision',
'flow_tree_node' );
+
+ public function testTopLevelReply() {
+ $result = $this->createTopic( 'result' );
+ $workflowId = $result['roots'][0];
+ $topicRevId = $result['posts'][$workflowId][0];
+
+ $data = $this->doApiRequest( array(
+ 'page' => "Topic:$workflowId",
+ 'token' => $this->getEditToken(),
+ 'action' => 'flow',
+ 'submodule' => 'reply',
+ 'repreplyTo' => $workflowId,
+ 'repcontent' => '⎛ ゚∩゚⎞⎛ ⍜⌒⍜⎞⎛ ゚⌒゚⎞'
+ ) );
+
+ $result = $data[0]['flow']['reply']['result']['topic'];
+ $debug = json_encode( $result );
+ $this->assertArrayHasKey( 'errors', $result, $debug );
+ $this->assertCount( 0, $result['errors'], $result );
+
+ $newPostId = end( $result['revisions'][$topicRevId]['replies']
);
+ $newRevisionId = $result['posts'][$newPostId][0];
+ $revision = $result['revisions'][$newRevisionId];
+ $this->assertArrayHasKey( 'changeType', $revision, $debug );
+ $this->assertEquals( 'reply', $revision['changeType'], $debug );
+ $this->assertEquals(
+ '⎛ ゚∩゚⎞⎛ ⍜⌒⍜⎞⎛ ゚⌒゚⎞',
+ trim( strip_tags( $revision['content']['content'] ) ),
+ $debug
+ );
+ $this->assertEquals( 'html', $revision['content']['format'],
$debug );
+ }
+}
diff --git a/tests/phpunit/api/ApiFlowViewHeaderTest.php
b/tests/phpunit/api/ApiFlowViewHeaderTest.php
new file mode 100644
index 0000000..492bbc6
--- /dev/null
+++ b/tests/phpunit/api/ApiFlowViewHeaderTest.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Flow\Tests\Api;
+
+use Flow\Container;
+use FlowHooks;
+use User;
+
+/**
+ * @group Flow
+ * @group medium
+ */
+class ApiFlowViewHeaderTest extends ApiTestCase {
+
+ protected $tablesUsed = array( 'flow_revision' );
+
+ public function testViewEmptyHeader() {
+ $data = $this->doApiRequest( array(
+ 'page' => "Talk:Flow_QA",
+ 'action' => 'flow',
+ 'submodule' => 'view-header',
+ ) );
+
+ $result = $data[0]['flow']['view-header']['result']['header'];
+ $debug = json_encode( $result );
+ $this->assertArrayHasKey( 'errors', $result, $debug );
+ $this->assertCount( 0, $result['errors'], $debug );
+
+ // a revision key should exist with only an action link
+ $this->assertArrayHasKey( 'revision', $result, $debug );
+ $revision = $result['revision'];
+ $this->assertEmpty( $revision['links'], $debug );
+ $this->assertEquals( array( 'edit' ), array_keys(
$revision['actions'] ), $debug );
+ $this->assertArrayNotHasKey( 'content', $revision );
+ }
+
+ public function testViewHeader() {
+ $data = $this->doApiRequest( array(
+ 'page' => 'Talk:Flow_QA',
+ 'token' => $this->getEditToken(),
+ 'action' => 'flow',
+ 'submodule' => 'edit-header',
+ 'ehprev_revision' => '',
+ 'ehcontent' => 'swimmingly',
+ ) );
+ $result = $data[0]['flow']['edit-header']['result']['header'];
+ $debug = json_encode( $result );
+ $this->assertArrayHasKey( 'errors', $result, $debug );
+ $this->assertCount( 0, $result['errors'], $debug );
+
+ $data = $this->doApiRequest( array(
+ 'page' => "Talk:Flow_QA",
+ 'action' => 'flow',
+ 'submodule' => 'view-header',
+ ) );
+ $result = $data[0]['flow']['view-header']['result']['header'];
+ $debug = json_encode( $result );
+ $this->assertArrayHasKey( 'errors', $result, $debug );
+ $this->assertCount( 0, $result['errors'], $debug );
+ $this->assertArrayHasKey( 'revision', $result );
+
+ $revision = $result['revision'];
+ $this->assertArrayHasKey( 'revisionId', $revision, $debug );
+ $this->assertArrayHasKey( 'content', $revision, $debug );
+ $this->assertArrayHasKey( 'content', $revision['content'],
$debug );
+ $this->assertEquals(
+ 'swimmingly',
+ trim( strip_tags( $revision['content']['content'] ) ),
+ $debug
+ );
+ $this->assertArrayHasKey( 'format', $revision['content'],
$debug );
+ $this->assertEquals( 'html', $revision['content']['format'],
$debug );
+ }
+
+ /**
+ * @todo
+ *
+ public function testViewHistorical() {
+ }
+ */
+}
diff --git a/tests/phpunit/api/ApiTestCase.php
b/tests/phpunit/api/ApiTestCase.php
index e7ef437..fe4a05e 100644
--- a/tests/phpunit/api/ApiTestCase.php
+++ b/tests/phpunit/api/ApiTestCase.php
@@ -66,6 +66,8 @@
if ( $return === 'all' ) {
return $data;
+ } elseif ( $return === 'result' ) {
+ return
$data[0]['flow']['new-topic']['result']['topiclist'];
} else {
return
$data[0]['flow']['new-topic']['result']['topiclist']['roots'][0];
}
--
To view, visit https://gerrit.wikimedia.org/r/168744
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icc31d684cd4ad5dec0b6c67a69c72b6ddd0ccca7
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: SG <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits