]> git.mxchange.org Git - friendica.git/blob - tests/src/App/ModeTest.php
Introduce DICE
[friendica.git] / tests / src / App / ModeTest.php
1 <?php
2
3 namespace Friendica\Test\src\App;
4
5 use Friendica\App\Mode;
6 use Friendica\Core\Config;
7 use Friendica\Database\Database;
8 use Friendica\Test\MockedTest;
9 use Friendica\Test\Util\DBAMockTrait;
10 use Friendica\Test\Util\VFSTrait;
11 use Friendica\Util\BasePath;
12 use Mockery\MockInterface;
13
14 class ModeTest extends MockedTest
15 {
16         use VFSTrait;
17         use DBAMockTrait;
18
19         /**
20          * @var BasePath|MockInterface
21          */
22         private $basePathMock;
23
24         /**
25          * @var Database|MockInterface
26          */
27         private $databaseMock;
28
29         /**
30          * @var Config\Cache\ConfigCache|MockInterface
31          */
32         private $configCacheMock;
33
34         public function setUp()
35         {
36                 parent::setUp();
37
38                 $this->setUpVfsDir();
39
40                 $this->basePathMock = \Mockery::mock(BasePath::class);
41                 $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
42
43                 $this->databaseMock = \Mockery::mock(Database::class);
44                 $this->configCacheMock = \Mockery::mock(Config\Cache\ConfigCache::class);
45         }
46
47         public function testItEmpty()
48         {
49                 $mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
50                 $this->assertTrue($mode->isInstall());
51                 $this->assertFalse($mode->isNormal());
52         }
53
54         public function testWithoutConfig()
55         {
56                 $mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
57
58                 $this->assertTrue($this->root->hasChild('config/local.config.php'));
59
60                 $this->delConfigFile('local.config.php');
61
62                 $this->assertFalse($this->root->hasChild('config/local.config.php'));
63
64                 $mode->determine();
65
66                 $this->assertTrue($mode->isInstall());
67                 $this->assertFalse($mode->isNormal());
68
69                 $this->assertFalse($mode->has(Mode::LOCALCONFIGPRESENT));
70         }
71
72         public function testWithoutDatabase()
73         {
74                 $this->databaseMock->shouldReceive('connected')->andReturn(false)->once();
75
76                 $mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
77                 $mode->determine();
78
79                 $this->assertFalse($mode->isNormal());
80                 $this->assertTrue($mode->isInstall());
81
82                 $this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
83                 $this->assertFalse($mode->has(Mode::DBAVAILABLE));
84         }
85
86         public function testWithoutDatabaseSetup()
87         {
88                 $this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
89                 $this->databaseMock->shouldReceive('fetchFirst')
90                                    ->with('SHOW TABLES LIKE \'config\'')->andReturn(false)->once();
91
92                 $mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
93                 $mode->determine();
94
95                 $this->assertFalse($mode->isNormal());
96                 $this->assertTrue($mode->isInstall());
97
98                 $this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
99         }
100
101         public function testWithMaintenanceMode()
102         {
103                 $this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
104                 $this->databaseMock->shouldReceive('fetchFirst')
105                                    ->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once();
106                 $this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
107                                       ->andReturn(true)->once();
108
109                 $mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
110                 $mode->determine();
111
112                 $this->assertFalse($mode->isNormal());
113                 $this->assertFalse($mode->isInstall());
114
115                 $this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
116                 $this->assertFalse($mode->has(Mode::MAINTENANCEDISABLED));
117         }
118
119         public function testNormalMode()
120         {
121                 $this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
122                 $this->databaseMock->shouldReceive('fetchFirst')
123                                    ->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once();
124                 $this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
125                                       ->andReturn(false)->once();
126                 $this->databaseMock->shouldReceive('selectFirst')
127                                    ->with('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])
128                                    ->andReturn(false)->once();
129
130                 $mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
131                 $mode->determine();
132
133                 $this->assertTrue($mode->isNormal());
134                 $this->assertFalse($mode->isInstall());
135
136                 $this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
137                 $this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
138         }
139 }