<?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
namespace Friendica\Test\src\App;
use Detection\MobileDetect;
+use Friendica\App\Arguments;
use Friendica\App\Mode;
-use Friendica\App\Module;
-use Friendica\Core\Config;
+use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Database\Database;
use Friendica\Test\MockedTest;
-use Friendica\Test\Util\DBAMockTrait;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\BasePath;
+use Mockery;
use Mockery\MockInterface;
class ModeTest extends MockedTest
{
use VFSTrait;
- use DBAMockTrait;
/**
* @var BasePath|MockInterface
private $databaseMock;
/**
- * @var Config\Cache\ConfigCache|MockInterface
+ * @var Cache|MockInterface
*/
private $configCacheMock;
- public function setUp()
+ protected function setUp(): void
{
parent::setUp();
$this->setUpVfsDir();
- $this->basePathMock = \Mockery::mock(BasePath::class);
- $this->databaseMock = \Mockery::mock(Database::class);
- $this->configCacheMock = \Mockery::mock(Config\Cache\ConfigCache::class);
+ $this->basePathMock = Mockery::mock(BasePath::class);
+ $this->databaseMock = Mockery::mock(Database::class);
+ $this->configCacheMock = Mockery::mock(Cache::class);
}
public function testItEmpty()
{
$mode = new Mode();
- $this->assertTrue($mode->isInstall());
- $this->assertFalse($mode->isNormal());
+ self::assertTrue($mode->isInstall());
+ self::assertFalse($mode->isNormal());
}
public function testWithoutConfig()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
- $this->assertTrue($this->root->hasChild('config/local.config.php'));
+ self::assertTrue($this->root->hasChild('config/local.config.php'));
$this->delConfigFile('local.config.php');
- $this->assertFalse($this->root->hasChild('config/local.config.php'));
+ self::assertFalse($this->root->hasChild('config/local.config.php'));
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
- $this->assertTrue($mode->isInstall());
- $this->assertFalse($mode->isNormal());
+ self::assertTrue($mode->isInstall());
+ self::assertFalse($mode->isNormal());
- $this->assertFalse($mode->has(Mode::LOCALCONFIGPRESENT));
+ self::assertFalse($mode->has(Mode::LOCALCONFIGPRESENT));
}
public function testWithoutDatabase()
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
- $this->assertFalse($mode->isNormal());
- $this->assertTrue($mode->isInstall());
+ self::assertFalse($mode->isNormal());
+ self::assertTrue($mode->isInstall());
- $this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
- $this->assertFalse($mode->has(Mode::DBAVAILABLE));
- }
-
- public function testWithoutDatabaseSetup()
- {
- $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
- $this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
- $this->databaseMock->shouldReceive('fetchFirst')
- ->with('SHOW TABLES LIKE \'config\'')->andReturn(false)->once();
-
- $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
-
- $this->assertFalse($mode->isNormal());
- $this->assertTrue($mode->isInstall());
-
- $this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
+ self::assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
+ self::assertFalse($mode->has(Mode::DBAVAILABLE));
}
public function testWithMaintenanceMode()
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$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();
+ ->andReturn(true)->once();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
- $this->assertFalse($mode->isNormal());
- $this->assertFalse($mode->isInstall());
+ self::assertFalse($mode->isNormal());
+ self::assertFalse($mode->isInstall());
- $this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
- $this->assertFalse($mode->has(Mode::MAINTENANCEDISABLED));
+ self::assertFalse($mode->has(Mode::MAINTENANCEDISABLED));
}
public function testNormalMode()
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$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' => null])->once();
+ ->andReturn(false)->once();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
- $this->assertTrue($mode->isNormal());
- $this->assertFalse($mode->isInstall());
+ self::assertTrue($mode->isNormal());
+ self::assertFalse($mode->isInstall());
- $this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
- $this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
+ self::assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
}
/**
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$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();
+ ->andReturn(false)->once();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
- $this->assertTrue($mode->isNormal());
- $this->assertFalse($mode->isInstall());
+ self::assertTrue($mode->isNormal());
+ self::assertFalse($mode->isInstall());
- $this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
- $this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
+ self::assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
}
/**
$modeNew = $mode->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
- $this->assertNotSame($modeNew, $mode);
+ self::assertNotSame($modeNew, $mode);
}
/**
* Test if not called by index is backend
*/
- public function testIsBackendNotIndex()
+ public function testIsBackendNotIsBackend()
{
- $server = ['PHP_SELF' => '/daemon.php'];
- $module = new Module();
+ $server = [];
+ $args = new Arguments();
$mobileDetect = new MobileDetect();
- $mode = (new Mode())->determineRunMode($module, $server, $mobileDetect);
+ $mode = (new Mode())->determineRunMode(true, $server, $args, $mobileDetect);
- $this->assertTrue($mode->isBackend());
+ self::assertTrue($mode->isBackend());
}
/**
*/
public function testIsBackendButIndex()
{
- $server = ['PHP_SELF' => '/index.php'];
- $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, true);
+ $server = [];
+ $args = new Arguments('', '', Mode::BACKEND_MODULES[0]);
$mobileDetect = new MobileDetect();
- $mode = (new Mode())->determineRunMode($module, $server, $mobileDetect);
+ $mode = (new Mode())->determineRunMode(false, $server, $args, $mobileDetect);
- $this->assertTrue($mode->isBackend());
+ self::assertTrue($mode->isBackend());
}
/**
*/
public function testIsNotBackend()
{
- $server = ['PHP_SELF' => '/index.php'];
- $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, false);
+ $server = [];
+ $args = new Arguments('', '', Arguments::DEFAULT_MODULE);
$mobileDetect = new MobileDetect();
- $mode = (new Mode())->determineRunMode($module, $server, $mobileDetect);
+ $mode = (new Mode())->determineRunMode(false, $server, $args, $mobileDetect);
- $this->assertFalse($mode->isBackend());
+ self::assertFalse($mode->isBackend());
}
/**
'HTTP_X_REQUESTED_WITH' => 'xmlhttprequest',
];
- $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, false);
+ $args = new Arguments('', '', Arguments::DEFAULT_MODULE);
$mobileDetect = new MobileDetect();
- $mode = (new Mode())->determineRunMode($module, $server, $mobileDetect);
+ $mode = (new Mode())->determineRunMode(true, $server, $args, $mobileDetect);
- $this->assertTrue($mode->isAjax());
+ self::assertTrue($mode->isAjax());
}
/**
*/
public function testIsNotAjax()
{
- $server = [];
- $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, false);
+ $server = [];
+ $args = new Arguments('', '', Arguments::DEFAULT_MODULE);
$mobileDetect = new MobileDetect();
- $mode = (new Mode())->determineRunMode($module, $server, $mobileDetect);
+ $mode = (new Mode())->determineRunMode(true, $server, $args, $mobileDetect);
- $this->assertFalse($mode->isAjax());
+ self::assertFalse($mode->isAjax());
}
/**
*/
public function testIsMobileIsTablet()
{
- $server = [];
- $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, false);
- $mobileDetect = \Mockery::mock(MobileDetect::class);
+ $server = [];
+ $args = new Arguments('', '', Arguments::DEFAULT_MODULE);
+ $mobileDetect = Mockery::mock(MobileDetect::class);
$mobileDetect->shouldReceive('isMobile')->andReturn(true);
$mobileDetect->shouldReceive('isTablet')->andReturn(true);
- $mode = (new Mode())->determineRunMode($module, $server, $mobileDetect);
+ $mode = (new Mode())->determineRunMode(true, $server, $args, $mobileDetect);
- $this->assertTrue($mode->isMobile());
- $this->assertTrue($mode->isTablet());
+ self::assertTrue($mode->isMobile());
+ self::assertTrue($mode->isTablet());
}
*/
public function testIsNotMobileIsNotTablet()
{
- $server = [];
- $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, false);
- $mobileDetect = \Mockery::mock(MobileDetect::class);
+ $server = [];
+ $args = new Arguments('', '', Arguments::DEFAULT_MODULE);
+ $mobileDetect = Mockery::mock(MobileDetect::class);
$mobileDetect->shouldReceive('isMobile')->andReturn(false);
$mobileDetect->shouldReceive('isTablet')->andReturn(false);
- $mode = (new Mode())->determineRunMode($module, $server, $mobileDetect);
+ $mode = (new Mode())->determineRunMode(true, $server, $args, $mobileDetect);
- $this->assertFalse($mode->isMobile());
- $this->assertFalse($mode->isTablet());
+ self::assertFalse($mode->isMobile());
+ self::assertFalse($mode->isTablet());
}
}