2018-10-06 10:27:20 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Test\src\App;
|
|
|
|
|
|
|
|
use Friendica\App\Mode;
|
2019-02-07 14:44:03 -05:00
|
|
|
use Friendica\Core\Config;
|
2019-07-20 19:22:10 -04:00
|
|
|
use Friendica\Database\Database;
|
2018-11-01 08:44:47 -04:00
|
|
|
use Friendica\Test\MockedTest;
|
|
|
|
use Friendica\Test\Util\DBAMockTrait;
|
2018-10-06 10:27:20 -04:00
|
|
|
use Friendica\Test\Util\VFSTrait;
|
2019-07-20 19:22:10 -04:00
|
|
|
use Friendica\Util\BasePath;
|
|
|
|
use Mockery\MockInterface;
|
2018-10-06 10:27:20 -04:00
|
|
|
|
2018-11-01 08:44:47 -04:00
|
|
|
class ModeTest extends MockedTest
|
2018-10-06 10:27:20 -04:00
|
|
|
{
|
|
|
|
use VFSTrait;
|
2018-11-01 08:44:47 -04:00
|
|
|
use DBAMockTrait;
|
2018-10-06 10:27:20 -04:00
|
|
|
|
2019-07-20 19:22:10 -04:00
|
|
|
/**
|
|
|
|
* @var BasePath|MockInterface
|
|
|
|
*/
|
|
|
|
private $basePathMock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Database|MockInterface
|
|
|
|
*/
|
|
|
|
private $databaseMock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Config\Cache\ConfigCache|MockInterface
|
|
|
|
*/
|
|
|
|
private $configCacheMock;
|
|
|
|
|
2018-10-06 10:27:20 -04:00
|
|
|
public function setUp()
|
|
|
|
{
|
2019-02-07 14:44:03 -05:00
|
|
|
parent::setUp();
|
2018-10-06 10:27:20 -04:00
|
|
|
|
|
|
|
$this->setUpVfsDir();
|
2019-07-20 19:22:10 -04:00
|
|
|
|
|
|
|
$this->basePathMock = \Mockery::mock(BasePath::class);
|
2019-08-11 18:01:11 -04:00
|
|
|
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
|
|
|
|
|
2019-07-20 19:22:10 -04:00
|
|
|
$this->databaseMock = \Mockery::mock(Database::class);
|
|
|
|
$this->configCacheMock = \Mockery::mock(Config\Cache\ConfigCache::class);
|
2018-10-06 10:27:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testItEmpty()
|
|
|
|
{
|
2019-08-11 18:01:11 -04:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
2018-10-06 10:27:20 -04:00
|
|
|
$this->assertTrue($mode->isInstall());
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWithoutConfig()
|
|
|
|
{
|
2019-08-11 18:01:11 -04:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
2018-10-06 10:27:20 -04:00
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->assertTrue($this->root->hasChild('config/local.config.php'));
|
2018-10-06 10:27:20 -04:00
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->delConfigFile('local.config.php');
|
2018-10-06 10:27:20 -04:00
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->assertFalse($this->root->hasChild('config/local.config.php'));
|
2018-10-06 10:27:20 -04:00
|
|
|
|
2019-08-11 18:01:11 -04:00
|
|
|
$mode->determine();
|
2018-10-06 10:27:20 -04:00
|
|
|
|
|
|
|
$this->assertTrue($mode->isInstall());
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
|
|
|
|
$this->assertFalse($mode->has(Mode::LOCALCONFIGPRESENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWithoutDatabase()
|
|
|
|
{
|
2019-07-20 19:22:10 -04:00
|
|
|
$this->databaseMock->shouldReceive('connected')->andReturn(false)->once();
|
2018-10-06 10:27:20 -04:00
|
|
|
|
2019-08-11 18:01:11 -04:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
|
|
|
$mode->determine();
|
2018-10-06 10:27:20 -04:00
|
|
|
|
|
|
|
$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-20 19:22:10 -04:00
|
|
|
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
|
|
|
|
$this->databaseMock->shouldReceive('fetchFirst')
|
|
|
|
->with('SHOW TABLES LIKE \'config\'')->andReturn(false)->once();
|
2018-10-06 10:27:20 -04:00
|
|
|
|
2019-08-11 18:01:11 -04:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
|
|
|
$mode->determine();
|
2018-10-06 10:27:20 -04:00
|
|
|
|
|
|
|
$this->assertFalse($mode->isNormal());
|
|
|
|
$this->assertTrue($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWithMaintenanceMode()
|
|
|
|
{
|
2019-07-20 19:22:10 -04: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();
|
|
|
|
|
2019-08-11 18:01:11 -04:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
|
|
|
$mode->determine();
|
2018-10-06 10:27:20 -04:00
|
|
|
|
|
|
|
$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-20 19:22:10 -04: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'])
|
2019-07-21 08:40:50 -04:00
|
|
|
->andReturn(['v' => null])->once();
|
|
|
|
|
2019-08-11 18:01:11 -04:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
|
|
|
$mode->determine();
|
2019-07-21 08:40:50 -04:00
|
|
|
|
|
|
|
$this->assertTrue($mode->isNormal());
|
|
|
|
$this->assertFalse($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
|
|
|
|
$this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test explicit disabled maintenance (in case you manually disable it)
|
|
|
|
*/
|
|
|
|
public function testDisabledMaintenance()
|
|
|
|
{
|
|
|
|
$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(['v' => '0'])->once();
|
2019-07-20 19:22:10 -04:00
|
|
|
|
2019-08-11 18:01:11 -04:00
|
|
|
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
|
|
|
|
$mode->determine();
|
2018-10-06 10:27:20 -04:00
|
|
|
|
|
|
|
$this->assertTrue($mode->isNormal());
|
|
|
|
$this->assertFalse($mode->isInstall());
|
|
|
|
|
|
|
|
$this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
|
|
|
|
$this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
|
|
|
|
}
|
|
|
|
}
|