ItSpiderman has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/342196 )

Change subject: API Unittest: InsertMagic
......................................................................

API Unittest: InsertMagic

Change-Id: I80ccc865ff31c6a66a9c6b7d7d2a5f350c97b44f
ERM: #5804
---
M InsertMagic/InsertMagic.class.php
M InsertMagic/extension.json
A InsertMagic/tests/phpunit/BSApiInsertMagicDataStoreTest.php
3 files changed, 73 insertions(+), 0 deletions(-)


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

diff --git a/InsertMagic/InsertMagic.class.php 
b/InsertMagic/InsertMagic.class.php
index 14618dd..4a84d1a 100644
--- a/InsertMagic/InsertMagic.class.php
+++ b/InsertMagic/InsertMagic.class.php
@@ -150,4 +150,16 @@
                array_splice( $aConfigOverwrite["toolbar2"], $iIndexOverwrite + 
1, 0, "bsmagic" );
                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;
+       }
 }
\ No newline at end of file
diff --git a/InsertMagic/extension.json b/InsertMagic/extension.json
index d1347af..bcb4bcb 100644
--- a/InsertMagic/extension.json
+++ b/InsertMagic/extension.json
@@ -23,6 +23,9 @@
                        "i18n"
                ]
        },
+       "Hooks": {
+               "UnitTestsList":"InsertMagic::"
+       }
        "AutoloadClasses": {
                "InsertMagic": "InsertMagic.class.php",
                "BSApiInsertMagicDataStore": 
"includes/api/BSApiInsertMagicDataStore.php"
diff --git a/InsertMagic/tests/phpunit/BSApiInsertMagicDataStoreTest.php 
b/InsertMagic/tests/phpunit/BSApiInsertMagicDataStoreTest.php
new file mode 100644
index 0000000..d5bb27c
--- /dev/null
+++ b/InsertMagic/tests/phpunit/BSApiInsertMagicDataStoreTest.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * @group medium
+ */
+class BSApiInsertMagicDataStoreTest extends ApiTestCase {
+
+       protected function setUp () {
+               parent::setUp ();
+       }
+
+       protected function tearDown () {
+               parent::tearDown ();
+       }
+
+       /**
+        * @group medium
+        */
+       public function testMakeData () {
+               $data = $this->doApiRequest ( [
+                       'action' => 'bs-insertmagic-data-store',
+                       'limit' => 9999
+               ] );
+
+               $this->assertArrayHasKey ( 'total', $data[ 0 ] );
+               $this->assertArrayHasKey ( 'results', $data[ 0 ] );
+
+               //check if total is equal to results number
+               $this->assertEquals ( $data[ 0 ][ 'total' ], count ( $data[ 0 
][ 'results' ] ) );
+
+               //Ensure there is at least one group data to test against
+               $this->assertGreaterThan ( 0, $data[ 0 ][ 'total' ] );
+
+               foreach ( $data[ 0 ][ "results" ] as $magicWord ) {
+                       $this->assertArrayHasKey ( 'id', $magicWord );
+                       $this->assertArrayHasKey ( 'type', $magicWord );
+                       $this->assertArrayHasKey ( 'name', $magicWord );
+                       $this->assertArrayHasKey ( 'desc', $magicWord );
+                       $this->assertArrayHasKey ( 'code', $magicWord );
+                       
+                       if ( array_key_exists ( 'previewable', $magicWord ) ) {
+                               $this->assertThat ( $magicWord[ 'previewable' 
], $this->logicalOr (
+                                       $this->equalTo ( true ), $this->equalTo 
( false )
+                               ) );
+                       }
+
+                       if ( array_key_exists ( 'examples', $magicWord ) ) {
+                               $this->assertType ( 'array', $magicWord[ 
'examples' ] );
+                       }
+                       if ( array_key_exists ( 'helplink', $magicWord ) ) {
+                               $this->assertType ( 'string', $magicWord[ 
'helplink' ] );
+                       }
+               }
+
+               return $data;
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/342196
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I80ccc865ff31c6a66a9c6b7d7d2a5f350c97b44f
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

Reply via email to