Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ModeTest.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace Friendica\Test\src\App;
  3. use Friendica\App\Mode;
  4. use Friendica\Test\Util\VFSTrait;
  5. use PHPUnit\Framework\TestCase;
  6. /**
  7. * @runTestsInSeparateProcesses
  8. * @preserveGlobalState disabled
  9. */
  10. class ModeTest extends TestCase
  11. {
  12. use VFSTrait;
  13. public function setUp()
  14. {
  15. parent::setUp(); // TODO: Change the autogenerated stub
  16. $this->setUpVfsDir();
  17. }
  18. public function testItEmpty()
  19. {
  20. $mode = new Mode($this->root->url());
  21. $this->assertTrue($mode->isInstall());
  22. $this->assertFalse($mode->isNormal());
  23. }
  24. public function testWithoutConfig()
  25. {
  26. $mode = new Mode($this->root->url());
  27. $this->assertTrue($this->root->hasChild('config/local.ini.php'));
  28. $this->delConfigFile('local.ini.php');
  29. $this->assertFalse($this->root->hasChild('config/local.ini.php'));
  30. $mode->determine();
  31. $this->assertTrue($mode->isInstall());
  32. $this->assertFalse($mode->isNormal());
  33. $this->assertFalse($mode->has(Mode::LOCALCONFIGPRESENT));
  34. }
  35. public function testWithoutDatabase()
  36. {
  37. $dba = \Mockery::mock('alias:Friendica\Database\DBA');
  38. $dba
  39. ->shouldReceive('connected')
  40. ->andReturn(false);
  41. $mode = new Mode($this->root->url());
  42. $mode->determine();
  43. $this->assertFalse($mode->isNormal());
  44. $this->assertTrue($mode->isInstall());
  45. $this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
  46. $this->assertFalse($mode->has(Mode::DBAVAILABLE));
  47. }
  48. public function testWithoutDatabaseSetup()
  49. {
  50. $dba = \Mockery::mock('alias:Friendica\Database\DBA');
  51. $dba
  52. ->shouldReceive('connected')
  53. ->andReturn(true);
  54. $dba
  55. ->shouldReceive('fetchFirst')
  56. ->with('SHOW TABLES LIKE \'config\'')
  57. ->andReturn(false);
  58. $mode = new Mode($this->root->url());
  59. $mode->determine();
  60. $this->assertFalse($mode->isNormal());
  61. $this->assertTrue($mode->isInstall());
  62. $this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
  63. }
  64. public function testWithMaintenanceMode()
  65. {
  66. $dba = \Mockery::mock('alias:Friendica\Database\DBA');
  67. $dba
  68. ->shouldReceive('connected')
  69. ->andReturn(true);
  70. $dba
  71. ->shouldReceive('fetchFirst')
  72. ->with('SHOW TABLES LIKE \'config\'')
  73. ->andReturn(true);
  74. $conf = \Mockery::mock('alias:Friendica\Core\Config');
  75. $conf
  76. ->shouldReceive('get')
  77. ->with('system', 'maintenance')
  78. ->andReturn(true);
  79. $mode = new Mode($this->root->url());
  80. $mode->determine();
  81. $this->assertFalse($mode->isNormal());
  82. $this->assertFalse($mode->isInstall());
  83. $this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
  84. $this->assertFalse($mode->has(Mode::MAINTENANCEDISABLED));
  85. }
  86. public function testNormalMode()
  87. {
  88. $dba = \Mockery::mock('alias:Friendica\Database\DBA');
  89. $dba
  90. ->shouldReceive('connected')
  91. ->andReturn(true);
  92. $dba
  93. ->shouldReceive('fetchFirst')
  94. ->with('SHOW TABLES LIKE \'config\'')
  95. ->andReturn(true);
  96. $conf = \Mockery::mock('alias:Friendica\Core\Config');
  97. $conf
  98. ->shouldReceive('get')
  99. ->with('system', 'maintenance')
  100. ->andReturn(false);
  101. $mode = new Mode($this->root->url());
  102. $mode->determine();
  103. $this->assertTrue($mode->isNormal());
  104. $this->assertFalse($mode->isInstall());
  105. $this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
  106. $this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
  107. }
  108. }