2017-04-15 13:21:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\core\Update;
|
|
|
|
|
|
|
|
|
|
|
|
use ManiaControl\ManiaControl;
|
2017-04-15 22:01:27 +02:00
|
|
|
use ManiaControl\Players\Player;
|
|
|
|
use ManiaControl\Update\UpdateData;
|
2017-04-15 13:21:49 +02:00
|
|
|
use ManiaControl\Update\UpdateManager;
|
|
|
|
|
|
|
|
final class UpdateManagerTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
2017-04-15 23:00:24 +02:00
|
|
|
private function getBuildDateFileName() {
|
|
|
|
return MANIACONTROL_PATH . "core" . DIRECTORY_SEPARATOR . UpdateManager::BUILD_DATE_FILE_NAME;
|
|
|
|
}
|
|
|
|
|
2017-04-15 13:21:49 +02:00
|
|
|
public function testBuildDate() {
|
|
|
|
$maniaControl = new ManiaControl();
|
|
|
|
$updateManager = new UpdateManager($maniaControl);
|
|
|
|
|
2017-04-15 23:00:24 +02:00
|
|
|
$fileName = $this->getBuildDateFileName();
|
2017-04-15 13:21:49 +02:00
|
|
|
|
2017-04-15 22:01:27 +02:00
|
|
|
if (!file_exists($fileName)) {
|
2017-04-15 13:21:49 +02:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2017-04-15 22:01:27 +02:00
|
|
|
public function testCheckCoreUpdateAsync() {
|
|
|
|
$maniaControl = new ManiaControl();
|
2017-04-15 13:21:49 +02:00
|
|
|
|
|
|
|
$updateManager = $maniaControl->getUpdateManager();
|
|
|
|
|
2017-04-15 22:01:27 +02:00
|
|
|
$called = false;
|
|
|
|
$function = function ($updateData) use (&$called) {
|
2017-04-15 13:21:49 +02:00
|
|
|
$called = true;
|
|
|
|
$this->assertNotNull($updateData);
|
|
|
|
$this->assertObjectHasAttribute("version", $updateData);
|
|
|
|
};
|
|
|
|
|
|
|
|
$updateManager->checkCoreUpdateAsync($function);
|
|
|
|
|
|
|
|
$maniaControl->run(6);
|
|
|
|
|
|
|
|
$this->assertTrue($called);
|
|
|
|
}
|
2017-04-15 22:01:27 +02:00
|
|
|
|
|
|
|
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
|
2017-04-15 23:00:24 +02:00
|
|
|
$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());
|
2017-04-15 22:01:27 +02:00
|
|
|
}
|
2017-04-15 23:00:24 +02:00
|
|
|
|
|
|
|
//TODO real test with download and unpack in a certain dir
|
2017-04-15 13:21:49 +02:00
|
|
|
}
|