jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/348912 )
Change subject: PageAssignments API Unit test + Filter fix
......................................................................
PageAssignments API Unit test + Filter fix
PageAssignmentStore has function that converts object to string, so it can
be filtered. It was using toStdClass() method that I dont know what is,
and wasnt working
Change-Id: I06ce2970abb8c04bf162308d39f7f83cc2642dda
ERM: #5807
---
M PageAssignments/includes/api/BSApiPageAssignmentStore.php
A PageAssignments/tests/phpunit/BSApiMyPageAssignmentStoreTest.php
A PageAssignments/tests/phpunit/BSApiPageAssignableStoreTest.php
A PageAssignments/tests/phpunit/BSApiPageAssignmentStoreTest.php
A PageAssignments/tests/phpunit/BSApiPageAssignmentTasksTest.php
5 files changed, 322 insertions(+), 1 deletion(-)
Approvals:
Robert Vogel: Looks good to me, approved
jenkins-bot: Verified
diff --git a/PageAssignments/includes/api/BSApiPageAssignmentStore.php
b/PageAssignments/includes/api/BSApiPageAssignmentStore.php
index 5c23b9a..3b98543 100644
--- a/PageAssignments/includes/api/BSApiPageAssignmentStore.php
+++ b/PageAssignments/includes/api/BSApiPageAssignmentStore.php
@@ -35,8 +35,9 @@
$sFieldValue = '';
foreach( $aDataSet->assignments as $oAsignee ) {
- $sFieldValue .= $oAsignee->toStdClass()->text;
+ $sFieldValue .= $oAsignee->text;
}
+
if( empty( $sFieldValue ) ) {
$sFieldValue = wfMessage(
'bs-pageassignments-no-assignments' )->plain();
}
diff --git a/PageAssignments/tests/phpunit/BSApiMyPageAssignmentStoreTest.php
b/PageAssignments/tests/phpunit/BSApiMyPageAssignmentStoreTest.php
new file mode 100644
index 0000000..87953fa
--- /dev/null
+++ b/PageAssignments/tests/phpunit/BSApiMyPageAssignmentStoreTest.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * @group medium
+ * @group Database
+ * @group API
+ * @group BlueSpice
+ */
+class BSApiMyPageAssignmentStoreTest extends BSApiExtJSStoreTestBase {
+ protected $iFixtureTotal = 2;
+
+ protected function getStoreSchema () {
+ return [
+ 'page_id' => [
+ 'type' => 'integer'
+ ],
+ 'page_prefixedtext' => [
+ 'type' => 'string'
+ ],
+ 'page_link' => [
+ 'type' => 'string'
+ ],
+ 'assigned_by' => [
+ 'type' => 'array'
+ ]
+ ];
+ }
+
+ protected function createStoreFixtureData () {
+ $dbw = $this->db;
+ $this->setUp();
+
+ $iPageID = $this->insertPage( "Test", "Dummy content" )['id'];
+
+ $dbw->insert( 'bs_pageassignments',
+ array( 'pa_page_id' => 1, 'pa_assignee_key' => 'sysop',
'pa_assignee_type' => 'group', 'pa_position' => 0 )
+ );
+ $dbw->insert( 'bs_pageassignments',
+ array( 'pa_page_id' => $iPageID, 'pa_assignee_key' =>
'bureaucrat', 'pa_assignee_type' => 'group', 'pa_position' => 1 )
+ );
+ $dbw->insert( 'bs_pageassignments',
+ array( 'pa_page_id' => $iPageID, 'pa_assignee_key' =>
'Apitestsysop', 'pa_assignee_type' => 'user', 'pa_position' => 2 )
+ );
+ $dbw->insert( 'bs_pageassignments',
+ array( 'pa_page_id' => 1, 'pa_assignee_key' =>
'TestUser', 'pa_assignee_type' => 'user', 'pa_position' => 3 )
+ );
+ return 2;
+ }
+
+ protected function getModuleName () {
+ return 'bs-mypageassignment-store';
+ }
+
+ public function provideSingleFilterData () {
+ return [
+ 'Filter by page_prefixedtext' => [ 'string', 'eq',
'page_prefixedtext', 'UTPage', 1 ]
+ ];
+ }
+
+ public function provideMultipleFilterData () {
+ return [
+ 'Filter by page_prefixedtext and assigned_by' => [
+ [
+ [
+ 'type' => 'string',
+ 'comparison' => 'ct',
+ 'field' => 'page_prefixedtext',
+ 'value' => 'UT'
+ ],
+ [
+ 'type' => 'integer',
+ 'comparison' => 'ct',
+ 'field' => 'assigned_by',
+ 'value' => 1
+ ]
+ ],
+ 1
+ ]
+ ];
+ }
+
+}
+
diff --git a/PageAssignments/tests/phpunit/BSApiPageAssignableStoreTest.php
b/PageAssignments/tests/phpunit/BSApiPageAssignableStoreTest.php
new file mode 100644
index 0000000..cfa3dff
--- /dev/null
+++ b/PageAssignments/tests/phpunit/BSApiPageAssignableStoreTest.php
@@ -0,0 +1,64 @@
+<?php
+
+/**
+ * @group medium
+ * @group API
+ * @group BlueSpice
+ */
+class BSApiPageAssignableStoreTest extends BSApiExtJSStoreTestBase {
+ protected $iFixtureTotal = 9;
+
+ protected function getStoreSchema () {
+ return [
+ 'type' => [
+ 'type' => 'string'
+ ],
+ 'id' => [
+ 'type' => 'string'
+ ],
+ 'text' => [
+ 'type' => 'string'
+ ],
+ 'anchor' => [
+ 'type' => 'string'
+ ]
+ ];
+ }
+
+ protected function createStoreFixtureData () {
+ return 9;
+ }
+
+ protected function getModuleName () {
+ return 'bs-pageassignable-store';
+ }
+
+ public function provideSingleFilterData () {
+ return [
+ 'Filter by type' => [ 'string', 'eq', 'type', 'group',
6 ]
+ ];
+ }
+
+ public function provideMultipleFilterData () {
+ return [
+ 'Filter by type and id' => [
+ [
+ [
+ 'type' => 'string',
+ 'comparison' => 'eq',
+ 'field' => 'type',
+ 'value' => 'group'
+ ],
+ [
+ 'type' => 'string',
+ 'comparison' => 'ct',
+ 'field' => 'id',
+ 'value' => 'bot'
+ ]
+ ],
+ 1
+ ]
+ ];
+ }
+}
+
diff --git a/PageAssignments/tests/phpunit/BSApiPageAssignmentStoreTest.php
b/PageAssignments/tests/phpunit/BSApiPageAssignmentStoreTest.php
new file mode 100644
index 0000000..9cfc9ab
--- /dev/null
+++ b/PageAssignments/tests/phpunit/BSApiPageAssignmentStoreTest.php
@@ -0,0 +1,81 @@
+<?php
+
+/**
+ * @group medium
+ * @group API
+ * @group BlueSpice
+ */
+class BSApiPageAssignmentStoreTest extends BSApiExtJSStoreTestBase {
+ protected $iFixtureTotal = 24;
+
+ protected $aPages = array(
+ 'UT_Test' => array( 'key' => 'sysop', 'type' => 'group' ),
+ 'UT_Test2' => array( 'key' => 'bureaucrat', 'type' => 'group' ),
+ 'UT_Test3' => array( 'key' => 'Apitestsysop', 'type' => 'user'
),
+ 'UT_Test4' => array( 'key' => 'UTSysop', 'type' => 'user' ),
+ );
+
+ protected function getStoreSchema () {
+ return [
+ 'page_id' => [
+ 'type' => 'integer'
+ ],
+ 'page_prefixedtext' => [
+ 'type' => 'string'
+ ],
+ 'assignments' => [
+ 'type' => 'array'
+ ]
+ ];
+ }
+
+ protected function createStoreFixtureData () {
+ $dbw = $this->db;
+
+ $iCount = 1;
+ foreach( $this->aPages as $sPage => $aData ) {
+ $aRes = $this->insertPage( $sPage );
+ $iPageId = $aRes['id'];
+ $this->assertGreaterThan( 0, $iPageId );
+ $dbw->insert( 'bs_pageassignments',
+ array( 'pa_page_id' => $iPageId,
'pa_assignee_key' => $aData['key'], 'pa_assignee_type' => $aData['type'],
'pa_position' => $iCount )
+ );
+
+ $iCount++;
+ }
+ return 24;
+ }
+
+ protected function getModuleName () {
+ return 'bs-pageassignment-store';
+ }
+
+ public function provideSingleFilterData () {
+ //8 is expected because of 4 pages inserted and their Talk pages
+ return [
+ 'Filter by page_prefixedtext' => [ 'string', 'ct',
'page_prefixedtext', "UT Test" , 8 ]
+ ];
+ }
+
+ public function provideMultipleFilterData () {
+ return [
+ 'Filter by page_prefixedtext and assignment' => [
+ [
+ [
+ 'type' => 'string',
+ 'comparison' => 'ct',
+ 'field' => 'page_prefixedtext',
+ 'value' => 'UT Test'
+ ],
+ [
+ 'type' => 'string',
+ 'comparison' => 'ct',
+ 'field' => 'assignments',
+ 'value' => 'group/sysop'
+ ]
+ ],
+ 1
+ ]
+ ];
+ }
+}
diff --git a/PageAssignments/tests/phpunit/BSApiPageAssignmentTasksTest.php
b/PageAssignments/tests/phpunit/BSApiPageAssignmentTasksTest.php
new file mode 100644
index 0000000..18baac2
--- /dev/null
+++ b/PageAssignments/tests/phpunit/BSApiPageAssignmentTasksTest.php
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * @group medium
+ * @group Database
+ * @group API
+ * @group BlueSpice
+ */
+class BSApiPageAssignmentTasksTest extends BSApiTasksTestBase {
+ protected function getModuleName () {
+ return 'bs-pageassignment-tasks';
+ }
+
+ function getTokens () {
+ return $this->getTokenList ( self::$users[ 'sysop' ] );
+ }
+
+ public function testEdit() {
+ $oData = $this->executeTask(
+ 'edit',
+ array(
+ 'pageId' => 1,
+ 'pageAssignments' => array(
+ 'user/UTSysop',
+ 'group/sysop'
+ )
+ )
+ );
+
+ $this->assertTrue( $oData->success );
+
+ $this->assertSelect(
+ 'bs_pageassignments',
+ array( 'pa_assignee_key', 'pa_assignee_type' ),
+ array( 'pa_page_id = 1' ),
+ array( array( 'UTSysop', 'user' ), array( 'sysop',
'group' ) )
+ );
+
+ $oData = $this->executeTask(
+ 'edit',
+ array(
+ 'pageId' => 1,
+ 'pageAssignments' => array(
+ )
+ )
+ );
+
+ $this->assertTrue( $oData->success );
+
+ $this->assertSelect(
+ 'bs_pageassignments',
+ array( 'pa_assignee_key', 'pa_assignee_type' ),
+ array( 'pa_page_id = 1' ),
+ array()
+ );
+ }
+
+ public function testGetForPage() {
+ $oData = $this->executeTask(
+ 'edit',
+ array(
+ 'pageId' => 1,
+ 'pageAssignments' => array(
+ 'user/UTSysop',
+ 'group/sysop'
+ )
+ )
+ );
+
+ $this->assertTrue( $oData->success );
+
+ $oData = $this->executeTask(
+ 'getForPage',
+ array(
+ 'pageId' => 1
+ )
+ );
+
+ $this->assertTrue( $oData->success );
+ $this->assertArrayHasKey( 0, $oData->payload );
+ $this->assertArrayHasKey( 1, $oData->payload );
+
+ $aAssignment = $oData->payload[0];
+ $this->assertArrayHasKey( 'type', $aAssignment );
+ $this->assertEquals( 'user', $aAssignment['type'] );
+ $this->assertArrayHasKey( 'id', $aAssignment );
+ $this->assertEquals( 'user/UTSysop', $aAssignment['id'] );
+ $this->assertArrayHasKey( 'text', $aAssignment );
+ $this->assertEquals( 'UTSysop', $aAssignment['text'] );
+ $this->assertArrayHasKey( 'anchor', $aAssignment );
+ }
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/348912
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I06ce2970abb8c04bf162308d39f7f83cc2642dda
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: REL1_27
Gerrit-Owner: Robert Vogel <[email protected]>
Gerrit-Reviewer: ItSpiderman <[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