2018-10-07 20:15:27 -04:00
|
|
|
<?php
|
2020-02-09 10:34:23 -05:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-10-07 20:15:27 -04:00
|
|
|
|
|
|
|
// this is in the same namespace as Install for mocking 'function_exists'
|
|
|
|
namespace Friendica\Core;
|
|
|
|
|
2019-07-26 09:54:14 -04:00
|
|
|
use Dice\Dice;
|
2020-01-19 16:23:44 -05:00
|
|
|
use Friendica\Core\Config\Cache;
|
2019-12-15 17:28:01 -05:00
|
|
|
use Friendica\DI;
|
2020-10-07 15:49:12 -04:00
|
|
|
use Friendica\Network\IHTTPResult;
|
2020-03-04 17:36:46 -05:00
|
|
|
use Friendica\Network\IHTTPRequest;
|
2018-11-01 08:44:47 -04:00
|
|
|
use Friendica\Test\MockedTest;
|
2018-10-07 20:15:27 -04:00
|
|
|
use Friendica\Test\Util\VFSTrait;
|
2019-07-09 15:44:02 -04:00
|
|
|
use Mockery\MockInterface;
|
2018-10-07 20:15:27 -04:00
|
|
|
|
2018-11-01 08:44:47 -04:00
|
|
|
class InstallerTest extends MockedTest
|
2018-10-07 20:15:27 -04:00
|
|
|
{
|
|
|
|
use VFSTrait;
|
2019-07-09 15:44:02 -04:00
|
|
|
|
|
|
|
/**
|
2020-01-18 14:59:39 -05:00
|
|
|
* @var \Friendica\Core\L10n|MockInterface
|
2019-07-09 15:44:02 -04:00
|
|
|
*/
|
|
|
|
private $l10nMock;
|
2020-03-04 17:36:46 -05:00
|
|
|
/**
|
|
|
|
* @var Dice|MockInterface
|
|
|
|
*/
|
|
|
|
private $dice;
|
2018-10-07 20:15:27 -04:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2018-11-01 08:44:47 -04:00
|
|
|
parent::setUp();
|
2018-10-07 20:15:27 -04:00
|
|
|
|
|
|
|
$this->setUpVfsDir();
|
2019-07-09 15:44:02 -04:00
|
|
|
|
2020-01-18 14:59:39 -05:00
|
|
|
$this->l10nMock = \Mockery::mock(\Friendica\Core\L10n::class);
|
2019-07-26 09:54:14 -04:00
|
|
|
|
|
|
|
/** @var Dice|MockInterface $dice */
|
2020-03-04 17:36:46 -05:00
|
|
|
$this->dice = \Mockery::mock(Dice::class)->makePartial();
|
|
|
|
$this->dice = $this->dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
|
2019-07-26 09:54:14 -04:00
|
|
|
|
2020-03-04 17:36:46 -05:00
|
|
|
$this->dice->shouldReceive('create')
|
2020-01-18 14:59:39 -05:00
|
|
|
->with(\Friendica\Core\L10n::class)
|
2019-07-26 09:54:14 -04:00
|
|
|
->andReturn($this->l10nMock);
|
|
|
|
|
2020-03-04 17:36:46 -05:00
|
|
|
DI::init($this->dice);
|
2019-07-09 15:44:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private function mockL10nT(string $text, $times = null)
|
|
|
|
{
|
2019-07-17 06:40:00 -04:00
|
|
|
$this->l10nMock->shouldReceive('t')->with($text)->andReturn($text)->times($times);
|
2018-10-07 20:15:27 -04:00
|
|
|
}
|
|
|
|
|
2018-11-01 08:44:47 -04:00
|
|
|
/**
|
2020-01-18 14:52:34 -05:00
|
|
|
* Mocking the DI::l10n()->t() calls for the function checks
|
2018-11-01 08:44:47 -04:00
|
|
|
*/
|
|
|
|
private function mockFunctionL10TCalls()
|
|
|
|
{
|
|
|
|
$this->mockL10nT('Apache mod_rewrite module', 1);
|
|
|
|
$this->mockL10nT('PDO or MySQLi PHP module', 1);
|
|
|
|
$this->mockL10nT('libCurl PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: libCURL PHP module required but not installed.', 1);
|
|
|
|
$this->mockL10nT('XML PHP module', 1);
|
|
|
|
$this->mockL10nT('GD graphics PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: GD graphics PHP module with JPEG support required but not installed.', 1);
|
|
|
|
$this->mockL10nT('OpenSSL PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: openssl PHP module required but not installed.', 1);
|
|
|
|
$this->mockL10nT('mb_string PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: mb_string PHP module required but not installed.', 1);
|
|
|
|
$this->mockL10nT('iconv PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: iconv PHP module required but not installed.', 1);
|
|
|
|
$this->mockL10nT('POSIX PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: POSIX PHP module required but not installed.', 1);
|
2018-12-22 17:56:57 -05:00
|
|
|
$this->mockL10nT('JSON PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: JSON PHP module required but not installed.', 1);
|
2019-02-16 16:13:19 -05:00
|
|
|
$this->mockL10nT('File Information PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: File Information PHP module required but not installed.', 1);
|
2018-11-01 08:44:47 -04:00
|
|
|
}
|
|
|
|
|
2018-10-07 20:15:27 -04:00
|
|
|
private function assertCheckExist($position, $title, $help, $status, $required, $assertionArray)
|
|
|
|
{
|
2019-12-21 18:36:29 -05:00
|
|
|
$subSet = [$position => [
|
2018-10-07 20:15:27 -04:00
|
|
|
'title' => $title,
|
|
|
|
'status' => $status,
|
|
|
|
'required' => $required,
|
|
|
|
'error_msg' => null,
|
|
|
|
'help' => $help]
|
2019-12-21 18:36:29 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->assertArraySubset($subSet, $assertionArray, false, "expected subset: " . PHP_EOL . print_r($subSet, true) . PHP_EOL . "current subset: " . print_r($assertionArray, true));
|
2018-10-07 20:15:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces function_exists results with given mocks
|
|
|
|
*
|
|
|
|
* @param array $functions a list from function names and their result
|
|
|
|
*/
|
|
|
|
private function setFunctions($functions)
|
|
|
|
{
|
|
|
|
global $phpMock;
|
|
|
|
$phpMock['function_exists'] = function($function) use ($functions) {
|
|
|
|
foreach ($functions as $name => $value) {
|
|
|
|
if ($function == $name) {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '__phpunit_continue__';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-23 06:31:15 -04:00
|
|
|
/**
|
|
|
|
* Replaces class_exist results with given mocks
|
|
|
|
*
|
|
|
|
* @param array $classes a list from class names and their results
|
|
|
|
*/
|
|
|
|
private function setClasses($classes)
|
|
|
|
{
|
|
|
|
global $phpMock;
|
|
|
|
$phpMock['class_exists'] = function($class) use ($classes) {
|
|
|
|
foreach ($classes as $name => $value) {
|
|
|
|
if ($class == $name) {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '__phpunit_continue__';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-07 20:15:27 -04:00
|
|
|
/**
|
|
|
|
* @small
|
|
|
|
*/
|
|
|
|
public function testCheckKeys()
|
|
|
|
{
|
2019-07-09 15:44:02 -04:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-01-30 14:26:17 -05:00
|
|
|
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->setFunctions(['openssl_pkey_new' => false]);
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertFalse($install->checkKeys());
|
|
|
|
|
|
|
|
$this->setFunctions(['openssl_pkey_new' => true]);
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertTrue($install->checkKeys());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
|
|
|
*/
|
|
|
|
public function testCheckFunctions()
|
|
|
|
{
|
2018-11-01 08:44:47 -04:00
|
|
|
$this->mockFunctionL10TCalls();
|
|
|
|
$this->setFunctions(['curl_init' => false, 'imagecreatefromjpeg' => true]);
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertFalse($install->checkFunctions());
|
|
|
|
$this->assertCheckExist(3,
|
2018-11-01 08:44:47 -04:00
|
|
|
'libCurl PHP module',
|
|
|
|
'Error: libCURL PHP module required but not installed.',
|
2018-10-07 20:15:27 -04:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 08:44:47 -04:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->setFunctions(['imagecreatefromjpeg' => false]);
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertFalse($install->checkFunctions());
|
|
|
|
$this->assertCheckExist(4,
|
2018-11-01 08:44:47 -04:00
|
|
|
'GD graphics PHP module',
|
|
|
|
'Error: GD graphics PHP module with JPEG support required but not installed.',
|
2018-10-07 20:15:27 -04:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 08:44:47 -04:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->setFunctions(['openssl_public_encrypt' => false]);
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertFalse($install->checkFunctions());
|
|
|
|
$this->assertCheckExist(5,
|
2018-11-01 08:44:47 -04:00
|
|
|
'OpenSSL PHP module',
|
|
|
|
'Error: openssl PHP module required but not installed.',
|
2018-10-07 20:15:27 -04:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 08:44:47 -04:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->setFunctions(['mb_strlen' => false]);
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertFalse($install->checkFunctions());
|
|
|
|
$this->assertCheckExist(6,
|
2018-11-01 08:44:47 -04:00
|
|
|
'mb_string PHP module',
|
|
|
|
'Error: mb_string PHP module required but not installed.',
|
2018-10-07 20:15:27 -04:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 08:44:47 -04:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->setFunctions(['iconv_strlen' => false]);
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertFalse($install->checkFunctions());
|
|
|
|
$this->assertCheckExist(7,
|
2018-11-01 08:44:47 -04:00
|
|
|
'iconv PHP module',
|
|
|
|
'Error: iconv PHP module required but not installed.',
|
2018-10-07 20:15:27 -04:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 08:44:47 -04:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->setFunctions(['posix_kill' => false]);
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertFalse($install->checkFunctions());
|
|
|
|
$this->assertCheckExist(8,
|
2018-11-01 08:44:47 -04:00
|
|
|
'POSIX PHP module',
|
|
|
|
'Error: POSIX PHP module required but not installed.',
|
2018-10-07 20:15:27 -04:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-12-22 17:04:47 -05:00
|
|
|
$this->mockFunctionL10TCalls();
|
|
|
|
$this->setFunctions(['json_encode' => false]);
|
|
|
|
$install = new Installer();
|
|
|
|
$this->assertFalse($install->checkFunctions());
|
|
|
|
$this->assertCheckExist(9,
|
|
|
|
'JSON PHP module',
|
|
|
|
'Error: JSON PHP module required but not installed.',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2019-02-16 16:13:19 -05:00
|
|
|
$this->mockFunctionL10TCalls();
|
|
|
|
$this->setFunctions(['finfo_open' => false]);
|
|
|
|
$install = new Installer();
|
|
|
|
$this->assertFalse($install->checkFunctions());
|
|
|
|
$this->assertCheckExist(10,
|
|
|
|
'File Information PHP module',
|
|
|
|
'Error: File Information PHP module required but not installed.',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 08:44:47 -04:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->setFunctions([
|
|
|
|
'curl_init' => true,
|
|
|
|
'imagecreatefromjpeg' => true,
|
|
|
|
'openssl_public_encrypt' => true,
|
|
|
|
'mb_strlen' => true,
|
|
|
|
'iconv_strlen' => true,
|
2018-12-22 17:36:53 -05:00
|
|
|
'posix_kill' => true,
|
2019-02-16 16:13:19 -05:00
|
|
|
'json_encode' => true,
|
|
|
|
'finfo_open' => true,
|
2018-10-07 20:15:27 -04:00
|
|
|
]);
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertTrue($install->checkFunctions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
|
|
|
*/
|
|
|
|
public function testCheckLocalIni()
|
|
|
|
{
|
2019-07-09 15:44:02 -04:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-01-30 14:26:17 -05:00
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->assertTrue($this->root->hasChild('config/local.config.php'));
|
2018-10-07 20:15:27 -04:00
|
|
|
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertTrue($install->checkLocalIni());
|
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->delConfigFile('local.config.php');
|
2018-10-07 20:15:27 -04:00
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->assertFalse($this->root->hasChild('config/local.config.php'));
|
2018-10-07 20:15:27 -04:00
|
|
|
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertTrue($install->checkLocalIni());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2019-07-09 15:44:02 -04:00
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
2018-10-07 20:15:27 -04:00
|
|
|
*/
|
|
|
|
public function testCheckHtAccessFail()
|
|
|
|
{
|
2019-07-09 15:44:02 -04:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-01-30 14:26:17 -05:00
|
|
|
|
2018-10-07 20:15:27 -04:00
|
|
|
// Mocking the CURL Response
|
2020-10-07 15:49:12 -04:00
|
|
|
$IHTTPResult = \Mockery::mock(IHTTPResult::class);
|
|
|
|
$IHTTPResult
|
2018-10-29 09:10:45 -04:00
|
|
|
->shouldReceive('getReturnCode')
|
|
|
|
->andReturn('404');
|
2020-10-07 15:49:12 -04:00
|
|
|
$IHTTPResult
|
2018-10-07 20:15:27 -04:00
|
|
|
->shouldReceive('getRedirectUrl')
|
|
|
|
->andReturn('');
|
2020-10-07 15:49:12 -04:00
|
|
|
$IHTTPResult
|
2018-10-07 20:15:27 -04:00
|
|
|
->shouldReceive('getError')
|
|
|
|
->andReturn('test Error');
|
|
|
|
|
|
|
|
// Mocking the CURL Request
|
2020-03-04 17:36:46 -05:00
|
|
|
$networkMock = \Mockery::mock(IHTTPRequest::class);
|
2018-10-07 20:15:27 -04:00
|
|
|
$networkMock
|
2020-03-04 17:36:46 -05:00
|
|
|
->shouldReceive('fetchFull')
|
2018-10-07 20:15:27 -04:00
|
|
|
->with('https://test/install/testrewrite')
|
2020-10-07 15:49:12 -04:00
|
|
|
->andReturn($IHTTPResult);
|
2018-10-07 20:15:27 -04:00
|
|
|
$networkMock
|
2020-03-04 17:36:46 -05:00
|
|
|
->shouldReceive('fetchFull')
|
2018-10-07 20:15:27 -04:00
|
|
|
->with('http://test/install/testrewrite')
|
2020-10-07 15:49:12 -04:00
|
|
|
->andReturn($IHTTPResult);
|
2018-10-07 20:15:27 -04:00
|
|
|
|
2020-03-04 17:36:46 -05:00
|
|
|
$this->dice->shouldReceive('create')
|
|
|
|
->with(IHTTPRequest::class)
|
|
|
|
->andReturn($networkMock);
|
|
|
|
|
|
|
|
DI::init($this->dice);
|
|
|
|
|
2018-10-07 20:15:27 -04:00
|
|
|
// Mocking that we can use CURL
|
|
|
|
$this->setFunctions(['curl_init' => true]);
|
|
|
|
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
|
2018-10-29 09:10:45 -04:00
|
|
|
$this->assertFalse($install->checkHtAccess('https://test'));
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertSame('test Error', $install->getChecks()[0]['error_msg']['msg']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2019-07-09 15:44:02 -04:00
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
2018-10-07 20:15:27 -04:00
|
|
|
*/
|
|
|
|
public function testCheckHtAccessWork()
|
|
|
|
{
|
2019-07-09 15:44:02 -04:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-01-30 14:26:17 -05:00
|
|
|
|
2018-10-07 20:15:27 -04:00
|
|
|
// Mocking the failed CURL Response
|
2020-10-07 15:49:12 -04:00
|
|
|
$IHTTPResultF = \Mockery::mock(IHTTPResult::class);
|
|
|
|
$IHTTPResultF
|
2018-10-29 09:10:45 -04:00
|
|
|
->shouldReceive('getReturnCode')
|
|
|
|
->andReturn('404');
|
2018-10-07 20:15:27 -04:00
|
|
|
|
|
|
|
// Mocking the working CURL Response
|
2020-10-07 15:49:12 -04:00
|
|
|
$IHTTPResultW = \Mockery::mock(IHTTPResult::class);
|
|
|
|
$IHTTPResultW
|
2018-10-29 09:10:45 -04:00
|
|
|
->shouldReceive('getReturnCode')
|
|
|
|
->andReturn('204');
|
2018-10-07 20:15:27 -04:00
|
|
|
|
|
|
|
// Mocking the CURL Request
|
2020-03-04 17:36:46 -05:00
|
|
|
$networkMock = \Mockery::mock(IHTTPRequest::class);
|
2018-10-07 20:15:27 -04:00
|
|
|
$networkMock
|
2020-03-04 17:36:46 -05:00
|
|
|
->shouldReceive('fetchFull')
|
2018-10-07 20:15:27 -04:00
|
|
|
->with('https://test/install/testrewrite')
|
2020-10-07 15:49:12 -04:00
|
|
|
->andReturn($IHTTPResultF);
|
2018-10-07 20:15:27 -04:00
|
|
|
$networkMock
|
2020-03-04 17:36:46 -05:00
|
|
|
->shouldReceive('fetchFull')
|
2018-10-07 20:15:27 -04:00
|
|
|
->with('http://test/install/testrewrite')
|
2020-10-07 15:49:12 -04:00
|
|
|
->andReturn($IHTTPResultW);
|
2018-10-07 20:15:27 -04:00
|
|
|
|
2020-03-04 17:36:46 -05:00
|
|
|
$this->dice->shouldReceive('create')
|
|
|
|
->with(IHTTPRequest::class)
|
|
|
|
->andReturn($networkMock);
|
|
|
|
|
|
|
|
DI::init($this->dice);
|
|
|
|
|
2018-10-07 20:15:27 -04:00
|
|
|
// Mocking that we can use CURL
|
|
|
|
$this->setFunctions(['curl_init' => true]);
|
|
|
|
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
|
2018-10-29 09:10:45 -04:00
|
|
|
$this->assertTrue($install->checkHtAccess('https://test'));
|
2018-10-07 20:15:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2019-07-09 15:44:02 -04:00
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
2018-10-07 20:15:27 -04:00
|
|
|
*/
|
|
|
|
public function testImagick()
|
|
|
|
{
|
2019-11-02 13:06:49 -04:00
|
|
|
$this->markTestIncomplete('needs adapted class_exists() mock');
|
2019-01-30 14:26:17 -05:00
|
|
|
|
2019-11-02 13:06:49 -04:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2018-10-07 20:15:27 -04:00
|
|
|
|
2018-10-23 06:31:15 -04:00
|
|
|
$this->setClasses(['Imagick' => true]);
|
|
|
|
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
|
|
|
|
// even there is no supported type, Imagick should return true (because it is not required)
|
|
|
|
$this->assertTrue($install->checkImagick());
|
2018-10-23 06:31:15 -04:00
|
|
|
|
2018-10-07 20:15:27 -04:00
|
|
|
$this->assertCheckExist(1,
|
2019-12-19 14:11:07 -05:00
|
|
|
$this->l10nMock->t('ImageMagick supports GIF'),
|
2018-10-07 20:15:27 -04:00
|
|
|
'',
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
$install->getChecks());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2019-07-09 15:44:02 -04:00
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
2018-10-07 20:15:27 -04:00
|
|
|
*/
|
|
|
|
public function testImagickNotFound()
|
|
|
|
{
|
2020-08-19 08:17:18 -04:00
|
|
|
$this->markTestIncomplete('Disabled due not working/difficult mocking global functions - needs more care!');
|
|
|
|
|
2019-07-09 15:44:02 -04:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-01-30 14:26:17 -05:00
|
|
|
|
2018-10-23 06:31:15 -04:00
|
|
|
$this->setClasses(['Imagick' => true]);
|
|
|
|
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-07 20:15:27 -04:00
|
|
|
|
|
|
|
// even there is no supported type, Imagick should return true (because it is not required)
|
|
|
|
$this->assertTrue($install->checkImagick());
|
|
|
|
$this->assertCheckExist(1,
|
2019-12-19 14:11:07 -05:00
|
|
|
$this->l10nMock->t('ImageMagick supports GIF'),
|
2018-10-07 20:15:27 -04:00
|
|
|
'',
|
2019-12-22 07:04:35 -05:00
|
|
|
false,
|
2018-10-07 20:15:27 -04:00
|
|
|
false,
|
|
|
|
$install->getChecks());
|
|
|
|
}
|
2018-10-23 06:31:15 -04:00
|
|
|
|
|
|
|
public function testImagickNotInstalled()
|
|
|
|
{
|
|
|
|
$this->setClasses(['Imagick' => false]);
|
2018-11-01 08:44:47 -04:00
|
|
|
$this->mockL10nT('ImageMagick PHP extension is not installed');
|
2018-10-23 06:31:15 -04:00
|
|
|
|
2018-10-29 13:44:39 -04:00
|
|
|
$install = new Installer();
|
2018-10-23 06:31:15 -04:00
|
|
|
|
|
|
|
// even there is no supported type, Imagick should return true (because it is not required)
|
|
|
|
$this->assertTrue($install->checkImagick());
|
|
|
|
$this->assertCheckExist(0,
|
2018-11-01 08:44:47 -04:00
|
|
|
'ImageMagick PHP extension is not installed',
|
2018-10-23 06:31:15 -04:00
|
|
|
'',
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
$install->getChecks());
|
|
|
|
}
|
2019-03-26 17:04:31 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setup of the config cache for installation
|
|
|
|
*/
|
|
|
|
public function testSetUpCache()
|
|
|
|
{
|
2019-07-09 15:44:02 -04:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-03-26 17:04:31 -04:00
|
|
|
|
|
|
|
$install = new Installer();
|
2020-01-19 16:23:44 -05:00
|
|
|
$configCache = \Mockery::mock(Cache::class);
|
2019-03-26 17:04:31 -04:00
|
|
|
$configCache->shouldReceive('set')->with('config', 'php_path', \Mockery::any())->once();
|
|
|
|
$configCache->shouldReceive('set')->with('system', 'basepath', '/test/')->once();
|
|
|
|
|
|
|
|
$install->setUpCache($configCache, '/test/');
|
|
|
|
}
|
2018-10-07 20:15:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A workaround to replace the PHP native function_exists with a mocked function
|
|
|
|
*
|
|
|
|
* @param string $function_name the Name of the function
|
|
|
|
*
|
|
|
|
* @return bool true or false
|
|
|
|
*/
|
|
|
|
function function_exists($function_name)
|
|
|
|
{
|
|
|
|
global $phpMock;
|
|
|
|
if (isset($phpMock['function_exists'])) {
|
|
|
|
$result = call_user_func_array($phpMock['function_exists'], func_get_args());
|
|
|
|
if ($result !== '__phpunit_continue__') {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return call_user_func_array('\function_exists', func_get_args());
|
|
|
|
}
|
2018-10-23 06:31:15 -04:00
|
|
|
|
|
|
|
function class_exists($class_name)
|
|
|
|
{
|
|
|
|
global $phpMock;
|
|
|
|
if (isset($phpMock['class_exists'])) {
|
|
|
|
$result = call_user_func_array($phpMock['class_exists'], func_get_args());
|
|
|
|
if ($result !== '__phpunit_continue__') {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return call_user_func_array('\class_exists', func_get_args());
|
|
|
|
}
|