Added some PHPUnit Tests
This commit is contained in:
parent
879b3056ce
commit
5e0a5c48a2
@ -33,7 +33,7 @@ class CallbackHelpStructure extends DocumentationStructure {
|
||||
* @api
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMethodName() {
|
||||
public function getCallbackName() {
|
||||
return $this->callbackName;
|
||||
}
|
||||
|
||||
|
@ -589,7 +589,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
||||
$this->getChat()->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
|
||||
|
||||
$this->startTime = time();
|
||||
|
||||
|
||||
// Main loop
|
||||
while (!$this->requestQuitMessage) {
|
||||
$this->loop();
|
||||
@ -613,8 +613,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
||||
|
||||
/**
|
||||
* Connect to ManiaPlanet server
|
||||
* Public only for PHPUnit Tests
|
||||
*/
|
||||
private function connect() {
|
||||
public function connect() {
|
||||
// Load remote client
|
||||
$serverConfig = $this->getServer()->loadConfig();
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace ManiaControl\Script;
|
||||
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\Callbacks\Structures\XmlRpc\CallbackListStructure;
|
||||
use ManiaControl\General\UsageInformationAble;
|
||||
use ManiaControl\General\UsageInformationTrait;
|
||||
use ManiaControl\ManiaControl;
|
||||
@ -38,6 +39,7 @@ class ModeScriptEventManager implements UsageInformationAble {
|
||||
$this->maniaControl->getClient()->triggerModeScriptEvent('XmlRpc.EnableCallbacks', array('true'));
|
||||
|
||||
$this->setApiVersion(self::API_VERSION);
|
||||
$this->unBlockAllCallbacks();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +82,18 @@ class ModeScriptEventManager implements UsageInformationAble {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a Array of Callbacks you want to Block
|
||||
* UnBlocks All Callbacks
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function unBlockAllCallbacks() {
|
||||
$this->getListOfDisabledCallbacks()->setCallable(function (CallbackListStructure $structure) {
|
||||
$this->unBlockCallbacks($structure->getCallbacks());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a Array of Callbacks you want to UnBlock
|
||||
*
|
||||
* @api
|
||||
* @param array $callbackNames
|
||||
@ -325,7 +338,7 @@ class ModeScriptEventManager implements UsageInformationAble {
|
||||
* @param $y
|
||||
* @param $z
|
||||
*/
|
||||
public function suegeSetProgressionUIPosition($x, $y, $z) {
|
||||
public function siegeSetProgressionUIPosition($x, $y, $z) {
|
||||
$this->maniaControl->getClient()->triggerModeScriptEvent('Shootmania.Siege.SetProgressionUIPosition', array(strval(floatval($x)), strval(floatval($y)), strval(floatval($z))));
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,13 @@
|
||||
|
||||
use ManiaControl\Logger;
|
||||
|
||||
/**
|
||||
* PHP Unit Test for Logger Class
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2017 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class LoggerTest extends PHPUnit_Framework_TestCase {
|
||||
public function testGetLogsFolder(){
|
||||
$this->assertEquals(Logger::getLogsFolder(), MANIACONTROL_PATH . 'logs' . DIRECTORY_SEPARATOR);
|
||||
|
@ -2,6 +2,13 @@
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* PHP Unit Test for Mania Control Class
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2017 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ManiaControlTest extends PHPUnit_Framework_TestCase {
|
||||
public function testRun(){
|
||||
$maniaControl = new ManiaControl();
|
||||
@ -9,6 +16,7 @@ class ManiaControlTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
sleep(15);
|
||||
|
||||
$this->assertNotNull($maniaControl->getBillManager());
|
||||
//$this->l
|
||||
//$this->assertNull($maniaControl);
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Lukas
|
||||
* Date: 15. Apr. 2017
|
||||
* Time: 22:44
|
||||
*/
|
||||
|
||||
namespace Tests\core\Update;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Utils\WebReader;
|
||||
|
||||
/**
|
||||
* PHP Unit Test for Plugin Update Manager Class
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2017 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PluginUpdateManagerTest extends \PHPUnit_Framework_TestCase {
|
||||
public function testWebReaderAndPluginsWebservice() {
|
||||
$url = ManiaControl::URL_WEBSERVICE . 'plugins';
|
||||
@ -33,9 +34,11 @@ class PluginUpdateManagerTest extends \PHPUnit_Framework_TestCase {
|
||||
//No Plugins Running so No new Updates
|
||||
$this->assertFalse($pluginUpdateManager->getPluginsUpdates());
|
||||
|
||||
$maniaControl->run(5);
|
||||
$maniaControl->run(10);
|
||||
|
||||
$this->assertNotFalse($pluginUpdateManager->getPluginsUpdates());
|
||||
//$this->assertNotFalse($pluginUpdateManager->getPluginsUpdates()); //failed manchmal
|
||||
//TODO load Plugin manually and then test (could happen that no update is existing)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,18 @@
|
||||
|
||||
namespace Tests\core\Update;
|
||||
|
||||
|
||||
use ManiaControl\Files\BackupUtil;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Update\UpdateData;
|
||||
use ManiaControl\Update\UpdateManager;
|
||||
|
||||
/**
|
||||
* PHP Unit Test for Update Manager Class
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2017 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
final class UpdateManagerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private function getBuildDateFileName() {
|
||||
|
233
phpunittests/core/script/ModeScriptEventManagerTest.php
Normal file
233
phpunittests/core/script/ModeScriptEventManagerTest.php
Normal file
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\core\script;
|
||||
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\Callbacks\Structures\XmlRpc\AllApiVersionsStructure;
|
||||
use ManiaControl\Callbacks\Structures\XmlRpc\ApiVersionStructure;
|
||||
use ManiaControl\Callbacks\Structures\XmlRpc\CallbackHelpStructure;
|
||||
use ManiaControl\Callbacks\Structures\XmlRpc\CallbackListStructure;
|
||||
use ManiaControl\Callbacks\Structures\XmlRpc\DocumentationStructure;
|
||||
use ManiaControl\Callbacks\Structures\XmlRpc\MethodHelpStructure;
|
||||
use ManiaControl\Callbacks\Structures\XmlRpc\MethodListStructure;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Script\ModeScriptEventManager;
|
||||
|
||||
/**
|
||||
* PHP Unit Test for Mode Script Event Manager Class
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2017 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ModeScriptEventManagerTest extends \PHPUnit_Framework_TestCase {
|
||||
public function testEnableCallbacks() {
|
||||
$maniaControl = new ManiaControl();
|
||||
$maniaControl->connect();
|
||||
|
||||
$modeScriptEventManager = $maniaControl->getModeScriptEventManager();
|
||||
$modeScriptEventManager->enableCallbacks();
|
||||
|
||||
$called = false;
|
||||
$modeScriptEventManager->getApiVersion()->setCallable(function (ApiVersionStructure $structure) use (&$called) {
|
||||
$called = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
$this->assertEquals(ModeScriptEventManager::API_VERSION, $structure->getVersion());
|
||||
});
|
||||
|
||||
$maniaControl->run(3);
|
||||
|
||||
$this->assertTrue($called);
|
||||
|
||||
//Disable Callbacks and Test Again
|
||||
$maniaControl->connect();
|
||||
$modeScriptEventManager->disableCallbacks();
|
||||
|
||||
$called = false;
|
||||
$modeScriptEventManager->getApiVersion()->setCallable(function (ApiVersionStructure $structure) use (&$called) {
|
||||
$called = true;
|
||||
});
|
||||
|
||||
$maniaControl->run(3);
|
||||
|
||||
$this->assertFalse($called);
|
||||
}
|
||||
|
||||
public function testGetCallbacksList() {
|
||||
$maniaControl = new ManiaControl();
|
||||
$maniaControl->connect();
|
||||
|
||||
$modeScriptEventManager = $maniaControl->getModeScriptEventManager();
|
||||
$modeScriptEventManager->enableCallbacks();
|
||||
|
||||
$called = false;
|
||||
$modeScriptEventManager->getCallbacksList()->setCallable(function (CallbackListStructure $structure) use (&$called) {
|
||||
$called = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
//At least 5 Callbacks existing
|
||||
$this->assertArrayHasKey(5, $structure->getCallbacks());
|
||||
});
|
||||
|
||||
$maniaControl->run(3);
|
||||
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testBlockUnBlockCallbacks() {
|
||||
$maniaControl = new ManiaControl();
|
||||
$maniaControl->connect();
|
||||
|
||||
$modeScriptEventManager = $maniaControl->getModeScriptEventManager();
|
||||
$modeScriptEventManager->enableCallbacks();
|
||||
|
||||
$called1 = false;
|
||||
$modeScriptEventManager->getListOfEnabledCallbacks()->setCallable(function (CallbackListStructure $structure) use (&$called1) {
|
||||
$called1 = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
//At least 5 Callbacks existing
|
||||
$this->assertArrayHasKey(5, $structure->getCallbacks());
|
||||
});
|
||||
|
||||
$called2 = false;
|
||||
$modeScriptEventManager->getListOfDisabledCallbacks()->setCallable(function (CallbackListStructure $structure) use (&$called2) {
|
||||
$called2 = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
//Has No Callback
|
||||
$this->assertEmpty($structure->getCallbacks());
|
||||
});
|
||||
|
||||
//Block a Callback
|
||||
$modeScriptEventManager->blockCallback(Callbacks::MP_ENDPLAYLOOP);
|
||||
|
||||
$called3 = false;
|
||||
$modeScriptEventManager->getListOfDisabledCallbacks()->setCallable(function (CallbackListStructure $structure) use (&$called3) {
|
||||
$called3 = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
$structure->getCallbacks();
|
||||
//Has No Callback
|
||||
$this->assertArrayHasKey(0, $structure->getCallbacks());
|
||||
$this->assertEquals(Callbacks::MP_ENDPLAYLOOP, $structure->getCallbacks()[0]);
|
||||
});
|
||||
|
||||
$modeScriptEventManager->unBlockCallback(Callbacks::MP_ENDPLAYLOOP);
|
||||
|
||||
$called4 = false;
|
||||
$modeScriptEventManager->getListOfDisabledCallbacks()->setCallable(function (CallbackListStructure $structure) use (&$called4) {
|
||||
$called4 = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
//Has No Callback
|
||||
$this->assertEmpty($structure->getCallbacks());
|
||||
});
|
||||
|
||||
$maniaControl->run(5);
|
||||
|
||||
$this->assertTrue($called1);
|
||||
$this->assertTrue($called2);
|
||||
$this->assertTrue($called3);
|
||||
$this->assertTrue($called4);
|
||||
}
|
||||
|
||||
public function testGetCallbackHelp() {
|
||||
$maniaControl = new ManiaControl();
|
||||
$maniaControl->connect();
|
||||
|
||||
$modeScriptEventManager = $maniaControl->getModeScriptEventManager();
|
||||
$modeScriptEventManager->enableCallbacks();
|
||||
|
||||
$called = false;
|
||||
$modeScriptEventManager->getCallbackHelp(Callbacks::SM_ONCAPTURE)->setCallable(function (CallbackHelpStructure $structure) use (&$called) {
|
||||
$called = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
$this->assertEquals(Callbacks::SM_ONCAPTURE, $structure->getCallbackName());
|
||||
$this->assertContains($structure->getCallbackName(), $structure->getDocumentation());
|
||||
});
|
||||
|
||||
$maniaControl->run(3);
|
||||
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testGetMethodsList() {
|
||||
$maniaControl = new ManiaControl();
|
||||
$maniaControl->connect();
|
||||
|
||||
$modeScriptEventManager = $maniaControl->getModeScriptEventManager();
|
||||
$modeScriptEventManager->enableCallbacks();
|
||||
|
||||
$called = false;
|
||||
$modeScriptEventManager->getMethodsList()->setCallable(function (MethodListStructure $structure) use (&$called) {
|
||||
$called = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
//Has at Least 10 Methods
|
||||
$this->assertArrayHasKey(10, $structure->getMethods());
|
||||
});
|
||||
|
||||
$maniaControl->run(3);
|
||||
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testGetMethodHelp() {
|
||||
$maniaControl = new ManiaControl();
|
||||
$maniaControl->connect();
|
||||
|
||||
$modeScriptEventManager = $maniaControl->getModeScriptEventManager();
|
||||
$modeScriptEventManager->enableCallbacks();
|
||||
|
||||
$called = false;
|
||||
$modeScriptEventManager->getMethodHelp('XmlRpc.GetMethodHelp')->setCallable(function (MethodHelpStructure $structure) use (&$called) {
|
||||
$called = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
$this->assertEquals('XmlRpc.GetMethodHelp', $structure->getMethodName());
|
||||
$this->assertContains("Name", $structure->getDocumentation());
|
||||
$this->assertContains("XmlRpc.GetMethodHelp", $structure->getDocumentation());
|
||||
$this->assertContains("Version", $structure->getDocumentation());
|
||||
});
|
||||
|
||||
$maniaControl->run(3);
|
||||
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testGetDocumentation(){
|
||||
$maniaControl = new ManiaControl();
|
||||
$maniaControl->connect();
|
||||
|
||||
$modeScriptEventManager = $maniaControl->getModeScriptEventManager();
|
||||
$modeScriptEventManager->enableCallbacks();
|
||||
|
||||
$called = false;
|
||||
$modeScriptEventManager->getDocumentation()->setCallable(function (DocumentationStructure $structure) use (&$called) {
|
||||
$called = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
$this->assertContains("Name", $structure->getDocumentation());
|
||||
$this->assertContains("XmlRpc.GetMethodHelp", $structure->getDocumentation());
|
||||
$this->assertContains("Version", $structure->getDocumentation());
|
||||
});
|
||||
|
||||
$maniaControl->run(3);
|
||||
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testGetAllApiVersions(){
|
||||
$maniaControl = new ManiaControl();
|
||||
$maniaControl->connect();
|
||||
|
||||
$modeScriptEventManager = $maniaControl->getModeScriptEventManager();
|
||||
$modeScriptEventManager->enableCallbacks();
|
||||
|
||||
$called = false;
|
||||
$modeScriptEventManager->getAllApiVersions()->setCallable(function (AllApiVersionsStructure $structure) use (&$called) {
|
||||
$called = true;
|
||||
$this->assertJson($structure->toJson());
|
||||
|
||||
$this->assertArrayHasKey(0, $structure->getVersions());
|
||||
$this->assertContains(".", $structure->getLatest()); // like 2.0.0 (just check if a dot is in)
|
||||
});
|
||||
|
||||
$maniaControl->run(3);
|
||||
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user