Blame view

sources/tests/lib/utilcheckserver.php 3 KB
f7d878ff1   kload   [enh] Update to 7...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  <?php
  /**
   * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
   * This file is licensed under the Affero General Public License version 3 or
   * later.
   * See the COPYING-README file.
   */
  
  /**
   * Tests for server check functions
   */
  class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
  
  	private $datadir;
  
  	public function setUp() {
  		$this->datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data');
  
  		file_put_contents($this->datadir . '/.ocdata', '');
  	}
  
  	public function tearDown() {
  		// clean up
  		@unlink($this->datadir . '/.ocdata');
  	}
  
  	/**
  	 * Test that checkServer() returns no errors in the regular case.
  	 */
  	public function testCheckServer() {
  		$result = \OC_Util::checkServer();
  		$this->assertEmpty($result);
  	}
  
  	/**
  	 * Test that checkServer() does not check the data dir validity
  	 * when the server is not installed yet (else the setup cannot
  	 * be run...)
  	 */
  	public function testCheckServerSkipDataDirValidityOnSetup() {
  		// simulate old version that didn't have it
  		unlink($this->datadir . '/.ocdata');
  
  		$session = \OC::$server->getSession();
  		$oldInstalled = \OC_Config::getValue('installed', false);
  
  		// simulate that the server isn't setup yet
  		\OC_Config::setValue('installed', false);
  
  		// even though ".ocdata" is missing, the error isn't
  		// triggered to allow setup to run
  		$result = \OC_Util::checkServer();
  		$this->assertEmpty($result);
  
  		// restore config
  		\OC_Config::setValue('installed', $oldInstalled);
  	}
  
  	/**
  	 * Test that checkServer() does not check the data dir validity
  	 * when an upgrade is required (else the upgrade cannot be
  	 * performed...)
  	 */
  	public function testCheckServerSkipDataDirValidityOnUpgrade() {
  		// simulate old version that didn't have it
  		unlink($this->datadir . '/.ocdata');
  
  		$session = \OC::$server->getSession();
  		$oldCurrentVersion = $session->get('OC_Version');
  		$oldInstallVersion = \OC_Config::getValue('version', '0.0.0');
  
  		// upgrade condition to simulate needUpgrade() === true
  		$session->set('OC_Version', array(6, 0, 0, 2));
  		\OC_Config::setValue('version', '6.0.0.1');
  
  		// even though ".ocdata" is missing, the error isn't
  		// triggered to allow for upgrade
  		$result = \OC_Util::checkServer();
  		$this->assertEmpty($result);
  
  		// restore versions
  		$session->set('OC_Version', $oldCurrentVersion);
  		\OC_Config::setValue('version', $oldInstallVersion);
  	}
  
  	/**
  	 * Test that checkDataDirectoryValidity returns no error
  	 * when ".ocdata" is present.
  	 */
  	public function testCheckDataDirValidity() {
  		$result = \OC_Util::checkDataDirectoryValidity($this->datadir);
  		$this->assertEmpty($result);
  	}
  
  	/**
  	 * Test that checkDataDirectoryValidity and checkServer 
  	 * both return an error when ".ocdata" is missing.
  	 */
  	public function testCheckDataDirValidityWhenFileMissing() {
  		unlink($this->datadir . '/.ocdata');
  		$result = \OC_Util::checkDataDirectoryValidity($this->datadir);
  		$this->assertEquals(1, count($result));
  
  		$result = \OC_Util::checkServer();
  		$this->assertEquals(1, count($result));
  	}
  
  }