Fixed Bug in Windows in Webreader
This commit is contained in:
		
							
								
								
									
										28
									
								
								Tests/core/Update/PluginUpdateManagerTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								Tests/core/Update/PluginUpdateManagerTest.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Created by PhpStorm.
 | 
				
			||||||
 | 
					 * User: Lukas
 | 
				
			||||||
 | 
					 * Date: 15. Apr. 2017
 | 
				
			||||||
 | 
					 * Time: 22:44
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Tests\core\Update;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use ManiaControl\ManiaControl;
 | 
				
			||||||
 | 
					use ManiaControl\Update\PluginUpdateManager;
 | 
				
			||||||
 | 
					use ManiaControl\Utils\WebReader;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PluginUpdateManagerTest extends \PHPUnit_Framework_TestCase {
 | 
				
			||||||
 | 
						public function testGetPluginUpdates(){
 | 
				
			||||||
 | 
							$maniaControl  = new ManiaControl();
 | 
				
			||||||
 | 
							$updateManager = $maniaControl->getUpdateManager();
 | 
				
			||||||
 | 
							$pluginUpdateManager = $updateManager->getPluginUpdateManager();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var_dump($pluginUpdateManager->getPluginsUpdates());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$url        = ManiaControl::URL_WEBSERVICE . 'plugins';
 | 
				
			||||||
 | 
							$response   = WebReader::getUrl($url);
 | 
				
			||||||
 | 
							$dataJson   = $response->getContent();
 | 
				
			||||||
 | 
							var_dump($dataJson);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -10,11 +10,15 @@ use ManiaControl\Update\UpdateManager;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
final class UpdateManagerTest extends \PHPUnit_Framework_TestCase {
 | 
					final class UpdateManagerTest extends \PHPUnit_Framework_TestCase {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private function getBuildDateFileName() {
 | 
				
			||||||
 | 
							return MANIACONTROL_PATH . "core" . DIRECTORY_SEPARATOR . UpdateManager::BUILD_DATE_FILE_NAME;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function testBuildDate() {
 | 
						public function testBuildDate() {
 | 
				
			||||||
		$maniaControl  = new ManiaControl();
 | 
							$maniaControl  = new ManiaControl();
 | 
				
			||||||
		$updateManager = new UpdateManager($maniaControl);
 | 
							$updateManager = new UpdateManager($maniaControl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$fileName = MANIACONTROL_PATH . "core" . DIRECTORY_SEPARATOR . UpdateManager::BUILD_DATE_FILE_NAME;
 | 
							$fileName = $this->getBuildDateFileName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!file_exists($fileName)) {
 | 
							if (!file_exists($fileName)) {
 | 
				
			||||||
			$this->assertTrue($updateManager->setBuildDate("BuildDateTest-6543210"));
 | 
								$this->assertTrue($updateManager->setBuildDate("BuildDateTest-6543210"));
 | 
				
			||||||
@@ -101,6 +105,43 @@ final class UpdateManagerTest extends \PHPUnit_Framework_TestCase {
 | 
				
			|||||||
		$updateManager->setCoreUpdateData($updateData);
 | 
							$updateManager->setCoreUpdateData($updateData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Methods should return its non closure success
 | 
							//Methods should return its non closure success
 | 
				
			||||||
		$this->assertTrue($updateManager->performCoreUpdate());
 | 
							$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
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@
 | 
				
			|||||||
		 beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutChangesToGlobalState="true">
 | 
							 beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutChangesToGlobalState="true">
 | 
				
			||||||
	<testsuites>
 | 
						<testsuites>
 | 
				
			||||||
		<testsuite name="ManiaControl">
 | 
							<testsuite name="ManiaControl">
 | 
				
			||||||
			<directory>Tests</directory>
 | 
								<directory>core</directory>
 | 
				
			||||||
		</testsuite>
 | 
							</testsuite>
 | 
				
			||||||
	</testsuites>
 | 
						</testsuites>
 | 
				
			||||||
	<filter>
 | 
						<filter>
 | 
				
			||||||
@@ -16,10 +16,10 @@
 | 
				
			|||||||
		<log type="coverage-clover" target="build/logs/clover.xml"/>
 | 
							<log type="coverage-clover" target="build/logs/clover.xml"/>
 | 
				
			||||||
	</logging>
 | 
						</logging>
 | 
				
			||||||
	<php>
 | 
						<php>
 | 
				
			||||||
		<!--<ini name="error_reporting" value="E_ALL"/>
 | 
							<ini name="error_reporting" value="E_ALL"/>
 | 
				
			||||||
		<ini name="display_errors" value="On"/>
 | 
							<ini name="display_errors" value="On"/>
 | 
				
			||||||
		<ini name="display_startup_errors" value="On"/>
 | 
							<ini name="display_startup_errors" value="On"/>
 | 
				
			||||||
		<get name="test-get-name" value="test-get-value"/>
 | 
							<get name="test-get-name" value="test-get-value"/>
 | 
				
			||||||
		<post name="test-post-name" value="test-post-value"/>-->
 | 
							<post name="test-post-name" value="test-post-value"/>
 | 
				
			||||||
	</php>
 | 
						</php>
 | 
				
			||||||
</phpunit>
 | 
					</phpunit>
 | 
				
			||||||
@@ -520,7 +520,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
 | 
				
			|||||||
		Logger::log('Restarting ManiaControl... ' . $message);
 | 
							Logger::log('Restarting ManiaControl... ' . $message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Start new instance
 | 
							// Start new instance
 | 
				
			||||||
 | 
							if (!defined('PHP_UNIT_TEST')) {
 | 
				
			||||||
			SystemUtil::restart();
 | 
								SystemUtil::restart();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Quit old instance
 | 
							// Quit old instance
 | 
				
			||||||
		$this->quit('Quitting ManiaControl to restart.');
 | 
							$this->quit('Quitting ManiaControl to restart.');
 | 
				
			||||||
@@ -690,7 +692,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
 | 
				
			|||||||
		$loopStart = microtime(true);
 | 
							$loopStart = microtime(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Extend script timeout
 | 
							// Extend script timeout
 | 
				
			||||||
		if(!defined('PHP_UNIT_TEST')){
 | 
							if (!defined('PHP_UNIT_TEST')) {
 | 
				
			||||||
			set_time_limit(self::SCRIPT_TIMEOUT);
 | 
								set_time_limit(self::SCRIPT_TIMEOUT);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -204,6 +204,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
 | 
				
			|||||||
		$response   = WebReader::getUrl($url);
 | 
							$response   = WebReader::getUrl($url);
 | 
				
			||||||
		$dataJson   = $response->getContent();
 | 
							$dataJson   = $response->getContent();
 | 
				
			||||||
		$pluginData = json_decode($dataJson);
 | 
							$pluginData = json_decode($dataJson);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!$pluginData || empty($pluginData)) {
 | 
							if (!$pluginData || empty($pluginData)) {
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -377,12 +377,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
 | 
				
			|||||||
				return;
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if(!defined('PHP_UNIT_TEST')){
 | 
								//Don't overwrite the files while testing
 | 
				
			||||||
 | 
								if (!defined('PHP_UNIT_TEST')) {
 | 
				
			||||||
				$zip->extractTo(MANIACONTROL_PATH);
 | 
									$zip->extractTo(MANIACONTROL_PATH);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			$zip->close();
 | 
								$zip->close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			unlink($updateFileName);
 | 
								unlink($updateFileName);
 | 
				
			||||||
			FileUtil::deleteTempFolder();
 | 
								FileUtil::deleteTempFolder();
 | 
				
			||||||
			}
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Set the build date
 | 
								// Set the build date
 | 
				
			||||||
			$this->setBuildDate($updateData->releaseDate);
 | 
								$this->setBuildDate($updateData->releaseDate);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,6 @@ use ManiaControl\ManiaControl;
 | 
				
			|||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
abstract class WebReader {
 | 
					abstract class WebReader {
 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Load a URL via GET
 | 
						 * Load a URL via GET
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -58,10 +57,12 @@ abstract class WebReader {
 | 
				
			|||||||
		        ->set(CURLOPT_ENCODING, '')// accept encoding
 | 
							        ->set(CURLOPT_ENCODING, '')// accept encoding
 | 
				
			||||||
		        ->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION)// user-agent
 | 
							        ->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION)// user-agent
 | 
				
			||||||
		        ->set(CURLOPT_RETURNTRANSFER, true)// return instead of output content
 | 
							        ->set(CURLOPT_RETURNTRANSFER, true)// return instead of output content
 | 
				
			||||||
		        ->set(CURLOPT_AUTOREFERER, true); // follow redirects
 | 
							        ->set(CURLOPT_AUTOREFERER, true)// follow redirects
 | 
				
			||||||
 | 
							        ->set(CURLOPT_SSL_VERIFYPEER, false);
 | 
				
			||||||
		return $request;
 | 
							return $request;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Perform the given callback function with the response
 | 
						 * Perform the given callback function with the response
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user