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;
|
2019-07-21 01:22:10 +02:00
|
|
|
use Friendica\Database\Database;
|
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;
|
2019-07-21 01:22:10 +02:00
|
|
|
use Friendica\Util\BasePath;
|
|
|
|
use Mockery\MockInterface;
|
2018-10-06 16:27:20 +02:00
|
|
|
|
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
|
|
|
|
2019-07-21 01:22:10 +02:00
|
|
|
/**
|
|
|
|
* @var BasePath|MockInterface
|
|
|
|
*/
|
|
|
|
private $basePathMock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Database|MockInterface
|
|
|
|
*/
|
|
|
|
private $databaseMock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Config\Cache\ConfigCache|MockInterface
|
|
|
|
*/
|
|
|
|
private $configCacheMock;
|
|
|
|
|
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();
|
2019-07-21 01:22:10 +02:00
|
|
|
|
|
|
|
$this->basePathMock = \Mockery::mock(BasePath::class);
|
|
|
|
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
|
|
|
|
|
|
|
|
$this->databaseMock = \Mockery::mock(Database::class);
|
|
|
|
$this->configCacheMock = \Mockery::mock(Config\Cache\ConfigCache::class);
|
2018-10-06 16:27:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testItEmpty()
|
|
|
|
{
|
2019-07-21 01:22:10 +02:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
2018-10-06 16:27:20 +02:00
|
|
|
$this->assertTrue($mode->isInstall());
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWithoutConfig()
|
|
|
|
{
|
2019-07-21 01:22:10 +02:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
2018-10-06 16:27:20 +02:00
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWithoutDatabase()
|
|
|
|
{
|
2019-07-21 01:22:10 +02:00
|
|
|
$this->databaseMock->shouldReceive('connected')->andReturn(false)->once();
|
2018-10-06 16:27:20 +02:00
|
|
|
|
2019-07-21 01:22:10 +02:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
2018-10-06 16:27:20 +02:00
|
|
|
$mode->determine();
|
|
|
|
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
$this->assertTrue($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
|
|
|
|
$this->assertFalse($mode->has(Mode::DBAVAILABLE));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWithoutDatabaseSetup()
|
|
|
|
{
|
2019-07-21 01:22:10 +02:00
|
|
|
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
|
|
|
|
$this->databaseMock->shouldReceive('fetchFirst')
|
|
|
|
->with('SHOW TABLES LIKE \'config\'')->andReturn(false)->once();
|
2018-10-06 16:27:20 +02:00
|
|
|
|
2019-07-21 01:22:10 +02:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
2018-10-06 16:27:20 +02:00
|
|
|
$mode->determine();
|
|
|
|
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
$this->assertTrue($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWithMaintenanceMode()
|
|
|
|
{
|
2019-07-21 01:22:10 +02:00
|
|
|
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
|
|
|
|
$this->databaseMock->shouldReceive('fetchFirst')
|
|
|
|
->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once();
|
|
|
|
$this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
|
|
|
|
->andReturn(true)->once();
|
|
|
|
|
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
2018-10-06 16:27:20 +02:00
|
|
|
$mode->determine();
|
|
|
|
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
$this->assertFalse($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
|
|
|
|
$this->assertFalse($mode->has(Mode::MAINTENANCEDISABLED));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNormalMode()
|
|
|
|
{
|
2019-07-21 01:22:10 +02:00
|
|
|
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
|
|
|
|
$this->databaseMock->shouldReceive('fetchFirst')
|
|
|
|
->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once();
|
|
|
|
$this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
|
|
|
|
->andReturn(false)->once();
|
|
|
|
$this->databaseMock->shouldReceive('selectFirst')
|
|
|
|
->with('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])
|
|
|
|
->andReturn(false)->once();
|
|
|
|
|
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
2018-10-06 16:27:20 +02:00
|
|
|
$mode->determine();
|
|
|
|
|
|
|
|
$this->assertTrue($mode->isNormal());
|
|
|
|
$this->assertFalse($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
|
|
|
|
$this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
|
|
|
|
}
|
|
|
|
}
|