5b4adf66e5
* currently there are two ways to access default values: OCP\Defaults or OC_Defaults (which is extended by OCA\Theming\ThemingDefaults) * our code used a mixture of both of them, which made it hard to work on theme values * this extended the public interface with the missing methods and uses them everywhere to only rely on the public interface Signed-off-by: Morris Jobke <hey@morrisjobke.de>
129 lines
3.8 KiB
PHP
129 lines
3.8 KiB
PHP
<?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.
|
|
*/
|
|
|
|
namespace Test;
|
|
|
|
use bantu\IniGetWrapper\IniGetWrapper;
|
|
use OC\SystemConfig;
|
|
use OCP\Defaults;
|
|
use OCP\IL10N;
|
|
use OCP\ILogger;
|
|
use OCP\Security\ISecureRandom;
|
|
|
|
class SetupTest extends \Test\TestCase {
|
|
|
|
/** @var SystemConfig|\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 Defaults|\PHPUnit_Framework_MockObject_MockObject */
|
|
private $defaults;
|
|
/** @var \OC\Setup|\PHPUnit_Framework_MockObject_MockObject */
|
|
protected $setupClass;
|
|
/** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
|
protected $logger;
|
|
/** @var \OCP\Security\ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */
|
|
protected $random;
|
|
|
|
protected function setUp() {
|
|
parent::setUp();
|
|
|
|
$this->config = $this->createMock(SystemConfig::class);
|
|
$this->iniWrapper = $this->createMock(IniGetWrapper::class);
|
|
$this->l10n = $this->createMock(IL10N::class);
|
|
$this->defaults = $this->createMock(Defaults::class);
|
|
$this->logger = $this->createMock(ILogger::class);
|
|
$this->random = $this->createMock(ISecureRandom::class);
|
|
$this->setupClass = $this->getMockBuilder('\OC\Setup')
|
|
->setMethods(['class_exists', 'is_callable', 'getAvailableDbDriversForPdo'])
|
|
->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random])
|
|
->getMock();
|
|
}
|
|
|
|
public function testGetSupportedDatabasesWithOneWorking() {
|
|
$this->config
|
|
->expects($this->once())
|
|
->method('getValue')
|
|
->will($this->returnValue(
|
|
array('sqlite', 'mysql', 'oci')
|
|
));
|
|
$this->setupClass
|
|
->expects($this->once())
|
|
->method('is_callable')
|
|
->will($this->returnValue(false));
|
|
$this->setupClass
|
|
->expects($this->any())
|
|
->method('getAvailableDbDriversForPdo')
|
|
->will($this->returnValue(['sqlite']));
|
|
$result = $this->setupClass->getSupportedDatabases();
|
|
$expectedResult = array(
|
|
'sqlite' => 'SQLite'
|
|
);
|
|
|
|
$this->assertSame($expectedResult, $result);
|
|
}
|
|
|
|
public function testGetSupportedDatabasesWithNoWorking() {
|
|
$this->config
|
|
->expects($this->once())
|
|
->method('getValue')
|
|
->will($this->returnValue(
|
|
array('sqlite', 'mysql', 'oci', 'pgsql')
|
|
));
|
|
$this->setupClass
|
|
->expects($this->any())
|
|
->method('is_callable')
|
|
->will($this->returnValue(false));
|
|
$this->setupClass
|
|
->expects($this->any())
|
|
->method('getAvailableDbDriversForPdo')
|
|
->will($this->returnValue([]));
|
|
$result = $this->setupClass->getSupportedDatabases();
|
|
|
|
$this->assertSame(array(), $result);
|
|
}
|
|
|
|
public function testGetSupportedDatabasesWithAllWorking() {
|
|
$this->config
|
|
->expects($this->once())
|
|
->method('getValue')
|
|
->will($this->returnValue(
|
|
array('sqlite', 'mysql', 'pgsql', 'oci')
|
|
));
|
|
$this->setupClass
|
|
->expects($this->any())
|
|
->method('is_callable')
|
|
->will($this->returnValue(true));
|
|
$this->setupClass
|
|
->expects($this->any())
|
|
->method('getAvailableDbDriversForPdo')
|
|
->will($this->returnValue(['sqlite', 'mysql', 'pgsql']));
|
|
$result = $this->setupClass->getSupportedDatabases();
|
|
$expectedResult = array(
|
|
'sqlite' => 'SQLite',
|
|
'mysql' => 'MySQL/MariaDB',
|
|
'pgsql' => 'PostgreSQL',
|
|
'oci' => 'Oracle'
|
|
);
|
|
$this->assertSame($expectedResult, $result);
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Exception
|
|
* @expectedExceptionMessage Supported databases are not properly configured.
|
|
*/
|
|
public function testGetSupportedDatabaseException() {
|
|
$this->config
|
|
->expects($this->once())
|
|
->method('getValue')
|
|
->will($this->returnValue('NotAnArray'));
|
|
$this->setupClass->getSupportedDatabases();
|
|
}
|
|
}
|