renamed tests folder

This commit is contained in:
kremsy 2017-04-15 23:20:36 +02:00
parent ba6d122447
commit 23d9ade5cf
6 changed files with 255 additions and 0 deletions

10
phpunittests/autoload.php Normal file
View File

@ -0,0 +1,10 @@
<?php
// Define base dir
define('MANIACONTROL_PATH', realpath(__DIR__ . '/..') . DIRECTORY_SEPARATOR);
define('DEV_MODE', true); // Development mode to not send error reports etc.
define('PHP_UNIT_TEST', true);
// Register AutoLoader
require_once MANIACONTROL_PATH . 'core' . DIRECTORY_SEPARATOR . 'AutoLoader.php';
\ManiaControl\AutoLoader::register();

View File

@ -0,0 +1,9 @@
<?php
use ManiaControl\Logger;
class LoggerTest extends PHPUnit_Framework_TestCase {
public function testGetLogsFolder(){
$this->assertEquals(Logger::getLogsFolder(), MANIACONTROL_PATH . 'logs' . DIRECTORY_SEPARATOR);
}
}

View File

@ -0,0 +1,23 @@
<?php
use ManiaControl\ManiaControl;
class ManiaControlTest extends PHPUnit_Framework_TestCase {
public function testRun(){
$maniaControl = new ManiaControl();
$maniaControl->run(10);
sleep(15);
//$this->l
//$this->assertNull($maniaControl);
}
/* public function testGetClient(){
$maniaControl = new ManiaControl();
$mcClient = $maniaControl->getClient();
//$maniaControl->connect();
//$mpClient = new Maniaplanet\DedicatedServer\Connection();
}*/
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Created by PhpStorm.
* User: Lukas
* Date: 15. Apr. 2017
* Time: 22:44
*/
namespace Tests\core\Update;
use ManiaControl\ManiaControl;
use ManiaControl\Utils\WebReader;
class PluginUpdateManagerTest extends \PHPUnit_Framework_TestCase {
public function testWebReaderAndPluginsWebservice() {
$url = ManiaControl::URL_WEBSERVICE . 'plugins';
$response = WebReader::getUrl($url);
$dataJson = $response->getContent();
$this->assertJson($dataJson);
$data = json_decode($dataJson);
$this->assertEquals(8, $data[0]->id);
$this->assertEquals("https://download.maniacontrol.com/plugins/8_Dedimania_Plugin_v0.1.zip", $data[0]->currentVersion->url);
}
public function testGetPluginUpdates() {
$maniaControl = new ManiaControl();
$updateManager = $maniaControl->getUpdateManager();
$pluginUpdateManager = $updateManager->getPluginUpdateManager();
//No Plugins Running so No new Updates
$this->assertFalse($pluginUpdateManager->getPluginsUpdates());
$maniaControl->run(5);
$this->assertNotFalse($pluginUpdateManager->getPluginsUpdates());
//TODO load Plugin manually and then test (could happen that no update is existing)
}
}

View File

@ -0,0 +1,147 @@
<?php
namespace Tests\core\Update;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Update\UpdateData;
use ManiaControl\Update\UpdateManager;
final class UpdateManagerTest extends \PHPUnit_Framework_TestCase {
private function getBuildDateFileName() {
return MANIACONTROL_PATH . "core" . DIRECTORY_SEPARATOR . UpdateManager::BUILD_DATE_FILE_NAME;
}
public function testBuildDate() {
$maniaControl = new ManiaControl();
$updateManager = new UpdateManager($maniaControl);
$fileName = $this->getBuildDateFileName();
if (!file_exists($fileName)) {
$this->assertTrue($updateManager->setBuildDate("BuildDateTest-6543210"));
}
$this->assertFileExists($fileName);
$buildDate = $updateManager->getBuildDate();
$this->assertStringEqualsFile($fileName, $buildDate);
$this->assertTrue($updateManager->setBuildDate("BuildDateTest-0123456"));
$this->assertEquals($updateManager->getBuildDate(), "BuildDateTest-0123456");
$this->assertStringEqualsFile($fileName, $updateManager->getBuildDate());
}
public function testGetPluginUpdateManagerTest() {
$maniaControl = new ManiaControl();
$updateManager = new UpdateManager($maniaControl);
$pluginUpdateManager = $updateManager->getPluginUpdateManager();
$this->assertInstanceOf("ManiaControl\\Update\\PluginUpdateManager", $pluginUpdateManager);
}
public function testIsNightlyUpdateChannel() {
$maniaControl = new ManiaControl();
$updateManager = new UpdateManager($maniaControl);
$this->assertTrue($updateManager->isNightlyUpdateChannel(UpdateManager::CHANNEL_NIGHTLY));
$isNightly = $updateManager->isNightlyUpdateChannel(null);
$this->assertEquals($updateManager->isNightlyUpdateChannel($updateManager->getCurrentUpdateChannelSetting()), $isNightly);
}
public function testCheckCoreUpdateAsync() {
$maniaControl = new ManiaControl();
$updateManager = $maniaControl->getUpdateManager();
$called = false;
$function = function ($updateData) use (&$called) {
$called = true;
$this->assertNotNull($updateData);
$this->assertObjectHasAttribute("version", $updateData);
};
$updateManager->checkCoreUpdateAsync($function);
$maniaControl->run(6);
$this->assertTrue($called);
}
public function testPerformCoreUpdate() {
$maniaControl = new ManiaControl();
$updateManager = $maniaControl->getUpdateManager();
//No Update Data Available -> so Fail
$this->assertFalse($updateManager->performCoreUpdate());
//Should Also Fail with a Player
$player = new Player($maniaControl, true);
$this->assertFalse($updateManager->performCoreUpdate($player));
$message = '[ERROR] Update failed: No update Data available!';
$message = '[' . date('d-M-Y H:i:s e') . '] ' . $message . PHP_EOL;
//Check message
$this->assertContains($message, $this->getActualOutput());
$dataJson = '[{"id":"260","version":"0.166","channel":"nightly","min_dedicated_build":"2014-04-02_18_00","release_date":"2017-03-16 21:57:40","url":"https:\/\/download.maniacontrol.com\/nightly\/ManiaControl_nightly_0-166.zip"}]';
//Create and Test Core Update Data
$updateData = new UpdateData(json_decode($dataJson)[0]);
$this->assertEquals("0.166", $updateData->version);
$this->assertEquals("nightly", $updateData->channel);
$this->assertEquals("2014-04-02_18_00", $updateData->minDedicatedBuild);
$this->assertEquals("2017-03-16 21:57:40", $updateData->releaseDate);
$this->assertEquals("https://download.maniacontrol.com/nightly/ManiaControl_nightly_0-166.zip", $updateData->url);
$updateManager->setCoreUpdateData($updateData);
//Methods should return its non closure success
$this->assertTrue($updateManager->performCoreUpdate($player));
$maniaControl->run(5);
//Check if Tempfolder got Deleted
$tempFolder = MANIACONTROL_PATH . 'temp' . DIRECTORY_SEPARATOR;
$this->assertFileNotExists($tempFolder);
//Check if UpdateFileName got Deleted
$updateFileName = $tempFolder . basename($updateData->url);
$this->assertFileNotExists($updateFileName);
$fileName = $this->getBuildDateFileName();
$this->assertStringEqualsFile($fileName, $updateData->releaseDate);
$this->assertEquals($updateData->releaseDate, $updateManager->getBuildDate());
$this->assertContains("Update finished!", $this->getActualOutput());
}
public function testPerformCoreUpdateFailUrl() {
$maniaControl = new ManiaControl();
$updateManager = $maniaControl->getUpdateManager();
$dataJson = '[{"id":"260","version":"0.166","channel":"nightly","min_dedicated_build":"2014-04-02_18_00","release_date":"2017-03-16 21:57:40","url":"https:\/\/download.maniacontrol.com\/nightly\/ManiaControl_nightly_0-166.zip"}]';
//Create and Test Core Update Data
$updateData = new UpdateData(json_decode($dataJson)[0]);
$updateData->url = "Invalid_URL";
$updateManager->setCoreUpdateData($updateData);
$updateManager->performCoreUpdate();
$maniaControl->run(5);
$player = new Player($maniaControl, true);
$this->assertTrue($updateManager->performCoreUpdate($player));
$this->assertContains("[ERROR] Update failed: Couldn't load Update zip! Could not resolve host: Invalid_URL", $this->getActualOutput());
}
//TODO real test with download and unpack in a certain dir
}

25
phpunittests/phpunit.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="autoload.php" colors="true" verbose="true" debug="true"
beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutChangesToGlobalState="true">
<testsuites>
<testsuite name="ManiaControl">
<directory>core</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">../core</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="build/logs/coverage.html"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<php>
<ini name="error_reporting" value="E_ALL"/>
<ini name="display_errors" value="On"/>
<ini name="display_startup_errors" value="On"/>
<get name="test-get-name" value="test-get-value"/>
<post name="test-post-name" value="test-post-value"/>
</php>
</phpunit>