Test enhancements

This commit is contained in:
Philipp Holzer 2018-11-01 13:44:47 +01:00
parent 70f9d3c596
commit 83ead5ec48
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
12 changed files with 154 additions and 71 deletions

View file

@ -3,16 +3,20 @@
namespace Friendica\Test\src\App;
use Friendica\App\Mode;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\ConfigMockTrait;
use Friendica\Test\Util\DBAMockTrait;
use Friendica\Test\Util\VFSTrait;
use PHPUnit\Framework\TestCase;
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class ModeTest extends TestCase
class ModeTest extends MockedTest
{
use VFSTrait;
use DBAMockTrait;
use ConfigMockTrait;
public function setUp()
{
@ -48,10 +52,7 @@ class ModeTest extends TestCase
public function testWithoutDatabase()
{
$dba = \Mockery::mock('alias:Friendica\Database\DBA');
$dba
->shouldReceive('connected')
->andReturn(false);
$this->mockConnected(false, 1);
$mode = new Mode($this->root->url());
$mode->determine();
@ -65,14 +66,8 @@ class ModeTest extends TestCase
public function testWithoutDatabaseSetup()
{
$dba = \Mockery::mock('alias:Friendica\Database\DBA');
$dba
->shouldReceive('connected')
->andReturn(true);
$dba
->shouldReceive('fetchFirst')
->with('SHOW TABLES LIKE \'config\'')
->andReturn(false);
$this->mockConnected(true, 1);
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', false, 1);
$mode = new Mode($this->root->url());
$mode->determine();
@ -85,20 +80,9 @@ class ModeTest extends TestCase
public function testWithMaintenanceMode()
{
$dba = \Mockery::mock('alias:Friendica\Database\DBA');
$dba
->shouldReceive('connected')
->andReturn(true);
$dba
->shouldReceive('fetchFirst')
->with('SHOW TABLES LIKE \'config\'')
->andReturn(true);
$conf = \Mockery::mock('alias:Friendica\Core\Config');
$conf
->shouldReceive('get')
->with('system', 'maintenance')
->andReturn(true);
$this->mockConnected(true, 1);
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
$this->mockConfigGet('system', 'maintenance', true, 1);
$mode = new Mode($this->root->url());
$mode->determine();
@ -112,20 +96,9 @@ class ModeTest extends TestCase
public function testNormalMode()
{
$dba = \Mockery::mock('alias:Friendica\Database\DBA');
$dba
->shouldReceive('connected')
->andReturn(true);
$dba
->shouldReceive('fetchFirst')
->with('SHOW TABLES LIKE \'config\'')
->andReturn(true);
$conf = \Mockery::mock('alias:Friendica\Core\Config');
$conf
->shouldReceive('get')
->with('system', 'maintenance')
->andReturn(false);
$this->mockConnected(true, 1);
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
$this->mockConfigGet('system', 'maintenance', false, 1);
$mode = new Mode($this->root->url());
$mode->determine();

View file

@ -0,0 +1,45 @@
<?php
/**
* BaseObjectTest class.
*/
namespace Friendica\Test;
use Friendica\App;
use Friendica\BaseObject;
use PHPUnit\Framework\TestCase;
/**
* Tests for the BaseObject class.
*/
class BaseObjectTest extends TestCase
{
/**
* Create variables used in tests.
*/
protected function setUp()
{
$this->baseObject = new BaseObject();
}
/**
* Test the getApp() function.
* @return void
*/
public function testGetApp()
{
$this->assertInstanceOf(App::class, $this->baseObject->getApp());
}
/**
* Test the setApp() function.
* @return void
*/
public function testSetApp()
{
$app = new App(__DIR__ . '/../../');
$this->assertNull($this->baseObject->setApp($app));
$this->assertEquals($app, $this->baseObject->getApp());
}
}

View file

@ -5,6 +5,7 @@ namespace Friendica\Test\src\Core\Console;
use Friendica\Core\Console\AutomaticInstallation;
use Friendica\Test\Util\DBAMockTrait;
use Friendica\Test\Util\DBStructureMockTrait;
use Friendica\Test\Util\L10nMockTrait;
use Friendica\Test\Util\RendererMockTrait;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamFile;
@ -16,6 +17,7 @@ use org\bovigo\vfs\vfsStreamFile;
*/
class AutomaticInstallationConsoleTest extends ConsoleTest
{
use L10nMockTrait;
use DBAMockTrait;
use DBStructureMockTrait;
use RendererMockTrait;
@ -51,6 +53,8 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
$this->db_pass = getenv('MYSQL_PASSWORD');
$this->mockConfigGet('config', 'php_path', false);
$this->mockL10nT();
}
/**

View file

@ -3,24 +3,48 @@
// this is in the same namespace as Install for mocking 'function_exists'
namespace Friendica\Core;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\L10nMockTrait;
use Friendica\Test\Util\VFSTrait;
use PHPUnit\Framework\TestCase;
/**
* @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);
}
private function assertCheckExist($position, $title, $help, $status, $required, $assertionArray)
{
$this->assertArraySubset([$position => [
@ -87,66 +111,73 @@ 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([
'curl_init' => true,
'imagecreatefromjpeg' => true,
@ -308,13 +339,14 @@ 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,