2014-10-27 11:51:26 +00:00
|
|
|
<?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;
|
|
|
|
|
2014-11-10 21:59:50 +00:00
|
|
|
class Test_OC_Setup extends \Test\TestCase {
|
2014-10-27 11:51:26 +00:00
|
|
|
|
2015-03-10 22:44:29 +00:00
|
|
|
/** @var IConfig | PHPUnit_Framework_MockObject_MockObject */
|
2014-10-27 11:51:26 +00:00
|
|
|
protected $config;
|
2015-03-10 22:44:29 +00:00
|
|
|
/** @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 */
|
2014-10-27 11:51:26 +00:00
|
|
|
protected $setupClass;
|
2015-07-30 07:02:35 +00:00
|
|
|
/** @var \OCP\ILogger | PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $logger;
|
|
|
|
/** @var \OCP\Security\ISecureRandom | PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $random;
|
2014-10-27 11:51:26 +00:00
|
|
|
|
2014-11-10 21:59:50 +00:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2014-10-27 11:51:26 +00:00
|
|
|
$this->config = $this->getMock('\OCP\IConfig');
|
2015-03-10 22:44:29 +00:00
|
|
|
$this->iniWrapper = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper');
|
|
|
|
$this->l10n = $this->getMock('\OCP\IL10N');
|
|
|
|
$this->defaults = $this->getMock('\OC_Defaults');
|
2015-07-30 07:02:35 +00:00
|
|
|
$this->logger = $this->getMock('\OCP\ILogger');
|
|
|
|
$this->random = $this->getMock('\OCP\Security\ISecureRandom');
|
2015-03-10 22:44:29 +00:00
|
|
|
$this->setupClass = $this->getMock('\OC\Setup',
|
2015-07-30 10:32:22 +00:00
|
|
|
['class_exists', 'is_callable', 'getAvailableDbDriversForPdo'],
|
2015-07-30 07:02:35 +00:00
|
|
|
[$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random]);
|
2014-10-27 11:51:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2015-07-30 10:32:22 +00:00
|
|
|
->expects($this->once())
|
2014-10-27 11:51:26 +00:00
|
|
|
->method('is_callable')
|
|
|
|
->will($this->returnValue(false));
|
2015-07-30 10:32:22 +00:00
|
|
|
$this->setupClass
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getAvailableDbDriversForPdo')
|
|
|
|
->will($this->returnValue([]));
|
2014-10-27 11:51:26 +00:00
|
|
|
$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
|
2015-07-30 10:32:22 +00:00
|
|
|
->expects($this->exactly(2))
|
2014-10-27 11:51:26 +00:00
|
|
|
->method('is_callable')
|
|
|
|
->will($this->returnValue(false));
|
2015-07-30 10:32:22 +00:00
|
|
|
$this->setupClass
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getAvailableDbDriversForPdo')
|
|
|
|
->will($this->returnValue([]));
|
2014-10-27 11:51:26 +00:00
|
|
|
$result = $this->setupClass->getSupportedDatabases();
|
|
|
|
|
|
|
|
$this->assertSame(array(), $result);
|
|
|
|
}
|
|
|
|
|
2015-07-29 18:14:28 +00:00
|
|
|
public function testGetSupportedDatabasesWithAllWorking() {
|
2014-10-27 11:51:26 +00:00
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
|
|
|
->will($this->returnValue(
|
2015-07-29 16:19:31 +00:00
|
|
|
array('sqlite', 'mysql', 'pgsql', 'oci')
|
2014-10-27 11:51:26 +00:00
|
|
|
));
|
|
|
|
$this->setupClass
|
|
|
|
->expects($this->once())
|
|
|
|
->method('class_exists')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
$this->setupClass
|
2015-07-30 10:32:22 +00:00
|
|
|
->expects($this->exactly(2))
|
2014-10-27 11:51:26 +00:00
|
|
|
->method('is_callable')
|
|
|
|
->will($this->returnValue(true));
|
2015-07-30 10:32:22 +00:00
|
|
|
$this->setupClass
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getAvailableDbDriversForPdo')
|
|
|
|
->will($this->returnValue(['mysql']));
|
2014-10-27 11:51:26 +00:00
|
|
|
$result = $this->setupClass->getSupportedDatabases();
|
|
|
|
$expectedResult = array(
|
|
|
|
'sqlite' => 'SQLite',
|
|
|
|
'mysql' => 'MySQL/MariaDB',
|
|
|
|
'pgsql' => 'PostgreSQL',
|
2015-07-29 16:19:31 +00:00
|
|
|
'oci' => 'Oracle'
|
2014-10-27 11:51:26 +00:00
|
|
|
);
|
|
|
|
$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();
|
|
|
|
}
|
2015-02-21 19:51:50 +00:00
|
|
|
}
|