2018-10-08 00:15:27 +00:00
|
|
|
<?php
|
2020-02-09 15:34:23 +00:00
|
|
|
/**
|
2024-01-02 20:57:26 +00:00
|
|
|
* @copyright Copyright (C) 2010-2024, the Friendica project
|
2020-02-09 15:34:23 +00:00
|
|
|
*
|
|
|
|
* @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-08 00:15:27 +00:00
|
|
|
|
2020-10-18 18:31:57 +00:00
|
|
|
/// @todo this is in the same namespace as Install for mocking 'function_exists'
|
2018-10-08 00:15:27 +00:00
|
|
|
namespace Friendica\Core;
|
|
|
|
|
2019-07-26 13:54:14 +00:00
|
|
|
use Dice\Dice;
|
2021-12-10 20:34:19 +00:00
|
|
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
2021-10-26 19:44:29 +00:00
|
|
|
use Friendica\Core\Config\ValueObject\Cache;
|
2019-12-15 22:28:01 +00:00
|
|
|
use Friendica\DI;
|
2021-10-23 10:50:31 +00:00
|
|
|
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
|
2021-10-29 06:03:59 +00:00
|
|
|
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
|
2018-11-01 12:44:47 +00:00
|
|
|
use Friendica\Test\MockedTest;
|
2018-10-08 00:15:27 +00:00
|
|
|
use Friendica\Test\Util\VFSTrait;
|
2020-10-18 18:31:57 +00:00
|
|
|
use Mockery;
|
2019-07-09 19:44:02 +00:00
|
|
|
use Mockery\MockInterface;
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2018-11-01 12:44:47 +00:00
|
|
|
class InstallerTest extends MockedTest
|
2018-10-08 00:15:27 +00:00
|
|
|
{
|
|
|
|
use VFSTrait;
|
2021-12-10 20:34:19 +00:00
|
|
|
use ArraySubsetAsserts;
|
2019-07-09 19:44:02 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-18 18:31:57 +00:00
|
|
|
* @var L10n|MockInterface
|
2019-07-09 19:44:02 +00:00
|
|
|
*/
|
|
|
|
private $l10nMock;
|
2020-03-04 22:36:46 +00:00
|
|
|
/**
|
|
|
|
* @var Dice|MockInterface
|
|
|
|
*/
|
|
|
|
private $dice;
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2021-04-01 21:04:30 +00:00
|
|
|
protected function setUp(): void
|
2018-10-08 00:15:27 +00:00
|
|
|
{
|
2018-11-01 12:44:47 +00:00
|
|
|
parent::setUp();
|
2018-10-08 00:15:27 +00:00
|
|
|
|
|
|
|
$this->setUpVfsDir();
|
2019-07-09 19:44:02 +00:00
|
|
|
|
2020-10-18 18:31:57 +00:00
|
|
|
$this->l10nMock = Mockery::mock(L10n::class);
|
2019-07-26 13:54:14 +00:00
|
|
|
|
|
|
|
/** @var Dice|MockInterface $dice */
|
2020-10-18 18:31:57 +00:00
|
|
|
$this->dice = Mockery::mock(Dice::class)->makePartial();
|
2020-03-04 22:36:46 +00:00
|
|
|
$this->dice = $this->dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
|
2019-07-26 13:54:14 +00:00
|
|
|
|
2020-03-04 22:36:46 +00:00
|
|
|
$this->dice->shouldReceive('create')
|
2020-10-18 18:31:57 +00:00
|
|
|
->with(L10n::class)
|
2019-07-26 13:54:14 +00:00
|
|
|
->andReturn($this->l10nMock);
|
|
|
|
|
2023-02-04 23:15:01 +00:00
|
|
|
DI::init($this->dice, true);
|
2019-07-09 19:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 21:04:30 +00:00
|
|
|
public static function tearDownAfterClass(): void
|
|
|
|
{
|
|
|
|
// Reset mocking
|
|
|
|
global $phpMock;
|
|
|
|
$phpMock = [];
|
|
|
|
|
|
|
|
parent::tearDownAfterClass();
|
|
|
|
}
|
|
|
|
|
2019-07-09 19:44:02 +00:00
|
|
|
private function mockL10nT(string $text, $times = null)
|
|
|
|
{
|
2019-07-17 10:40:00 +00:00
|
|
|
$this->l10nMock->shouldReceive('t')->with($text)->andReturn($text)->times($times);
|
2018-10-08 00:15:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 12:44:47 +00:00
|
|
|
/**
|
2020-01-18 19:52:34 +00:00
|
|
|
* Mocking the DI::l10n()->t() calls for the function checks
|
2023-10-12 19:41:07 +00:00
|
|
|
*
|
|
|
|
* @param bool $disableTimes if true, the L10, which are just created in case of an error, will be set to false (because the check will succeed)
|
2018-11-01 12:44:47 +00:00
|
|
|
*/
|
2023-10-12 19:41:07 +00:00
|
|
|
private function mockFunctionL10TCalls(bool $disableTimes = false)
|
2018-11-01 12:44:47 +00:00
|
|
|
{
|
|
|
|
$this->mockL10nT('Apache mod_rewrite module', 1);
|
|
|
|
$this->mockL10nT('PDO or MySQLi PHP module', 1);
|
2023-10-12 19:41:07 +00:00
|
|
|
$this->mockL10nT('IntlChar PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: The IntlChar module is not installed.', $disableTimes ? 0 : 1);
|
2018-11-01 12:44:47 +00:00
|
|
|
$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 22:56:57 +00:00
|
|
|
$this->mockL10nT('JSON PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: JSON PHP module required but not installed.', 1);
|
2019-02-16 21:13:19 +00:00
|
|
|
$this->mockL10nT('File Information PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: File Information PHP module required but not installed.', 1);
|
2022-07-17 09:08:12 +00:00
|
|
|
$this->mockL10nT('GNU Multiple Precision PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: GNU Multiple Precision PHP module required but not installed.', 1);
|
2024-04-06 09:20:23 +00:00
|
|
|
$this->mockL10nT('IDN Functions PHP module', 1);
|
|
|
|
$this->mockL10nT('Error: IDN Functions PHP module required but not installed.', 1);
|
2021-01-07 14:20:03 +00:00
|
|
|
$this->mockL10nT('Program execution functions', 1);
|
2021-05-23 07:43:02 +00:00
|
|
|
$this->mockL10nT('Error: Program execution functions (proc_open) required but not enabled.', 1);
|
2018-11-01 12:44:47 +00:00
|
|
|
}
|
|
|
|
|
2018-10-08 00:15:27 +00:00
|
|
|
private function assertCheckExist($position, $title, $help, $status, $required, $assertionArray)
|
|
|
|
{
|
2019-12-21 23:36:29 +00:00
|
|
|
$subSet = [$position => [
|
2018-10-08 00:15:27 +00:00
|
|
|
'title' => $title,
|
|
|
|
'status' => $status,
|
|
|
|
'required' => $required,
|
|
|
|
'error_msg' => null,
|
|
|
|
'help' => $help]
|
2019-12-21 23:36:29 +00:00
|
|
|
];
|
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertArraySubset($subSet, $assertionArray, false, "expected subset: " . PHP_EOL . print_r($subSet, true) . PHP_EOL . "current subset: " . print_r($assertionArray, true));
|
2018-10-08 00:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces function_exists results with given mocks
|
|
|
|
*
|
|
|
|
* @param array $functions a list from function names and their result
|
|
|
|
*/
|
2020-10-18 18:31:57 +00:00
|
|
|
private function setFunctions(array $functions)
|
2018-10-08 00:15:27 +00:00
|
|
|
{
|
|
|
|
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 10:31:15 +00:00
|
|
|
/**
|
|
|
|
* Replaces class_exist results with given mocks
|
|
|
|
*
|
|
|
|
* @param array $classes a list from class names and their results
|
|
|
|
*/
|
2020-10-18 18:31:57 +00:00
|
|
|
private function setClasses(array $classes)
|
2018-10-23 10:31:15 +00:00
|
|
|
{
|
|
|
|
global $phpMock;
|
|
|
|
$phpMock['class_exists'] = function($class) use ($classes) {
|
|
|
|
foreach ($classes as $name => $value) {
|
|
|
|
if ($class == $name) {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '__phpunit_continue__';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-08 00:15:27 +00:00
|
|
|
/**
|
|
|
|
* @small
|
|
|
|
*/
|
|
|
|
public function testCheckKeys()
|
|
|
|
{
|
2019-07-09 19:44:02 +00:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-01-30 19:26:17 +00:00
|
|
|
|
2018-10-08 00:15:27 +00:00
|
|
|
$this->setFunctions(['openssl_pkey_new' => false]);
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($install->checkKeys());
|
2018-10-08 00:15:27 +00:00
|
|
|
|
|
|
|
$this->setFunctions(['openssl_pkey_new' => true]);
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertTrue($install->checkKeys());
|
2018-10-08 00:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
|
|
|
*/
|
|
|
|
public function testCheckFunctions()
|
|
|
|
{
|
2023-10-12 19:41:07 +00:00
|
|
|
$this->mockFunctionL10TCalls();
|
|
|
|
$this->setClasses(['IntlChar' => false]);
|
|
|
|
$install = new Installer();
|
|
|
|
self::assertFalse($install->checkFunctions());
|
|
|
|
self::assertCheckExist(2,
|
|
|
|
'IntlChar PHP module',
|
|
|
|
'Error: The IntlChar module is not installed.',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 12:44:47 +00:00
|
|
|
$this->mockFunctionL10TCalls();
|
|
|
|
$this->setFunctions(['curl_init' => false, 'imagecreatefromjpeg' => true]);
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($install->checkFunctions());
|
2023-10-12 19:41:07 +00:00
|
|
|
self::assertCheckExist(4,
|
2018-11-01 12:44:47 +00:00
|
|
|
'libCurl PHP module',
|
|
|
|
'Error: libCURL PHP module required but not installed.',
|
2018-10-08 00:15:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 12:44:47 +00:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-08 00:15:27 +00:00
|
|
|
$this->setFunctions(['imagecreatefromjpeg' => false]);
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($install->checkFunctions());
|
2023-10-12 19:41:07 +00:00
|
|
|
self::assertCheckExist(5,
|
2018-11-01 12:44:47 +00:00
|
|
|
'GD graphics PHP module',
|
|
|
|
'Error: GD graphics PHP module with JPEG support required but not installed.',
|
2018-10-08 00:15:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 12:44:47 +00:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-08 00:15:27 +00:00
|
|
|
$this->setFunctions(['openssl_public_encrypt' => false]);
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($install->checkFunctions());
|
2023-10-12 19:41:07 +00:00
|
|
|
self::assertCheckExist(6,
|
2018-11-01 12:44:47 +00:00
|
|
|
'OpenSSL PHP module',
|
|
|
|
'Error: openssl PHP module required but not installed.',
|
2018-10-08 00:15:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 12:44:47 +00:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-08 00:15:27 +00:00
|
|
|
$this->setFunctions(['mb_strlen' => false]);
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($install->checkFunctions());
|
2023-10-12 19:41:07 +00:00
|
|
|
self::assertCheckExist(7,
|
2018-11-01 12:44:47 +00:00
|
|
|
'mb_string PHP module',
|
|
|
|
'Error: mb_string PHP module required but not installed.',
|
2018-10-08 00:15:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 12:44:47 +00:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-08 00:15:27 +00:00
|
|
|
$this->setFunctions(['iconv_strlen' => false]);
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($install->checkFunctions());
|
2023-10-12 19:41:07 +00:00
|
|
|
self::assertCheckExist(8,
|
2018-11-01 12:44:47 +00:00
|
|
|
'iconv PHP module',
|
|
|
|
'Error: iconv PHP module required but not installed.',
|
2018-10-08 00:15:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-11-01 12:44:47 +00:00
|
|
|
$this->mockFunctionL10TCalls();
|
2018-10-08 00:15:27 +00:00
|
|
|
$this->setFunctions(['posix_kill' => false]);
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($install->checkFunctions());
|
2023-10-12 19:41:07 +00:00
|
|
|
self::assertCheckExist(9,
|
2018-11-01 12:44:47 +00:00
|
|
|
'POSIX PHP module',
|
|
|
|
'Error: POSIX PHP module required but not installed.',
|
2018-10-08 00:15:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2018-12-22 22:04:47 +00:00
|
|
|
$this->mockFunctionL10TCalls();
|
2021-01-07 14:20:03 +00:00
|
|
|
$this->setFunctions(['proc_open' => false]);
|
2018-12-22 22:04:47 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($install->checkFunctions());
|
2023-10-12 19:41:07 +00:00
|
|
|
self::assertCheckExist(10,
|
2021-01-07 14:20:03 +00:00
|
|
|
'Program execution functions',
|
2021-05-23 07:47:25 +00:00
|
|
|
'Error: Program execution functions (proc_open) required but not enabled.',
|
2021-01-07 14:20:03 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
$this->mockFunctionL10TCalls();
|
|
|
|
$this->setFunctions(['json_encode' => false]);
|
|
|
|
$install = new Installer();
|
|
|
|
self::assertFalse($install->checkFunctions());
|
2023-10-12 19:41:07 +00:00
|
|
|
self::assertCheckExist(11,
|
2018-12-22 22:04:47 +00:00
|
|
|
'JSON PHP module',
|
|
|
|
'Error: JSON PHP module required but not installed.',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2019-02-16 21:13:19 +00:00
|
|
|
$this->mockFunctionL10TCalls();
|
|
|
|
$this->setFunctions(['finfo_open' => false]);
|
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($install->checkFunctions());
|
2023-10-12 19:41:07 +00:00
|
|
|
self::assertCheckExist(12,
|
2019-02-16 21:13:19 +00:00
|
|
|
'File Information PHP module',
|
|
|
|
'Error: File Information PHP module required but not installed.',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2022-07-17 09:02:28 +00:00
|
|
|
$this->mockFunctionL10TCalls();
|
|
|
|
$this->setFunctions(['gmp_strval' => false]);
|
|
|
|
$install = new Installer();
|
|
|
|
self::assertFalse($install->checkFunctions());
|
2023-10-12 19:41:07 +00:00
|
|
|
self::assertCheckExist(13,
|
2022-07-17 09:02:28 +00:00
|
|
|
'GNU Multiple Precision PHP module',
|
|
|
|
'Error: GNU Multiple Precision PHP module required but not installed.',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
$install->getChecks());
|
|
|
|
|
2023-10-12 19:41:07 +00:00
|
|
|
$this->mockFunctionL10TCalls(true);
|
2018-10-08 00:15:27 +00:00
|
|
|
$this->setFunctions([
|
|
|
|
'curl_init' => true,
|
|
|
|
'imagecreatefromjpeg' => true,
|
|
|
|
'openssl_public_encrypt' => true,
|
|
|
|
'mb_strlen' => true,
|
|
|
|
'iconv_strlen' => true,
|
2018-12-22 22:36:53 +00:00
|
|
|
'posix_kill' => true,
|
2019-02-16 21:13:19 +00:00
|
|
|
'json_encode' => true,
|
|
|
|
'finfo_open' => true,
|
2022-07-17 09:17:07 +00:00
|
|
|
'gmp_strval' => true,
|
2018-10-08 00:15:27 +00:00
|
|
|
]);
|
2023-10-12 19:41:07 +00:00
|
|
|
$this->setClasses(['IntlChar' => true]);
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertTrue($install->checkFunctions());
|
2018-10-08 00:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
|
|
|
*/
|
|
|
|
public function testCheckLocalIni()
|
|
|
|
{
|
2019-07-09 19:44:02 +00:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-01-30 19:26:17 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertTrue($this->root->hasChild('config/local.config.php'));
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertTrue($install->checkLocalIni());
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2018-11-25 06:44:09 +00:00
|
|
|
$this->delConfigFile('local.config.php');
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($this->root->hasChild('config/local.config.php'));
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertTrue($install->checkLocalIni());
|
2018-10-08 00:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2019-07-09 19:44:02 +00:00
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
2018-10-08 00:15:27 +00:00
|
|
|
*/
|
|
|
|
public function testCheckHtAccessFail()
|
|
|
|
{
|
2019-07-09 19:44:02 +00:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-01-30 19:26:17 +00:00
|
|
|
|
2018-10-08 00:15:27 +00:00
|
|
|
// Mocking the CURL Response
|
2021-10-23 10:50:31 +00:00
|
|
|
$IHTTPResult = Mockery::mock(ICanHandleHttpResponses::class);
|
2021-08-20 17:48:14 +00:00
|
|
|
$IHTTPResult
|
2018-10-29 13:10:45 +00:00
|
|
|
->shouldReceive('getReturnCode')
|
|
|
|
->andReturn('404');
|
2021-08-20 17:48:14 +00:00
|
|
|
$IHTTPResult
|
2018-10-08 00:15:27 +00:00
|
|
|
->shouldReceive('getRedirectUrl')
|
|
|
|
->andReturn('');
|
2021-08-20 17:48:14 +00:00
|
|
|
$IHTTPResult
|
2018-10-08 00:15:27 +00:00
|
|
|
->shouldReceive('getError')
|
|
|
|
->andReturn('test Error');
|
|
|
|
|
|
|
|
// Mocking the CURL Request
|
2021-10-29 06:03:59 +00:00
|
|
|
$networkMock = Mockery::mock(ICanSendHttpRequests::class);
|
2018-10-08 00:15:27 +00:00
|
|
|
$networkMock
|
2020-03-04 22:36:46 +00:00
|
|
|
->shouldReceive('fetchFull')
|
2018-10-08 00:15:27 +00:00
|
|
|
->with('https://test/install/testrewrite')
|
2021-08-20 17:48:14 +00:00
|
|
|
->andReturn($IHTTPResult);
|
2018-10-08 00:15:27 +00:00
|
|
|
$networkMock
|
2020-03-04 22:36:46 +00:00
|
|
|
->shouldReceive('fetchFull')
|
2018-10-08 00:15:27 +00:00
|
|
|
->with('http://test/install/testrewrite')
|
2021-08-20 17:48:14 +00:00
|
|
|
->andReturn($IHTTPResult);
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2020-03-04 22:36:46 +00:00
|
|
|
$this->dice->shouldReceive('create')
|
2021-10-29 06:03:59 +00:00
|
|
|
->with(ICanSendHttpRequests::class)
|
2020-03-04 22:36:46 +00:00
|
|
|
->andReturn($networkMock);
|
|
|
|
|
2023-02-04 23:15:01 +00:00
|
|
|
DI::init($this->dice, true);
|
2020-03-04 22:36:46 +00:00
|
|
|
|
2018-10-08 00:15:27 +00:00
|
|
|
// Mocking that we can use CURL
|
|
|
|
$this->setFunctions(['curl_init' => true]);
|
|
|
|
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertFalse($install->checkHtAccess('https://test'));
|
|
|
|
self::assertSame('test Error', $install->getChecks()[0]['error_msg']['msg']);
|
2018-10-08 00:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2019-07-09 19:44:02 +00:00
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
2018-10-08 00:15:27 +00:00
|
|
|
*/
|
|
|
|
public function testCheckHtAccessWork()
|
|
|
|
{
|
2019-07-09 19:44:02 +00:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-01-30 19:26:17 +00:00
|
|
|
|
2018-10-08 00:15:27 +00:00
|
|
|
// Mocking the failed CURL Response
|
2021-10-23 10:50:31 +00:00
|
|
|
$IHTTPResultF = Mockery::mock(ICanHandleHttpResponses::class);
|
2021-08-20 17:48:14 +00:00
|
|
|
$IHTTPResultF
|
2018-10-29 13:10:45 +00:00
|
|
|
->shouldReceive('getReturnCode')
|
|
|
|
->andReturn('404');
|
2018-10-08 00:15:27 +00:00
|
|
|
|
|
|
|
// Mocking the working CURL Response
|
2021-10-23 10:50:31 +00:00
|
|
|
$IHTTPResultW = Mockery::mock(ICanHandleHttpResponses::class);
|
2021-08-20 17:48:14 +00:00
|
|
|
$IHTTPResultW
|
2018-10-29 13:10:45 +00:00
|
|
|
->shouldReceive('getReturnCode')
|
|
|
|
->andReturn('204');
|
2018-10-08 00:15:27 +00:00
|
|
|
|
|
|
|
// Mocking the CURL Request
|
2021-10-29 06:03:59 +00:00
|
|
|
$networkMock = Mockery::mock(ICanSendHttpRequests::class);
|
2018-10-08 00:15:27 +00:00
|
|
|
$networkMock
|
2020-03-04 22:36:46 +00:00
|
|
|
->shouldReceive('fetchFull')
|
2018-10-08 00:15:27 +00:00
|
|
|
->with('https://test/install/testrewrite')
|
2021-08-20 17:48:14 +00:00
|
|
|
->andReturn($IHTTPResultF);
|
2018-10-08 00:15:27 +00:00
|
|
|
$networkMock
|
2020-03-04 22:36:46 +00:00
|
|
|
->shouldReceive('fetchFull')
|
2018-10-08 00:15:27 +00:00
|
|
|
->with('http://test/install/testrewrite')
|
2021-08-20 17:48:14 +00:00
|
|
|
->andReturn($IHTTPResultW);
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2020-03-04 22:36:46 +00:00
|
|
|
$this->dice->shouldReceive('create')
|
2021-10-29 06:03:59 +00:00
|
|
|
->with(ICanSendHttpRequests::class)
|
2020-03-04 22:36:46 +00:00
|
|
|
->andReturn($networkMock);
|
|
|
|
|
2023-02-04 23:15:01 +00:00
|
|
|
DI::init($this->dice, true);
|
2020-03-04 22:36:46 +00:00
|
|
|
|
2018-10-08 00:15:27 +00:00
|
|
|
// Mocking that we can use CURL
|
|
|
|
$this->setFunctions(['curl_init' => true]);
|
|
|
|
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertTrue($install->checkHtAccess('https://test'));
|
2018-10-08 00:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2019-07-09 19:44:02 +00:00
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
2018-10-08 00:15:27 +00:00
|
|
|
*/
|
|
|
|
public function testImagick()
|
|
|
|
{
|
2020-10-18 18:31:57 +00:00
|
|
|
static::markTestIncomplete('needs adapted class_exists() mock');
|
2019-01-30 19:26:17 +00:00
|
|
|
|
2019-11-02 17:06:49 +00:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2018-10-08 00:15:27 +00:00
|
|
|
|
2018-10-23 10:31:15 +00:00
|
|
|
$this->setClasses(['Imagick' => true]);
|
|
|
|
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2018-10-08 00:15:27 +00:00
|
|
|
|
|
|
|
// even there is no supported type, Imagick should return true (because it is not required)
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertTrue($install->checkImagick());
|
2018-10-23 10:31:15 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertCheckExist(1,
|
2019-12-19 19:11:07 +00:00
|
|
|
$this->l10nMock->t('ImageMagick supports GIF'),
|
2018-10-08 00:15:27 +00:00
|
|
|
'',
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
$install->getChecks());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2019-07-09 19:44:02 +00:00
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
2018-10-08 00:15:27 +00:00
|
|
|
*/
|
|
|
|
public function testImagickNotFound()
|
|
|
|
{
|
2020-10-18 18:31:57 +00:00
|
|
|
static::markTestIncomplete('Disabled due not working/difficult mocking global functions - needs more care!');
|
2020-08-19 12:17:18 +00:00
|
|
|
|
2019-07-09 19:44:02 +00:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-01-30 19:26:17 +00:00
|
|
|
|
2018-10-23 10:31:15 +00:00
|
|
|
$this->setClasses(['Imagick' => true]);
|
|
|
|
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2018-10-08 00:15:27 +00:00
|
|
|
|
|
|
|
// even there is no supported type, Imagick should return true (because it is not required)
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertTrue($install->checkImagick());
|
|
|
|
self::assertCheckExist(1,
|
2019-12-19 19:11:07 +00:00
|
|
|
$this->l10nMock->t('ImageMagick supports GIF'),
|
2018-10-08 00:15:27 +00:00
|
|
|
'',
|
2019-12-22 12:04:35 +00:00
|
|
|
false,
|
2018-10-08 00:15:27 +00:00
|
|
|
false,
|
|
|
|
$install->getChecks());
|
|
|
|
}
|
2018-10-23 10:31:15 +00:00
|
|
|
|
|
|
|
public function testImagickNotInstalled()
|
|
|
|
{
|
|
|
|
$this->setClasses(['Imagick' => false]);
|
2018-11-01 12:44:47 +00:00
|
|
|
$this->mockL10nT('ImageMagick PHP extension is not installed');
|
2018-10-23 10:31:15 +00:00
|
|
|
|
2018-10-29 17:44:39 +00:00
|
|
|
$install = new Installer();
|
2018-10-23 10:31:15 +00:00
|
|
|
|
|
|
|
// even there is no supported type, Imagick should return true (because it is not required)
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertTrue($install->checkImagick());
|
|
|
|
self::assertCheckExist(0,
|
2018-11-01 12:44:47 +00:00
|
|
|
'ImageMagick PHP extension is not installed',
|
2018-10-23 10:31:15 +00:00
|
|
|
'',
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
$install->getChecks());
|
|
|
|
}
|
2019-03-26 21:04:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setup of the config cache for installation
|
2021-04-01 19:19:45 +00:00
|
|
|
* @doesNotPerformAssertions
|
2019-03-26 21:04:31 +00:00
|
|
|
*/
|
|
|
|
public function testSetUpCache()
|
|
|
|
{
|
2021-04-01 21:04:30 +00:00
|
|
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
2019-03-26 21:04:31 +00:00
|
|
|
|
|
|
|
$install = new Installer();
|
2020-10-18 18:31:57 +00:00
|
|
|
$configCache = Mockery::mock(Cache::class);
|
|
|
|
$configCache->shouldReceive('set')->with('config', 'php_path', Mockery::any())->once();
|
2019-03-26 21:04:31 +00:00
|
|
|
$configCache->shouldReceive('set')->with('system', 'basepath', '/test/')->once();
|
|
|
|
|
|
|
|
$install->setUpCache($configCache, '/test/');
|
|
|
|
}
|
2018-10-08 00:15:27 +00: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
|
|
|
|
*/
|
2020-10-18 18:31:57 +00:00
|
|
|
function function_exists(string $function_name)
|
2018-10-08 00:15:27 +00:00
|
|
|
{
|
|
|
|
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 10:31:15 +00: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());
|
|
|
|
}
|