[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceExtensions[master]: Checklist: Add PHPUnit Tests for API functions

2016-11-29 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Checklist: Add PHPUnit Tests for API functions
..


Checklist: Add PHPUnit Tests for API functions

Change-Id: Ie43454bdb1d8b21ecde54254f8f96603799bebe0
---
M Checklist/Checklist.class.php
M Checklist/extension.json
A Checklist/tests/phpunit/BSApiChecklistAvailableOptionsStoreTest.php
A Checklist/tests/phpunit/BSApiChecklistTasksTest.php
A Checklist/tests/phpunit/BSApiChecklistTemplateStoreTest.php
5 files changed, 208 insertions(+), 1 deletion(-)

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



diff --git a/Checklist/Checklist.class.php b/Checklist/Checklist.class.php
index 5ecbc62..9482bd1 100644
--- a/Checklist/Checklist.class.php
+++ b/Checklist/Checklist.class.php
@@ -67,6 +67,18 @@
}
 
/**
+* 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;
+   }
+
+   /**
 * Hook Handler for VisualEditorConfig Hook
 * @param Array $aConfigStandard reference
 * @param Array $aConfigOverwrite reference
diff --git a/Checklist/extension.json b/Checklist/extension.json
index 96ca10f..1734b85 100644
--- a/Checklist/extension.json
+++ b/Checklist/extension.json
@@ -45,7 +45,8 @@
 "BSInsertMagicAjaxGetData": "Checklist::onBSInsertMagicAjaxGetData",
 "VisualEditorConfig": "Checklist::onVisualEditorConfig",
 "BSUsageTrackerRegisterCollectors": 
"Checklist::onBSUsageTrackerRegisterCollectors",
-"EditPage::showEditForm:initial": 
"Checklist::onEditPage_showEditForm_initial"
+"EditPage::showEditForm:initial": 
"Checklist::onEditPage_showEditForm_initial",
+   "UnitTestsList": "Checklist::onUnitTestsList"
 },
 "ResourceModules": {
 "ext.bluespice.checklist": {
diff --git 
a/Checklist/tests/phpunit/BSApiChecklistAvailableOptionsStoreTest.php 
b/Checklist/tests/phpunit/BSApiChecklistAvailableOptionsStoreTest.php
new file mode 100644
index 000..39663a7
--- /dev/null
+++ b/Checklist/tests/phpunit/BSApiChecklistAvailableOptionsStoreTest.php
@@ -0,0 +1,44 @@
+doLogin();
+   }
+
+   /**
+* Anything cleanup you need to do should go here.
+*/
+   protected function tearDown() {
+   parent::tearDown();
+   }
+
+   public function testMakeData(){
+   $data = $this->doApiRequest( [
+   'action' => 'bs-checklist-available-options-store'
+   ] );
+
+   $this->assertArrayHasKey( 'total', $data[0] );
+   $this->assertArrayHasKey( 'results', $data[0] );
+
+   return $data;
+   }
+
+}
diff --git a/Checklist/tests/phpunit/BSApiChecklistTasksTest.php 
b/Checklist/tests/phpunit/BSApiChecklistTasksTest.php
new file mode 100644
index 000..60f4918
--- /dev/null
+++ b/Checklist/tests/phpunit/BSApiChecklistTasksTest.php
@@ -0,0 +1,104 @@
+doLogin();
+   $this->insertPage( "Test", "" );
+   }
+
+   function getTokens() {
+   return $this->getTokenList( self::$users[ 'sysop' ] );
+   }
+
+   /**
+* Anything cleanup you need to do should go here.
+*/
+   protected function tearDown() {
+   parent::tearDown();
+   }
+
+   public function testTask_doChangeCheckItem() {
+   $tokens = $this->getTokens();
+
+   $data = $this->doApiRequest( [
+   'action' => 'bs-checklist-tasks',
+   'token' => $tokens[ 'edittoken' ],
+   'task' => 'doChangeCheckItem',
+   'taskData' => json_encode( [
+   'pos' => '1',
+   'value' => 'true'
+   ] ),
+   'context' => json_encode( ['wgTitle' => 'Test' ] )
+ ] );
+
+   $this->assertEquals( true, $data[ 0 ][ 'success' ] );
+
+   return $data;
+   }
+
+   public function testTask_saveOptionsList() {
+   $tokens = $this->getTokens();
+
+   $oTitle = Title::makeTitle( NS_TEMPLATE, 'Test' );
+   $this->assertEquals( false, $oTitle->exists() );
+
+   $arrRecords = ['a', 'b', 'c' ];
+
+   $data = $this->doApiRequest( [
+   'action' => 'bs-checklist-tasks',
+   'token' => $tokens[ 'edittoken' ],
+   'task' => 

[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceExtensions[master]: Checklist: Add PHPUnit Tests for API functions

2016-11-18 Thread Ljonka (Code Review)
Ljonka has uploaded a new change for review.

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

Change subject: Checklist: Add PHPUnit Tests for API functions
..

Checklist: Add PHPUnit Tests for API functions

Change-Id: Ie43454bdb1d8b21ecde54254f8f96603799bebe0
---
M Checklist/Checklist.class.php
M Checklist/extension.json
A Checklist/tests/phpunit/BSApiChecklistAvailableOptionsStoreTest.php
A Checklist/tests/phpunit/BSApiChecklistTasksTest.php
A Checklist/tests/phpunit/BSApiChecklistTemplateStoreTest.php
5 files changed, 210 insertions(+), 1 deletion(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions 
refs/changes/46/322246/1

diff --git a/Checklist/Checklist.class.php b/Checklist/Checklist.class.php
index 5ecbc62..9482bd1 100644
--- a/Checklist/Checklist.class.php
+++ b/Checklist/Checklist.class.php
@@ -67,6 +67,18 @@
}
 
/**
+* 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;
+   }
+
+   /**
 * Hook Handler for VisualEditorConfig Hook
 * @param Array $aConfigStandard reference
 * @param Array $aConfigOverwrite reference
diff --git a/Checklist/extension.json b/Checklist/extension.json
index 96ca10f..2a54855 100644
--- a/Checklist/extension.json
+++ b/Checklist/extension.json
@@ -45,7 +45,8 @@
 "BSInsertMagicAjaxGetData": "Checklist::onBSInsertMagicAjaxGetData",
 "VisualEditorConfig": "Checklist::onVisualEditorConfig",
 "BSUsageTrackerRegisterCollectors": 
"Checklist::onBSUsageTrackerRegisterCollectors",
-"EditPage::showEditForm:initial": 
"Checklist::onEditPage_showEditForm_initial"
+"EditPage::showEditForm:initial": 
"Checklist::onEditPage_showEditForm_initial",
+   "UnitTestsList": "Checklist::onUnitTestsList"
 },
 "ResourceModules": {
 "ext.bluespice.checklist": {
diff --git 
a/Checklist/tests/phpunit/BSApiChecklistAvailableOptionsStoreTest.php 
b/Checklist/tests/phpunit/BSApiChecklistAvailableOptionsStoreTest.php
new file mode 100644
index 000..fe784a3
--- /dev/null
+++ b/Checklist/tests/phpunit/BSApiChecklistAvailableOptionsStoreTest.php
@@ -0,0 +1,46 @@
+doLogin();
+   }
+
+   /**
+* Anything cleanup you need to do should go here.
+*/
+   protected function tearDown() {
+   parent::tearDown();
+   }
+
+   public function testMakeData(){
+   
+
+   $data = $this->doApiRequest( [
+   'action' => 'bs-checklist-available-options-store'
+   ] );
+
+   $this->assertArrayHasKey( 'total', $data[0] );
+   $this->assertArrayHasKey( 'results', $data[0] );
+
+   return $data;
+   }
+
+}
diff --git a/Checklist/tests/phpunit/BSApiChecklistTasksTest.php 
b/Checklist/tests/phpunit/BSApiChecklistTasksTest.php
new file mode 100644
index 000..60f4918
--- /dev/null
+++ b/Checklist/tests/phpunit/BSApiChecklistTasksTest.php
@@ -0,0 +1,104 @@
+doLogin();
+   $this->insertPage( "Test", "" );
+   }
+
+   function getTokens() {
+   return $this->getTokenList( self::$users[ 'sysop' ] );
+   }
+
+   /**
+* Anything cleanup you need to do should go here.
+*/
+   protected function tearDown() {
+   parent::tearDown();
+   }
+
+   public function testTask_doChangeCheckItem() {
+   $tokens = $this->getTokens();
+
+   $data = $this->doApiRequest( [
+   'action' => 'bs-checklist-tasks',
+   'token' => $tokens[ 'edittoken' ],
+   'task' => 'doChangeCheckItem',
+   'taskData' => json_encode( [
+   'pos' => '1',
+   'value' => 'true'
+   ] ),
+   'context' => json_encode( ['wgTitle' => 'Test' ] )
+ ] );
+
+   $this->assertEquals( true, $data[ 0 ][ 'success' ] );
+
+   return $data;
+   }
+
+   public function testTask_saveOptionsList() {
+   $tokens = $this->getTokens();
+
+   $oTitle = Title::makeTitle( NS_TEMPLATE, 'Test' );
+   $this->assertEquals( false, $oTitle->exists() );
+
+   $arrRecords = ['a', 'b', 'c' ];
+
+   $data = $this->doApiRequest( [
+   'action' => 'bs-checklist-tasks',
+