diff --git a/core/Callbacks/Structures/XmlRpc/CallbackHelpStructure.php b/core/Callbacks/Structures/XmlRpc/CallbackHelpStructure.php index 23230721..7acad8f9 100644 --- a/core/Callbacks/Structures/XmlRpc/CallbackHelpStructure.php +++ b/core/Callbacks/Structures/XmlRpc/CallbackHelpStructure.php @@ -33,7 +33,7 @@ class CallbackHelpStructure extends DocumentationStructure { * @api * @return mixed */ - public function getMethodName() { + public function getCallbackName() { return $this->callbackName; } diff --git a/core/ManiaControl.php b/core/ManiaControl.php index 0b6d9d2b..b5940c4e 100644 --- a/core/ManiaControl.php +++ b/core/ManiaControl.php @@ -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(); diff --git a/core/Script/ModeScriptEventManager.php b/core/Script/ModeScriptEventManager.php index d76a5fd5..272b68d7 100644 --- a/core/Script/ModeScriptEventManager.php +++ b/core/Script/ModeScriptEventManager.php @@ -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)))); } diff --git a/phpunittests/core/LoggerTest.php b/phpunittests/core/LoggerTest.php index a1a9e0dc..435622a8 100644 --- a/phpunittests/core/LoggerTest.php +++ b/phpunittests/core/LoggerTest.php @@ -2,6 +2,13 @@ use ManiaControl\Logger; +/** + * PHP Unit Test for Logger Class + * + * @author ManiaControl Team + * @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); diff --git a/phpunittests/core/ManiaControlTest.php b/phpunittests/core/ManiaControlTest.php index c7e111fb..dbbefe85 100644 --- a/phpunittests/core/ManiaControlTest.php +++ b/phpunittests/core/ManiaControlTest.php @@ -2,6 +2,13 @@ use ManiaControl\ManiaControl; +/** + * PHP Unit Test for Mania Control Class + * + * @author ManiaControl Team + * @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); } diff --git a/phpunittests/core/Update/PluginUpdateManagerTest.php b/phpunittests/core/Update/PluginUpdateManagerTest.php index 73a117dd..43a85714 100644 --- a/phpunittests/core/Update/PluginUpdateManagerTest.php +++ b/phpunittests/core/Update/PluginUpdateManagerTest.php @@ -1,16 +1,17 @@ + * @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) } + + } diff --git a/phpunittests/core/Update/UpdateManagerTest.php b/phpunittests/core/Update/UpdateManagerTest.php index 2e24f149..b9561533 100644 --- a/phpunittests/core/Update/UpdateManagerTest.php +++ b/phpunittests/core/Update/UpdateManagerTest.php @@ -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 + * @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() { diff --git a/phpunittests/core/script/ModeScriptEventManagerTest.php b/phpunittests/core/script/ModeScriptEventManagerTest.php new file mode 100644 index 00000000..2d5b40a5 --- /dev/null +++ b/phpunittests/core/script/ModeScriptEventManagerTest.php @@ -0,0 +1,233 @@ + + * @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); + } +}