jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/353543 )
Change subject: BSShoutBox: api test
......................................................................
BSShoutBox: api test
Patch Set 8: * Add onUnitTestsList hook
* Add failure messages to asserts
* Normalize user rights
Change-Id: I44df325d8ac3badc88624a51a208d145dcd3b2ec
---
M ShoutBox/ShoutBox.class.php
M ShoutBox/extension.json
A ShoutBox/tests/phpunit/BSApiShoutBoxTasksTest.php
A ShoutBox/tests/phpunit/BSShoutBoxFixture.php
4 files changed, 320 insertions(+), 1 deletion(-)
Approvals:
Mglaser: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ShoutBox/ShoutBox.class.php b/ShoutBox/ShoutBox.class.php
index 29db6a6..fe496ad 100644
--- a/ShoutBox/ShoutBox.class.php
+++ b/ShoutBox/ShoutBox.class.php
@@ -440,4 +440,16 @@
);
return true;
}
+
+ /**
+ * UnitTestsList allows registration of additional test suites to
execute
+ * under PHPUnit. Extensions can append paths to files to the $paths
array,
+ * and since MediaWiki 1.24, can specify paths to directories, which
will
+ * be scanned recursively for any test case files with the suffix
"Test.php".
+ * @param array $paths
+ */
+ public static function onUnitTestsList ( array &$paths ) {
+ $paths[] = __DIR__ . '/tests/phpunit/';
+ return true;
+ }
}
diff --git a/ShoutBox/extension.json b/ShoutBox/extension.json
index d247a98..49e3876 100644
--- a/ShoutBox/extension.json
+++ b/ShoutBox/extension.json
@@ -73,7 +73,8 @@
},
"Hooks": {
"LoadExtensionSchemaUpdates": "ShoutBox::getSchemaUpdates",
- "BSUsageTrackerRegisterCollectors":
"ShoutBox::onBSUsageTrackerRegisterCollectors"
+ "BSUsageTrackerRegisterCollectors":
"ShoutBox::onBSUsageTrackerRegisterCollectors",
+ "UnitTestsList": "ShoutBox::onUnitTestsList"
},
"callback": "ShoutBox::onRegistration",
"manifest_version": 1
diff --git a/ShoutBox/tests/phpunit/BSApiShoutBoxTasksTest.php
b/ShoutBox/tests/phpunit/BSApiShoutBoxTasksTest.php
new file mode 100644
index 0000000..bd4ae54
--- /dev/null
+++ b/ShoutBox/tests/phpunit/BSApiShoutBoxTasksTest.php
@@ -0,0 +1,239 @@
+<?php
+
+/**
+ * @group medium
+ * @group Database
+ * @group API
+ * @group BlueSpice
+ * @group BlueSpiceExtensions
+ * @group BlueSpiceShoutBox
+ */
+require_once __DIR__."/BSShoutBoxFixture.php";
+class BSApiShoutBoxTasksTest extends BSApiTasksTestBase {
+ /**
+ * @var BSShoutBoxFixture
+ */
+ protected $oShoutBoxFixture = null;
+
+ /**
+ * @return BSShoutBoxFixture
+ */
+ protected function getFixture() {
+ if( $this->oShoutBoxFixture ) {
+ return $this->oShoutBoxFixture;
+ }
+ $this->oShoutBoxFixture = new BSShoutBoxFixture( $this );
+ return $this->oShoutBoxFixture;
+ }
+
+ protected $tablesUsed = [
+ 'user',
+ 'user_groups',
+ 'user_properties',
+ 'bs_shoutbox'
+ ];
+
+ protected function setUp() {
+ parent::setUp();
+ if( !is_array( self::$users ) ) {
+ self::$users = [];
+ }
+ self::$users = array_merge(
+ self::$users,
+ $this->getFixture()->getTestUsers()
+ );
+ $this->insertPage(
+ $this->getFixture()->getTestTitle()->getText(),
+ "ShoutBox test page"
+ );
+ $this->getFixture()->addTestDBData( $this->db );
+ $this->mergeMwGlobalArrayValue(
+ 'wgGroupPermissions',
+ [ 'user' => [ 'readshoutbox' => true, 'writeshoutbox'
=> true ] ]
+ );
+ }
+
+ protected function getModuleName () {
+ return 'bs-shoutbox-tasks';
+ }
+
+ function getTokens () {
+ return $this->getTokenList( self::$users[ 'sbtestuser' ] );
+ }
+
+ public function testFailGetShoutsMissingArticleID() {
+ $this->doLogin( 'sbtestuser' );
+ $oData = $this->executeTask(
+ 'getShouts',
+ []
+ );
+
+ $this->assertFalse( $oData->success, "API sends success where
it should have failed" );
+ $this->assertArrayEquals( ['html' => ''], $oData->payload,
"HTML is not empty" );
+ $this->assertNotEmpty( $oData->message, "Error message is
missing" );
+ }
+
+ public function testGetShouts() {
+ $this->doLogin( 'sbtestuser' );
+ $oParams = (object)[
+ 'articleId' =>
$this->getFixture()->getTestTitle()->getArticleId()
+ ];
+ $oData = $this->executeTask(
+ 'getShouts',
+ $oParams
+ );
+
+ $this->assertTrue( $oData->success, "API sends failed where it
should have succeeded" );
+ $this->assertTrue( $oData->payload_count == 2, "Count reports
wrong number" );
+ $this->assertEmpty( $oData->message, "There is an error message
where there should be none" );
+ }
+
+ public function testFailInsertShoutMissingArticleId() {
+ $this->doLogin( 'sbtestuser' );
+ $oParams = (object)[
+ 'message' => __METHOD__,
+ ];
+ $oData = $this->executeTask(
+ 'insertShout',
+ $oParams
+ );
+
+ $this->assertFalse( $oData->success, "API sends success where
it should have failed" );
+ $this->assertNotEmpty( $oData->message, "Error message is
missing" );
+ }
+
+ public function testFailInsertShoutMissingMessage() {
+ $this->doLogin( 'sbtestuser' );
+ $oParams = (object)[
+ 'articleId' =>
$this->getFixture()->getTestTitle()->getArticleId(),
+ ];
+ $oData = $this->executeTask(
+ 'insertShout',
+ $oParams
+ );
+
+ $this->assertFalse( $oData->success, "API sends success where
it should have failed" );
+ $this->assertNotEmpty( $oData->message, "Error message is
missing" );
+ }
+
+ public function testInsertShout() {
+ $this->doLogin( 'sbtestuser' );
+ $oParams = (object)[
+ 'articleId' =>
$this->getFixture()->getTestTitle()->getArticleId(),
+ 'message' => __METHOD__,
+ ];
+ $oData = $this->executeTask(
+ 'insertShout',
+ $oParams
+ );
+
+ $this->assertTrue( $oData->success, "API sends failed where it
should have succeeded" );
+ $this->assertArrayHasKey( 'sb_id', $oData->payload, "There is
no id information" );
+ $this->assertNotEmpty( $oData->payload['sb_id'], "ID field is
empty" );
+ }
+
+ public function testFailArchiveShoutMissingShoutId() {
+ $this->doLogin( 'sbtestuser' );
+ $oParams = (object)[];
+ $oData = $this->executeTask(
+ 'archiveShout',
+ $oParams
+ );
+
+ $this->assertFalse( $oData->success, "API sends success where
it should have failed" );
+ $this->assertNotEmpty( $oData->message, "Error message is
missing" );
+ }
+
+ public function testArchiveShout() {
+ $this->doLogin( 'sbtestuser' );
+ $aUsers = $this->getFixture()->getTestUsers();
+ $oUser = $aUsers['sbtestuser']->getUser();
+
+ $oRow = $this->db->selectRow(
+ 'bs_shoutbox',
+ 'sb_id',
+ [
+ 'sb_user_id' => (int)$oUser->getId(),
+ 'sb_page_id' =>
(int)$this->getFixture()->getTestTitle()
+ ->getArticleID(),
+ 'sb_archived' => 0,
+ ],
+ __METHOD__
+ );
+
+ if( !$oRow ) {
+ $this->fail();
+ }
+
+ $oParams = (object)[
+ 'shoutId' => $oRow->sb_id,
+ ];
+ $oData = $this->executeTask(
+ 'archiveShout',
+ $oParams
+ );
+
+ $this->assertTrue( $oData->success, "API sends failed where it
should have succeeded" );
+ }
+
+ public function testFailArchiveShoutNotMine() {
+ $this->doLogin( 'sbtestuser' );
+ $aUsers = $this->getFixture()->getTestUsers();
+ $oUser = $aUsers['sbtestsysop']->getUser();
+
+ $oRow = $this->db->selectRow(
+ 'bs_shoutbox',
+ 'sb_id',
+ [
+ 'sb_user_id' => (int)$oUser->getId(),
+ 'sb_page_id' =>
(int)$this->getFixture()->getTestTitle()
+ ->getArticleID(),
+ 'sb_archived' => 0,
+ ],
+ __METHOD__
+ );
+ if( !$oRow ) {
+ $this->fail();
+ }
+ $oParams = (object)[
+ 'shoutId' => $oRow->sb_id,
+ ];
+ $oData = $this->executeTask(
+ 'archiveShout',
+ $oParams
+ );
+
+ $this->assertFalse( $oData->success, "API sends success where
it should have failed" );
+ $this->assertNotEmpty( $oData->message, "Error message is
missing" );
+ }
+
+ public function testArchiveShoutNotMine() {
+ $this->doLogin( 'sbtestsysop' );
+ $aUsers = $this->getFixture()->getTestUsers();
+ $oUser = $aUsers['sbtestuser']->getUser();
+
+ $oRow = $this->db->selectRow(
+ 'bs_shoutbox',
+ 'sb_id',
+ [
+ 'sb_user_id' => (int)$oUser->getId(),
+ 'sb_page_id' =>
(int)$this->getFixture()->getTestTitle()
+ ->getArticleID(),
+ 'sb_archived' => 0,
+ ],
+ __METHOD__
+ );
+ if( !$oRow ) {
+ $this->fail();
+ }
+ $oParams = (object)[
+ 'shoutId' => $oRow->sb_id,
+ ];
+ $oData = $this->executeTask(
+ 'archiveShout',
+ $oParams
+ );
+
+ $this->assertTrue( $oData->success, "API sends failed where it
should have succeeded" );
+ }
+}
\ No newline at end of file
diff --git a/ShoutBox/tests/phpunit/BSShoutBoxFixture.php
b/ShoutBox/tests/phpunit/BSShoutBoxFixture.php
new file mode 100644
index 0000000..ef30957
--- /dev/null
+++ b/ShoutBox/tests/phpunit/BSShoutBoxFixture.php
@@ -0,0 +1,67 @@
+<?php
+
+class BSShoutBoxFixture {
+ protected $oTest = null;
+ protected $aTestUsers = null;
+
+ public function __construct( $oTest ) {
+ $this->oTest = $oTest;
+ }
+
+ public function addTestDBData( $oDB ) {
+ $aShouts = $this->getTestShouts();
+ foreach( $aShouts as $row ) {
+ $oDB->insert( 'bs_shoutbox', [
+ 'sb_page_id' => $row[0],
+ 'sb_user_id' => $row[1],
+ 'sb_timestamp' => $row[2],
+ 'sb_user_name' => $row[3],
+ 'sb_message' => $row[4],
+ ]);
+ }
+ }
+
+ public function getTestTitle() {
+ return Title::newFromText( 'ShoutBoxUnitTestPage', NS_MAIN );
+ }
+
+ public function getTestUsers() {
+ if( $this->aTestUsers ) {
+ return $this->aTestUsers;
+ }
+ $this->aTestUsers = [
+ 'sbtestuser' => new TestUser(
+ 'Shoutboxtestuser',
+ 'ShoutBox Test User',
+ '[email protected]',
+ []
+ ),
+ 'sbtestsysop' => new TestUser(
+ 'Shoutboxtestsysop',
+ 'ShoutBox Test Sysop',
+ '[email protected]',
+ [ 'sysop' ]
+ ),
+ ];
+ return $this->aTestUsers;
+ }
+
+ public function getTestShouts() {
+ $aUsers = $this->getTestUsers();
+ return [
+ [
+ (int)$this->getTestTitle()->getArticleID(),
+ (int)$aUsers['sbtestuser']->getUser()->getId(),
+ '20150314092653',
+ $aUsers['sbtestuser']->getUser()->getRealName(),
+ "I shout: the sheriff",
+ ], [
+ (int)$this->getTestTitle()->getArticleID(),
+ (int)$aUsers['sbtestsysop']->getUser()->getId(),
+ '20170517101431',
+
$aUsers['sbtestsysop']->getUser()->getRealName(),
+ "Another generic test shout",
+ ],
+ ];
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/353543
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I44df325d8ac3badc88624a51a208d145dcd3b2ec
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Pwirth <[email protected]>
Gerrit-Reviewer: Mglaser <[email protected]>
Gerrit-Reviewer: Pwirth <[email protected]>
Gerrit-Reviewer: Robert Vogel <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits