summaryrefslogtreecommitdiffstats
path: root/tests/lib/setup.php
blob: caaeec08fb31e617224c8e14985f17c2f2122f74 (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
 * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

use OCP\IConfig;

class Test_OC_Setup extends \Test\TestCase {

	/** @var IConfig | PHPUnit_Framework_MockObject_MockObject */
	protected $config;
	/** @var \bantu\IniGetWrapper\IniGetWrapper | PHPUnit_Framework_MockObject_MockObject */
	private $iniWrapper;
	/** @var \OCP\IL10N | PHPUnit_Framework_MockObject_MockObject */
	private $l10n;
	/** @var \OC_Defaults | PHPUnit_Framework_MockObject_MockObject */
	private $defaults;
	/** @var \OC\Setup | PHPUnit_Framework_MockObject_MockObject */
	protected $setupClass;

	protected function setUp() {
		parent::setUp();

		$this->config = $this->getMock('\OCP\IConfig');
		$this->iniWrapper = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper');
		$this->l10n = $this->getMock('\OCP\IL10N');
		$this->defaults = $this->getMock('\OC_Defaults');
		$this->setupClass = $this->getMock('\OC\Setup',
			['class_exists', 'is_callable'],
			[$this->config, $this->iniWrapper, $this->l10n, $this->defaults]);
	}

	public function testGetSupportedDatabasesWithOneWorking() {
		$this->config
			->expects($this->once())
			->method('getSystemValue')
			->will($this->returnValue(
				array('sqlite', 'mysql', 'oci')
			));
		$this->setupClass
			->expects($this->once())
			->method('class_exists')
			->will($this->returnValue(true));
		$this->setupClass
			->expects($this->exactly(2))
			->method('is_callable')
			->will($this->returnValue(false));
		$result = $this->setupClass->getSupportedDatabases();
		$expectedResult = array(
			'sqlite' => 'SQLite'
		);

		$this->assertSame($expectedResult, $result);
	}

	public function testGetSupportedDatabasesWithNoWorking() {
		$this->config
			->expects($this->once())
			->method('getSystemValue')
			->will($this->returnValue(
				array('sqlite', 'mysql', 'oci', 'pgsql')
			));
		$this->setupClass
			->expects($this->once())
			->method('class_exists')
			->will($this->returnValue(false));
		$this->setupClass
			->expects($this->exactly(3))
			->method('is_callable')
			->will($this->returnValue(false));
		$result = $this->setupClass->getSupportedDatabases();

		$this->assertSame(array(), $result);
	}

	public function testGetSupportedDatabasesWitAllWorking() {
		$this->config
			->expects($this->once())
			->method('getSystemValue')
			->will($this->returnValue(
				array('sqlite', 'mysql', 'pgsql', 'oci', 'mssql')
			));
		$this->setupClass
			->expects($this->once())
			->method('class_exists')
			->will($this->returnValue(true));
		$this->setupClass
			->expects($this->exactly(4))
			->method('is_callable')
			->will($this->returnValue(true));
		$result = $this->setupClass->getSupportedDatabases();
		$expectedResult = array(
			'sqlite' => 'SQLite',
			'mysql' => 'MySQL/MariaDB',
			'pgsql' => 'PostgreSQL',
			'oci' => 'Oracle',
			'mssql' => 'MS SQL'
		);
		$this->assertSame($expectedResult, $result);
	}

	/**
	 * @expectedException \Exception
	 * @expectedExceptionMessage Supported databases are not properly configured.
	 */
	public function testGetSupportedDatabaseException() {
		$this->config
			->expects($this->once())
			->method('getSystemValue')
			->will($this->returnValue('NotAnArray'));
		$this->setupClass->getSupportedDatabases();
	}

	/**
	 * This is actual more an integration test whether the version parameter in the .htaccess
	 * was updated as well when the version has been incremented.
	 * If it hasn't this test will fail.
	 */
	public function testHtaccessIsCurrent() {
		$result = Test_Helper::invokePrivate(
			$this->setupClass,
			'isCurrentHtaccess'
		);
		$this->assertTrue($result);
	}
}