ItSpiderman has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/346976 )
Change subject: Flexiskin: API Unittest + API documentation fix
......................................................................
Flexiskin: API Unittest + API documentation fix
I dont know how to test BSApiFlexiskinUpload, could someone help?
On BSApiFlexiskinUploadStore, im casting items to objects in order for
filtering to work
Change-Id: I2da576444eee183d36b9cf9fa3b1647f1a4515ae
---
M Flexiskin/includes/api/BSApiFlexiskinTasks.php
M Flexiskin/includes/api/BSApiFlexiskinUploadStore.php
A Flexiskin/tests/phpunit/BSApiFlexiskinStoreTest.php
A Flexiskin/tests/phpunit/BSApiFlexiskinTasksTest.php
A Flexiskin/tests/phpunit/BSApiFlexiskinUploadStoreTest.php
A Flexiskin/tests/phpunit/BSApiFlexiskinUploadTest.php
A Flexiskin/tests/phpunit/data/dummy.PNG
A Flexiskin/tests/phpunit/data/test.PNG
8 files changed, 327 insertions(+), 9 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions
refs/changes/76/346976/1
diff --git a/Flexiskin/includes/api/BSApiFlexiskinTasks.php
b/Flexiskin/includes/api/BSApiFlexiskinTasks.php
index b62dbe2..5230fff 100644
--- a/Flexiskin/includes/api/BSApiFlexiskinTasks.php
+++ b/Flexiskin/includes/api/BSApiFlexiskinTasks.php
@@ -65,12 +65,12 @@
'delete' => [
'examples' => [
[
- 'id' => 'SomeSkinName'
+ 'id' =>
'5b918c15b12ede0c3f39c6e8692525a7'
]
],
'params' => [
'id' => [
- 'desc' => 'Valid skin ID',
+ 'desc' => 'Valid skin ID (hash)',
'type' => 'string',
'required' => true
]
@@ -79,7 +79,7 @@
'save' => [
'examples' => [
[
- 'id' => 'SomeSkinName',
+ 'id' =>
'5b918c15b12ede0c3f39c6e8692525a7',
'data' => [
[
'name' => "SkinName",
@@ -91,7 +91,7 @@
],
'params' => [
'id' => [
- 'desc' => 'Valid skin ID',
+ 'desc' => 'Valid skin ID (hash)',
'type' => 'string',
'required' => true
],
@@ -105,12 +105,12 @@
'reset' => [
'examples' => [
[
- 'id' => 'SomeSkinName'
+ 'id' =>
'5b918c15b12ede0c3f39c6e8692525a7'
]
],
'params' => [
'id' => [
- 'desc' => 'Valid skin ID',
+ 'desc' => 'Valid skin ID (hash)',
'type' => 'string',
'required' => true
]
@@ -119,7 +119,7 @@
'preview' => [
'examples' => [
[
- 'id' => 'SomeSkinName',
+ 'id' =>
'5b918c15b12ede0c3f39c6e8692525a7',
'data' => [
[
'name' => "SkinName",
@@ -131,7 +131,7 @@
],
'params' => [
'id' => [
- 'desc' => 'Valid skin ID',
+ 'desc' => 'Valid skin ID (hash)',
'type' => 'string',
'required' => true
],
diff --git a/Flexiskin/includes/api/BSApiFlexiskinUploadStore.php
b/Flexiskin/includes/api/BSApiFlexiskinUploadStore.php
index b34ee7c..02a7df6 100644
--- a/Flexiskin/includes/api/BSApiFlexiskinUploadStore.php
+++ b/Flexiskin/includes/api/BSApiFlexiskinUploadStore.php
@@ -47,7 +47,7 @@
foreach( $flexiskinFiles as $object ){
if( $object instanceof SplFileInfo );
- $aData[] = array(
+ $aData[] = (object) array(
'filename' => $object->getFilename(),
'extension' => $object->getExtension(),
'mtime' => $object->getMTime()
diff --git a/Flexiskin/tests/phpunit/BSApiFlexiskinStoreTest.php
b/Flexiskin/tests/phpunit/BSApiFlexiskinStoreTest.php
new file mode 100644
index 0000000..9babda0
--- /dev/null
+++ b/Flexiskin/tests/phpunit/BSApiFlexiskinStoreTest.php
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * @group medium
+ */
+class BSApiFlexiskinStoreTest extends BSApiExtJSStoreTestBase{
+ protected $iFixtureTotal = 3;
+
+ protected $aFlexiskins = array(
+ array( 'name' => 'UTTest1', 'desc' => 'Desc1'),
+ array( 'name' => 'UTTest2', 'desc' => 'Desc2'),
+ array( 'name' => 'UTTest3', 'desc' => 'Desc3'),
+ );
+
+ protected function getStoreSchema () {
+ return [
+ 'flexiskin_id' => [
+ 'type' => 'string'
+ ],
+ 'flexiskin_name' => [
+ 'type' => 'string'
+ ],
+ 'flexiskin_desc' => [
+ 'type' => 'string'
+ ],
+ 'flexiskin_active' => [
+ 'type' => 'boolean'
+ ],
+ 'flexiskin_config' => [
+ 'type' => 'array'
+ ]
+ ];
+ }
+
+ protected function createStoreFixtureData () {
+ return 4;
+ }
+
+ protected function setUp() {
+ $aFSs = $this->aFlexiskins;
+ foreach( $aFSs as $aFS ) {
+
+ $sConfigFile = Flexiskin::generateConfigFile( (object)
$aFS );
+ $sId = $aFS['name'];
+ BsFileSystemHelper::saveToDataDirectory( 'conf.json',
$sConfigFile, "flexiskin" . DS . md5( $sId ) );
+ BsFileSystemHelper::ensureDataDirectory( "flexiskin" .
DS . md5( $sId ) . DS . "images" );
+ }
+ parent::setUp();
+ }
+
+ protected function tearDown() {
+
+ $aFSs = $this->aFlexiskins;
+ foreach( $aFSs as $aFS ) {
+ $sId = $aFS['name'];
+ $oStatus = BsFileSystemHelper::deleteFolder(
"flexiskin" . DS . md5( $sId ) );
+ }
+ parent::tearDown();
+ }
+
+ protected function getModuleName () {
+ return 'bs-flexiskin-store';
+ }
+
+ public function provideSingleFilterData () {
+ return [
+ 'Filter by flexiskin_name' => [ 'string', 'ct',
'flexiskin_name', 'UT', 3 ]
+ ];
+ }
+
+ public function provideMultipleFilterData () {
+ return [
+ 'Filter by flexiskin_name and flexiskin_desc' => [
+ [
+ [
+ 'type' => 'string',
+ 'comparison' => 'ct',
+ 'field' => 'flexiskin_name',
+ 'value' => 'UT'
+ ],
+ [
+ 'type' => 'string',
+ 'comparison' => 'eq',
+ 'field' => 'flexiskin_desc',
+ 'value' => 'Desc1'
+ ]
+ ],
+ 1
+ ]
+ ];
+ }
+}
diff --git a/Flexiskin/tests/phpunit/BSApiFlexiskinTasksTest.php
b/Flexiskin/tests/phpunit/BSApiFlexiskinTasksTest.php
new file mode 100644
index 0000000..9b76ca4
--- /dev/null
+++ b/Flexiskin/tests/phpunit/BSApiFlexiskinTasksTest.php
@@ -0,0 +1,122 @@
+<?php
+
+/**
+ * @group medium
+ */
+class BSApiFlexiskinTasksTest extends BSApiTasksTestBase {
+ protected function getModuleName () {
+ return 'bs-flexiskin-tasks';
+ }
+
+ function getTokens () {
+ return $this->getTokenList ( self::$users[ 'sysop' ] );
+ }
+
+ protected function setUp() {
+ parent::setUp();
+ RequestContext::getMain()->setTitle( Title::newMainPage() );
+ }
+
+ public function testAdd() {
+ $oData = $this->executeTask(
+ 'add',
+ array(
+ 'data' => array(
+ array(
+ 'name' => 'UT Test1',
+ 'desc' => 'UNITTEST entry',
+ 'template' => ''
+ )
+ )
+ )
+ );
+
+ $this->assertTrue( $oData->success );
+
+ $sId = str_replace( " ", "_", strtolower( 'UT Test1' ) );
+ $sFlexiskinPath = BsFileSystemHelper::getDataDirectory(
'flexiskin' . DS . md5( $sId ) );
+
+ $this->assertTrue( is_dir( $sFlexiskinPath) );
+
+ }
+
+ public function testSave() {
+ $oData = $this->executeTask(
+ 'save',
+ array(
+ 'id' => md5( str_replace( " ", "_", strtolower(
'UT Test1' ) ) ),
+ 'data' => array(
+ array(
+ 'name' => 'UT TestChanged',
+ 'desc' => 'UNITTEST entry
changed',
+ 'template' => ''
+ )
+ )
+ )
+ );
+
+ $this->assertTrue( $oData->success );
+ $this->assertEquals( md5( str_replace( " ", "_", strtolower(
'UT TestChanged' ) ) ), $oData->id );
+
+ $sId = str_replace( " ", "_", strtolower( 'UT TestChanged' ) );
+ $sFlexiskinPath = BsFileSystemHelper::getDataDirectory(
'flexiskin' . DS . md5( $sId ) );
+
+ $this->assertTrue( is_dir( $sFlexiskinPath) );
+ }
+
+ public function testPreview() {
+ $oData = $this->executeTask(
+ 'preview',
+ array(
+ 'id' => md5( str_replace( " ", "_", strtolower(
'UT TestChanged' ) ) ),
+ 'data' => array()
+ )
+ );
+
+ $this->assertTrue( $oData->success );
+ }
+
+ public function testReset() {
+ $oData = $this->executeTask(
+ 'reset',
+ array(
+ 'id' => md5( str_replace( " ", "_", strtolower(
'UT TestChanged' ) ) )
+ )
+ );
+
+ $this->assertTrue( $oData->success );
+
+ $this->assertArrayHasKey( 'skinId', $oData->data );
+ $this->assertEquals( md5( str_replace( " ", "_", strtolower(
'UT TestChanged' ) ) ), $oData->data['skinId'] );
+
+ }
+
+ public function testActivate() {
+ $oData = $this->executeTask(
+ 'activate',
+ array(
+ 'id' => md5( str_replace( " ", "_", strtolower(
'UT TestChanged' ) ) )
+ )
+ );
+
+ $this->assertTrue( $oData->success );
+
+ }
+
+ public function testDelete() {
+ $oData = $this->executeTask(
+ 'delete',
+ array(
+ 'id' => md5( str_replace( " ", "_", strtolower(
'UT TestChanged' ) ) )
+ )
+ );
+
+ $this->assertTrue( $oData->success );
+
+ $sId = str_replace( " ", "_", strtolower( 'UT TestChanged' ) );
+ $sFlexiskinPath = BsFileSystemHelper::getDataDirectory(
'flexiskin' . DS . md5( $sId ) );
+
+ $this->assertFalse( is_dir( $sFlexiskinPath) );
+
+ }
+}
\ No newline at end of file
diff --git a/Flexiskin/tests/phpunit/BSApiFlexiskinUploadStoreTest.php
b/Flexiskin/tests/phpunit/BSApiFlexiskinUploadStoreTest.php
new file mode 100644
index 0000000..18f9803
--- /dev/null
+++ b/Flexiskin/tests/phpunit/BSApiFlexiskinUploadStoreTest.php
@@ -0,0 +1,94 @@
+<?php
+
+/**
+ * @group medium
+ */
+class BSApiFlexiskinUploadStoreTest extends BSApiExtJSStoreTestBase {
+ protected $iFixtureTotal = 1;
+ protected $sQuery = '';
+
+ protected $aFlexiskin = array( 'name' => 'UTTest1', 'desc' => 'Desc1');
+
+ protected function makeRequestParams() {
+ return [
+ 'action' => $this->getModuleName(),
+ 'query' => $this->getSkinId()
+ ];
+ }
+
+ protected function getSkinId( ) {
+ $sId = str_replace( " ", "_", strtolower(
$this->aFlexiskin['name'] ) );
+ return md5( $sId );
+ }
+
+ protected function getStoreSchema () {
+ return [
+ 'filename' => [
+ 'type' => 'string'
+ ],
+ 'extension' => [
+ 'type' => 'string'
+ ],
+ 'mtime' => [
+ 'type' => 'numeric'
+ ]
+ ];
+ }
+
+ protected function createStoreFixtureData () {
+ return 1;
+ }
+
+ protected function setUp() {
+ $aFS = $this->aFlexiskin;
+
+ $sConfigFile = Flexiskin::generateConfigFile( (object) $aFS );
+ BsFileSystemHelper::saveToDataDirectory( 'conf.json',
$sConfigFile, "flexiskin" . DS . $this->getSkinId() );
+ BsFileSystemHelper::ensureDataDirectory( "flexiskin" . DS .
$this->getSkinId() . DS . "images" );
+ $sSource = __DIR__ . DS . 'data' . DS . 'test.png';
+ $sDest = BS_DATA_DIR . DS . 'flexiskin' . DS .
$this->getSkinId() . DS .'images' . DS . 'test.png';
+ copy( $sSource, $sDest );
+
+ $this->sQuery = $this->getSkinId();
+
+ parent::setUp();
+ }
+
+ protected function tearDown() {
+ $aFS = $this->aFlexiskin;
+ $oStatus = BsFileSystemHelper::deleteFolder( "flexiskin" . DS .
$this->getSkinId() );
+ parent::tearDown();
+ }
+
+ protected function getModuleName () {
+ return 'bs-flexiskin-upload-store';
+ }
+
+ public function provideSingleFilterData () {
+ return [
+ 'Filter by filename' => [ 'string', 'ct', 'filename',
'te', 1 ]
+ ];
+ }
+
+ public function provideMultipleFilterData () {
+ return [
+ 'Filter by filename and extension' => [
+ [
+ [
+ 'type' => 'string',
+ 'comparison' => 'ct',
+ 'field' => 'filename',
+ 'value' => 'test'
+ ],
+ [
+ 'type' => 'string',
+ 'comparison' => 'eq',
+ 'field' => 'extension',
+ 'value' => 'png'
+ ]
+ ],
+ 1
+ ]
+ ];
+ }
+}
diff --git a/Flexiskin/tests/phpunit/BSApiFlexiskinUploadTest.php
b/Flexiskin/tests/phpunit/BSApiFlexiskinUploadTest.php
new file mode 100644
index 0000000..710d41b
--- /dev/null
+++ b/Flexiskin/tests/phpunit/BSApiFlexiskinUploadTest.php
@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * @group medium
+ */
+class BSApiFlexiskinUploadTest extends BSApiTasksTestBase {
+ protected function getModuleName () {
+ return 'bs-flexiskin-upload';
+ }
+}
diff --git a/Flexiskin/tests/phpunit/data/dummy.PNG
b/Flexiskin/tests/phpunit/data/dummy.PNG
new file mode 100644
index 0000000..3fd7036
--- /dev/null
+++ b/Flexiskin/tests/phpunit/data/dummy.PNG
Binary files differ
diff --git a/Flexiskin/tests/phpunit/data/test.PNG
b/Flexiskin/tests/phpunit/data/test.PNG
new file mode 100644
index 0000000..2933343
--- /dev/null
+++ b/Flexiskin/tests/phpunit/data/test.PNG
Binary files differ
--
To view, visit https://gerrit.wikimedia.org/r/346976
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2da576444eee183d36b9cf9fa3b1647f1a4515ae
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: ItSpiderman <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits