3 namespace Friendica\Test\src\App;
5 use Friendica\App\Mode;
6 use Friendica\Core\Config;
7 use Friendica\Test\MockedTest;
8 use Friendica\Test\Util\DBAMockTrait;
9 use Friendica\Test\Util\VFSTrait;
11 class ModeTest extends MockedTest
16 public function setUp()
23 public function testItEmpty()
25 $mode = new Mode($this->root->url());
26 $this->assertTrue($mode->isInstall());
27 $this->assertFalse($mode->isNormal());
30 public function testWithoutConfig()
32 $mode = new Mode($this->root->url());
34 $this->assertTrue($this->root->hasChild('config/local.config.php'));
36 $this->delConfigFile('local.config.php');
38 $this->assertFalse($this->root->hasChild('config/local.config.php'));
42 $this->assertTrue($mode->isInstall());
43 $this->assertFalse($mode->isNormal());
45 $this->assertFalse($mode->has(Mode::LOCALCONFIGPRESENT));
49 * @runInSeparateProcess
50 * @preserveGlobalState disabled
52 public function testWithoutDatabase()
54 $this->mockConnected(false, 1);
56 $mode = new Mode($this->root->url());
59 $this->assertFalse($mode->isNormal());
60 $this->assertTrue($mode->isInstall());
62 $this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
63 $this->assertFalse($mode->has(Mode::DBAVAILABLE));
67 * @runInSeparateProcess
68 * @preserveGlobalState disabled
70 public function testWithoutDatabaseSetup()
72 $this->mockConnected(true, 1);
73 $this->mockFetchFirst('SHOW TABLES LIKE \'config\'', false, 1);
75 $mode = new Mode($this->root->url());
78 $this->assertFalse($mode->isNormal());
79 $this->assertTrue($mode->isInstall());
81 $this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
85 * @runInSeparateProcess
86 * @preserveGlobalState disabled
88 public function testWithMaintenanceMode()
90 $this->mockConnected(true, 1);
91 $this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
93 $config = \Mockery::mock('Friendica\Core\Config\ConfigCache');
95 ->shouldReceive('get')
96 ->with('system', 'maintenance', null)
99 // Initialize empty Config
100 Config::init($config);
101 $configAdapter = \Mockery::mock('Friendica\Core\Config\IConfigAdapter');
103 ->shouldReceive('isConnected')
105 Config::setAdapter($configAdapter);
107 $mode = new Mode($this->root->url());
110 $this->assertFalse($mode->isNormal());
111 $this->assertFalse($mode->isInstall());
113 $this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
114 $this->assertFalse($mode->has(Mode::MAINTENANCEDISABLED));
118 * @runInSeparateProcess
119 * @preserveGlobalState disabled
121 public function testNormalMode()
123 $this->mockConnected(true, 1);
124 $this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
126 $config = \Mockery::mock('Friendica\Core\Config\ConfigCache');
128 ->shouldReceive('get')
129 ->with('system', 'maintenance', null)
132 // Initialize empty Config
133 Config::init($config);
134 $configAdapter = \Mockery::mock('Friendica\Core\Config\IConfigAdapter');
136 ->shouldReceive('isConnected')
138 Config::setAdapter($configAdapter);
140 $mode = new Mode($this->root->url());
143 $this->assertTrue($mode->isNormal());
144 $this->assertFalse($mode->isInstall());
146 $this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
147 $this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));