123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace Test;
- class UtilCheckServerTest extends \Test\TestCase {
- private $datadir;
-
- protected function getConfig($systemOptions) {
- $systemOptions['datadirectory'] = $this->datadir;
- $systemOptions['appstoreenabled'] = false;
- $config = $this->getMockBuilder('\OC\SystemConfig')
- ->disableOriginalConstructor()
- ->getMock();
- $config->expects($this->any())
- ->method('getValue')
- ->willReturnCallback(function ($key, $default) use ($systemOptions) {
- return $systemOptions[$key] ?? $default;
- });
- return $config;
- }
- protected function setUp(): void {
- parent::setUp();
- $this->datadir = \OC::$server->getTempManager()->getTemporaryFolder();
- file_put_contents($this->datadir . '/.ocdata', '');
- \OC::$server->getSession()->set('checkServer_succeeded', false);
- }
- protected function tearDown(): void {
-
- @unlink($this->datadir . '/.ocdata');
- parent::tearDown();
- }
-
- public function testCheckServer() {
- $result = \OC_Util::checkServer($this->getConfig([
- 'installed' => true
- ]));
- $this->assertEmpty($result);
- }
-
- public function testCheckServerSkipDataDirValidityOnSetup() {
-
- unlink($this->datadir . '/.ocdata');
-
-
- $result = \OC_Util::checkServer($this->getConfig([
- 'installed' => false
- ]));
- $this->assertEmpty($result);
- }
-
- public function testCheckServerSkipDataDirValidityOnUpgrade() {
-
- unlink($this->datadir . '/.ocdata');
- $session = \OC::$server->getSession();
- $oldCurrentVersion = $session->get('OC_Version');
-
- $session->set('OC_Version', [6, 0, 0, 2]);
-
-
- $result = \OC_Util::checkServer($this->getConfig([
- 'installed' => true,
- 'version' => '6.0.0.1'
- ]));
- $this->assertEmpty($result);
-
- $session->set('OC_Version', $oldCurrentVersion);
- }
-
- public function testCheckDataDirValidity() {
- $result = \OC_Util::checkDataDirectoryValidity($this->datadir);
- $this->assertEmpty($result);
- }
-
- public function testCheckDataDirValidityWhenFileMissing() {
- unlink($this->datadir . '/.ocdata');
- $result = \OC_Util::checkDataDirectoryValidity($this->datadir);
- $this->assertEquals(1, count($result));
- $result = \OC_Util::checkServer($this->getConfig([
- 'installed' => true,
- 'version' => implode('.', \OCP\Util::getVersion())
- ]));
- $this->assertCount(1, $result);
- }
-
- public function testDataDirWritable() {
- $result = \OC_Util::checkServer($this->getConfig([
- 'installed' => true,
- 'version' => implode('.', \OCP\Util::getVersion())
- ]));
- $this->assertEmpty($result);
- }
-
- public function testDataDirNotWritable() {
- $this->markTestSkipped('TODO: Disable because fails on drone');
- chmod($this->datadir, 0300);
- $result = \OC_Util::checkServer($this->getConfig([
- 'installed' => true,
- 'version' => implode('.', \OCP\Util::getVersion())
- ]));
- $this->assertCount(1, $result);
- }
-
- public function testDataDirNotWritableSetup() {
- chmod($this->datadir, 0300);
- $result = \OC_Util::checkServer($this->getConfig([
- 'installed' => false,
- 'version' => implode('.', \OCP\Util::getVersion())
- ]));
- chmod($this->datadir, 0700);
- $this->assertEmpty($result);
- }
- }
|