]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Core/InstallerTest.php
Merge pull request #7019 from nupplaphil/features/6929-improve_redis
[friendica.git] / tests / src / Core / InstallerTest.php
index a4ee20b8ce22df4d5a6e52bbba1e7435fa0c40af..a238bf8e7d9389383ef0bc3738163c2a694d0978 100644 (file)
@@ -3,24 +3,56 @@
 // this is in the same namespace as Install for mocking 'function_exists'
 namespace Friendica\Core;
 
+use Friendica\Core\Config\Cache\IConfigCache;
+use Friendica\Network\CurlResult;
+use Friendica\Object\Image;
+use Friendica\Test\MockedTest;
+use Friendica\Test\Util\L10nMockTrait;
 use Friendica\Test\Util\VFSTrait;
-use PHPUnit\Framework\TestCase;
+use Friendica\Util\Network;
 
 /**
  * @runTestsInSeparateProcesses
  * @preserveGlobalState disabled
  */
-class InstallerTest extends TestCase
+class InstallerTest extends MockedTest
 {
        use VFSTrait;
+       use L10nMockTrait;
 
        public function setUp()
        {
-               parent::setUp(); // TODO: Change the autogenerated stub
+               parent::setUp();
 
                $this->setUpVfsDir();
        }
 
+       /**
+        * Mocking the L10n::t() calls for the function checks
+        */
+       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);
+               $this->mockL10nT('JSON PHP module', 1);
+               $this->mockL10nT('Error: JSON PHP module required but not installed.', 1);
+               $this->mockL10nT('File Information PHP module', 1);
+               $this->mockL10nT('Error: File Information PHP module required but not installed.', 1);
+       }
+
        private function assertCheckExist($position, $title, $help, $status, $required, $assertionArray)
        {
                $this->assertArraySubset([$position => [
@@ -73,6 +105,8 @@ class InstallerTest extends TestCase
         */
        public function testCheckKeys()
        {
+               $this->mockL10nT();
+
                $this->setFunctions(['openssl_pkey_new' => false]);
                $install = new Installer();
                $this->assertFalse($install->checkKeys());
@@ -87,73 +121,104 @@ class InstallerTest extends TestCase
         */
        public function testCheckFunctions()
        {
-               $this->setFunctions(['curl_init' => false]);
+               $this->mockFunctionL10TCalls();
+               $this->setFunctions(['curl_init' => false, 'imagecreatefromjpeg' => true]);
                $install = new Installer();
                $this->assertFalse($install->checkFunctions());
                $this->assertCheckExist(3,
-                       L10n::t('libCurl PHP module'),
-                       L10n::t('Error: libCURL PHP module required but not installed.'),
+                       'libCurl PHP module',
+                       'Error: libCURL PHP module required but not installed.',
                        false,
                        true,
                        $install->getChecks());
 
+               $this->mockFunctionL10TCalls();
                $this->setFunctions(['imagecreatefromjpeg' => false]);
                $install = new Installer();
                $this->assertFalse($install->checkFunctions());
                $this->assertCheckExist(4,
-                       L10n::t('GD graphics PHP module'),
-                       L10n::t('Error: GD graphics PHP module with JPEG support required but not installed.'),
+                       'GD graphics PHP module',
+                       'Error: GD graphics PHP module with JPEG support required but not installed.',
                        false,
                        true,
                        $install->getChecks());
 
+               $this->mockFunctionL10TCalls();
                $this->setFunctions(['openssl_public_encrypt' => false]);
                $install = new Installer();
                $this->assertFalse($install->checkFunctions());
                $this->assertCheckExist(5,
-                       L10n::t('OpenSSL PHP module'),
-                       L10n::t('Error: openssl PHP module required but not installed.'),
+                       'OpenSSL PHP module',
+                       'Error: openssl PHP module required but not installed.',
                        false,
                        true,
                        $install->getChecks());
 
+               $this->mockFunctionL10TCalls();
                $this->setFunctions(['mb_strlen' => false]);
                $install = new Installer();
                $this->assertFalse($install->checkFunctions());
                $this->assertCheckExist(6,
-                       L10n::t('mb_string PHP module'),
-                       L10n::t('Error: mb_string PHP module required but not installed.'),
+                       'mb_string PHP module',
+                       'Error: mb_string PHP module required but not installed.',
                        false,
                        true,
                        $install->getChecks());
 
+               $this->mockFunctionL10TCalls();
                $this->setFunctions(['iconv_strlen' => false]);
                $install = new Installer();
                $this->assertFalse($install->checkFunctions());
                $this->assertCheckExist(7,
-                       L10n::t('iconv PHP module'),
-                       L10n::t('Error: iconv PHP module required but not installed.'),
+                       'iconv PHP module',
+                       'Error: iconv PHP module required but not installed.',
                        false,
                        true,
                        $install->getChecks());
 
+               $this->mockFunctionL10TCalls();
                $this->setFunctions(['posix_kill' => false]);
                $install = new Installer();
                $this->assertFalse($install->checkFunctions());
                $this->assertCheckExist(8,
-                       L10n::t('POSIX PHP module'),
-                       L10n::t('Error: POSIX PHP module required but not installed.'),
+                       'POSIX PHP module',
+                       'Error: POSIX PHP module required but not installed.',
+                       false,
+                       true,
+                       $install->getChecks());
+
+               $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());
+
+               $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());
 
+               $this->mockFunctionL10TCalls();
                $this->setFunctions([
                        'curl_init' => true,
                        'imagecreatefromjpeg' => true,
                        'openssl_public_encrypt' => true,
                        'mb_strlen' => true,
                        'iconv_strlen' => true,
-                       'posix_kill' => true
+                       'posix_kill' => true,
+                       'json_encode' => true,
+                       'finfo_open' => true,
                ]);
                $install = new Installer();
                $this->assertTrue($install->checkFunctions());
@@ -164,14 +229,16 @@ class InstallerTest extends TestCase
         */
        public function testCheckLocalIni()
        {
-               $this->assertTrue($this->root->hasChild('config/local.ini.php'));
+               $this->mockL10nT();
+
+               $this->assertTrue($this->root->hasChild('config/local.config.php'));
 
                $install = new Installer();
                $this->assertTrue($install->checkLocalIni());
 
-               $this->delConfigFile('local.ini.php');
+               $this->delConfigFile('local.config.php');
 
-               $this->assertFalse($this->root->hasChild('config/local.ini.php'));
+               $this->assertFalse($this->root->hasChild('config/local.config.php'));
 
                $install = new Installer();
                $this->assertTrue($install->checkLocalIni());
@@ -182,8 +249,10 @@ class InstallerTest extends TestCase
         */
        public function testCheckHtAccessFail()
        {
+               $this->mockL10nT();
+
                // Mocking the CURL Response
-               $curlResult = \Mockery::mock('Friendica\Network\CurlResult');
+               $curlResult = \Mockery::mock(CurlResult::class);
                $curlResult
                        ->shouldReceive('getReturnCode')
                        ->andReturn('404');
@@ -195,7 +264,7 @@ class InstallerTest extends TestCase
                        ->andReturn('test Error');
 
                // Mocking the CURL Request
-               $networkMock = \Mockery::mock('alias:Friendica\Util\Network');
+               $networkMock = \Mockery::mock('alias:' . Network::class);
                $networkMock
                        ->shouldReceive('fetchUrlFull')
                        ->with('https://test/install/testrewrite')
@@ -208,9 +277,6 @@ class InstallerTest extends TestCase
                // Mocking that we can use CURL
                $this->setFunctions(['curl_init' => true]);
 
-               // needed because of "normalise_link"
-               require_once __DIR__ . '/../../../include/text.php';
-
                $install = new Installer();
 
                $this->assertFalse($install->checkHtAccess('https://test'));
@@ -222,20 +288,22 @@ class InstallerTest extends TestCase
         */
        public function testCheckHtAccessWork()
        {
+               $this->mockL10nT();
+
                // Mocking the failed CURL Response
-               $curlResultF = \Mockery::mock('Friendica\Network\CurlResult');
+               $curlResultF = \Mockery::mock(CurlResult::class);
                $curlResultF
                        ->shouldReceive('getReturnCode')
                        ->andReturn('404');
 
                // Mocking the working CURL Response
-               $curlResultW = \Mockery::mock('Friendica\Network\CurlResult');
+               $curlResultW = \Mockery::mock(CurlResult::class);
                $curlResultW
                        ->shouldReceive('getReturnCode')
                        ->andReturn('204');
 
                // Mocking the CURL Request
-               $networkMock = \Mockery::mock('alias:Friendica\Util\Network');
+               $networkMock = \Mockery::mock('alias:' . Network::class);
                $networkMock
                        ->shouldReceive('fetchUrlFull')
                        ->with('https://test/install/testrewrite')
@@ -261,7 +329,9 @@ class InstallerTest extends TestCase
         */
        public function testImagick()
        {
-               $imageMock = \Mockery::mock('alias:Friendica\Object\Image');
+               $this->mockL10nT();
+
+               $imageMock = \Mockery::mock('alias:'. Image::class);
                $imageMock
                        ->shouldReceive('supportedTypes')
                        ->andReturn(['image/gif' => 'gif']);
@@ -286,7 +356,9 @@ class InstallerTest extends TestCase
         */
        public function testImagickNotFound()
        {
-               $imageMock = \Mockery::mock('alias:Friendica\Object\Image');
+               $this->mockL10nT();
+
+               $imageMock = \Mockery::mock('alias:' . Image::class);
                $imageMock
                        ->shouldReceive('supportedTypes')
                        ->andReturn([]);
@@ -308,18 +380,34 @@ class InstallerTest extends TestCase
        public function testImagickNotInstalled()
        {
                $this->setClasses(['Imagick' => false]);
+               $this->mockL10nT('ImageMagick PHP extension is not installed');
 
                $install = new Installer();
 
                // even there is no supported type, Imagick should return true (because it is not required)
                $this->assertTrue($install->checkImagick());
                $this->assertCheckExist(0,
-                       L10n::t('ImageMagick PHP extension is not installed'),
+                       'ImageMagick PHP extension is not installed',
                        '',
                        false,
                        false,
                        $install->getChecks());
        }
+
+       /**
+        * Test the setup of the config cache for installation
+        */
+       public function testSetUpCache()
+       {
+               $this->mockL10nT();
+
+               $install = new Installer();
+               $configCache = \Mockery::mock(IConfigCache::class);
+               $configCache->shouldReceive('set')->with('config', 'php_path', \Mockery::any())->once();
+               $configCache->shouldReceive('set')->with('system', 'basepath', '/test/')->once();
+
+               $install->setUpCache($configCache, '/test/');
+       }
 }
 
 /**