use Detection\MobileDetect;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Database\Database;
-use Friendica\Util\BasePath;
/**
* Mode of the current Friendica Node
*
* @throws \Exception
*/
- public function determine(BasePath $basepath, Database $database, Cache $configCache): Mode
+ public function determine(string $basePath, Database $database, Cache $configCache): Mode
{
$mode = 0;
- $basepathName = $basepath->getPath();
-
- if (!file_exists($basepathName . '/config/local.config.php')
- && !file_exists($basepathName . '/config/local.ini.php')
- && !file_exists($basepathName . '/.htconfig.php')) {
+ if (!file_exists($basePath . '/config/local.config.php') &&
+ !file_exists($basePath . '/config/local.ini.php') &&
+ !file_exists($basePath . '/.htconfig.php')) {
return new Mode($mode);
}
$this->setUpVfsDir();
- $this->basePathMock = Mockery::mock(BasePath::class);
$this->databaseMock = Mockery::mock(Database::class);
$this->configCacheMock = Mockery::mock(Cache::class);
}
public function testWithoutConfig()
{
- $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
self::assertTrue($this->root->hasChild('config/local.config.php'));
$this->delConfigFile('local.config.php');
self::assertFalse($this->root->hasChild('config/local.config.php'));
- $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+ $mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configCacheMock);
self::assertTrue($mode->isInstall());
self::assertFalse($mode->isNormal());
public function testWithoutDatabase()
{
- $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
$this->databaseMock->shouldReceive('connected')->andReturn(false)->once();
- $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+ $mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configCacheMock);
self::assertFalse($mode->isNormal());
self::assertTrue($mode->isInstall());
public function testWithMaintenanceMode()
{
- $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
$this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
->andReturn(true)->once();
- $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+ $mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configCacheMock);
self::assertFalse($mode->isNormal());
self::assertFalse($mode->isInstall());
public function testNormalMode()
{
- $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
$this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
->andReturn(false)->once();
- $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+ $mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configCacheMock);
self::assertTrue($mode->isNormal());
self::assertFalse($mode->isInstall());
*/
public function testDisabledMaintenance()
{
- $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
$this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
->andReturn(false)->once();
- $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+ $mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configCacheMock);
self::assertTrue($mode->isNormal());
self::assertFalse($mode->isInstall());
*/
public function testImmutable()
{
- $this->basePathMock->shouldReceive('getPath')->andReturn(null)->once();
-
$mode = new Mode();
- $modeNew = $mode->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+ $modeNew = $mode->determine('', $this->databaseMock, $this->configCacheMock);
self::assertNotSame($modeNew, $mode);
}