2018-10-06 16:27:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Test\src\App;
|
|
|
|
|
|
|
|
use Friendica\App\Mode;
|
2019-02-07 20:44:03 +01:00
|
|
|
use Friendica\Core\Config;
|
2018-11-01 13:44:47 +01:00
|
|
|
use Friendica\Test\MockedTest;
|
|
|
|
use Friendica\Test\Util\DBAMockTrait;
|
2018-10-06 16:27:20 +02:00
|
|
|
use Friendica\Test\Util\VFSTrait;
|
|
|
|
|
2018-11-01 13:44:47 +01:00
|
|
|
class ModeTest extends MockedTest
|
2018-10-06 16:27:20 +02:00
|
|
|
{
|
|
|
|
use VFSTrait;
|
2018-11-01 13:44:47 +01:00
|
|
|
use DBAMockTrait;
|
2018-10-06 16:27:20 +02:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2019-02-07 20:44:03 +01:00
|
|
|
parent::setUp();
|
2018-10-06 16:27:20 +02:00
|
|
|
|
|
|
|
$this->setUpVfsDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItEmpty()
|
|
|
|
{
|
|
|
|
$mode = new Mode($this->root->url());
|
|
|
|
$this->assertTrue($mode->isInstall());
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWithoutConfig()
|
|
|
|
{
|
|
|
|
$mode = new Mode($this->root->url());
|
|
|
|
|
2018-11-25 07:44:09 +01:00
|
|
|
$this->assertTrue($this->root->hasChild('config/local.config.php'));
|
2018-10-06 16:27:20 +02:00
|
|
|
|
2018-11-25 07:44:09 +01:00
|
|
|
$this->delConfigFile('local.config.php');
|
2018-10-06 16:27:20 +02:00
|
|
|
|
2018-11-25 07:44:09 +01:00
|
|
|
$this->assertFalse($this->root->hasChild('config/local.config.php'));
|
2018-10-06 16:27:20 +02:00
|
|
|
|
|
|
|
$mode->determine();
|
|
|
|
|
|
|
|
$this->assertTrue($mode->isInstall());
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
|
|
|
|
$this->assertFalse($mode->has(Mode::LOCALCONFIGPRESENT));
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:44:03 +01:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
*/
|
2018-10-06 16:27:20 +02:00
|
|
|
public function testWithoutDatabase()
|
|
|
|
{
|
2018-11-01 13:44:47 +01:00
|
|
|
$this->mockConnected(false, 1);
|
2018-10-06 16:27:20 +02:00
|
|
|
|
|
|
|
$mode = new Mode($this->root->url());
|
|
|
|
$mode->determine();
|
|
|
|
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
$this->assertTrue($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
|
|
|
|
$this->assertFalse($mode->has(Mode::DBAVAILABLE));
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:44:03 +01:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
*/
|
2018-10-06 16:27:20 +02:00
|
|
|
public function testWithoutDatabaseSetup()
|
|
|
|
{
|
2018-11-01 13:44:47 +01:00
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', false, 1);
|
2018-10-06 16:27:20 +02:00
|
|
|
|
|
|
|
$mode = new Mode($this->root->url());
|
|
|
|
$mode->determine();
|
|
|
|
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
$this->assertTrue($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:44:03 +01:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
*/
|
2018-10-06 16:27:20 +02:00
|
|
|
public function testWithMaintenanceMode()
|
|
|
|
{
|
2018-11-01 13:44:47 +01:00
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
|
2019-02-07 20:44:03 +01:00
|
|
|
|
2019-02-17 21:41:45 +01:00
|
|
|
$config = \Mockery::mock(Config\Configuration::class);
|
2019-02-07 20:44:03 +01:00
|
|
|
$config
|
|
|
|
->shouldReceive('get')
|
2019-02-10 19:52:21 +01:00
|
|
|
->with('system', 'maintenance', null, false)
|
2019-02-07 20:44:03 +01:00
|
|
|
->andReturn(true)
|
|
|
|
->once();
|
|
|
|
// Initialize empty Config
|
|
|
|
Config::init($config);
|
2018-10-06 16:27:20 +02:00
|
|
|
|
|
|
|
$mode = new Mode($this->root->url());
|
|
|
|
$mode->determine();
|
|
|
|
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
$this->assertFalse($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
|
|
|
|
$this->assertFalse($mode->has(Mode::MAINTENANCEDISABLED));
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:44:03 +01:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
*/
|
2018-10-06 16:27:20 +02:00
|
|
|
public function testNormalMode()
|
|
|
|
{
|
2018-11-01 13:44:47 +01:00
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
|
2019-02-07 20:44:03 +01:00
|
|
|
|
2019-02-17 21:41:45 +01:00
|
|
|
$config = \Mockery::mock(Config\Configuration::class);
|
2019-02-07 20:44:03 +01:00
|
|
|
$config
|
|
|
|
->shouldReceive('get')
|
2019-02-10 19:52:21 +01:00
|
|
|
->with('system', 'maintenance', null, false)
|
2019-02-07 20:44:03 +01:00
|
|
|
->andReturn(false)
|
|
|
|
->once();
|
|
|
|
// Initialize empty Config
|
|
|
|
Config::init($config);
|
2018-10-06 16:27:20 +02:00
|
|
|
|
|
|
|
$mode = new Mode($this->root->url());
|
|
|
|
$mode->determine();
|
|
|
|
|
|
|
|
$this->assertTrue($mode->isNormal());
|
|
|
|
$this->assertFalse($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
|
|
|
|
$this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
|
|
|
|
}
|
|
|
|
}
|