2014-10-27 14:51:26 +03: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.
|
|
|
|
*/
|
|
|
|
|
2016-05-19 10:38:52 +03:00
|
|
|
namespace Test;
|
|
|
|
|
2016-09-07 21:22:02 +03:00
|
|
|
use bantu\IniGetWrapper\IniGetWrapper;
|
2014-10-27 14:51:26 +03:00
|
|
|
use OCP\IConfig;
|
2016-09-07 21:22:02 +03:00
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\Security\ISecureRandom;
|
2014-10-27 14:51:26 +03:00
|
|
|
|
2016-05-19 10:38:52 +03:00
|
|
|
class SetupTest extends \Test\TestCase {
|
2014-10-27 14:51:26 +03:00
|
|
|
|
2016-05-19 10:38:52 +03:00
|
|
|
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
|
2014-10-27 14:51:26 +03:00
|
|
|
protected $config;
|
2016-05-19 10:38:52 +03:00
|
|
|
/** @var \bantu\IniGetWrapper\IniGetWrapper | \PHPUnit_Framework_MockObject_MockObject */
|
2015-03-11 01:44:29 +03:00
|
|
|
private $iniWrapper;
|
2016-05-19 10:38:52 +03:00
|
|
|
/** @var \OCP\IL10N | \PHPUnit_Framework_MockObject_MockObject */
|
2015-03-11 01:44:29 +03:00
|
|
|
private $l10n;
|
2016-05-19 10:38:52 +03:00
|
|
|
/** @var \OC_Defaults | \PHPUnit_Framework_MockObject_MockObject */
|
2015-03-11 01:44:29 +03:00
|
|
|
private $defaults;
|
2016-05-19 10:38:52 +03:00
|
|
|
/** @var \OC\Setup | \PHPUnit_Framework_MockObject_MockObject */
|
2014-10-27 14:51:26 +03:00
|
|
|
protected $setupClass;
|
2016-05-19 10:38:52 +03:00
|
|
|
/** @var \OCP\ILogger | \PHPUnit_Framework_MockObject_MockObject */
|
2015-07-30 10:02:35 +03:00
|
|
|
protected $logger;
|
2016-05-19 10:38:52 +03:00
|
|
|
/** @var \OCP\Security\ISecureRandom | \PHPUnit_Framework_MockObject_MockObject */
|
2015-07-30 10:02:35 +03:00
|
|
|
protected $random;
|
2014-10-27 14:51:26 +03:00
|
|
|
|
2014-11-11 00:59:50 +03:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2016-09-07 21:22:02 +03:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
$this->iniWrapper = $this->createMock(IniGetWrapper::class);
|
|
|
|
$this->l10n = $this->createMock(IL10N::class);
|
|
|
|
$this->defaults = $this->createMock(\OC_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();
|
2014-10-27 14:51:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSupportedDatabasesWithOneWorking() {
|
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
|
|
|
->will($this->returnValue(
|
|
|
|
array('sqlite', 'mysql', 'oci')
|
|
|
|
));
|
|
|
|
$this->setupClass
|
2015-07-30 13:32:22 +03:00
|
|
|
->expects($this->once())
|
2014-10-27 14:51:26 +03:00
|
|
|
->method('is_callable')
|
|
|
|
->will($this->returnValue(false));
|
2015-07-30 13:32:22 +03:00
|
|
|
$this->setupClass
|
2016-07-13 13:23:44 +03:00
|
|
|
->expects($this->any())
|
2015-07-30 13:32:22 +03:00
|
|
|
->method('getAvailableDbDriversForPdo')
|
2017-01-25 01:14:20 +03:00
|
|
|
->will($this->returnValue(['sqlite']));
|
2014-10-27 14:51:26 +03: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
|
2016-07-13 13:23:44 +03:00
|
|
|
->expects($this->any())
|
2014-10-27 14:51:26 +03:00
|
|
|
->method('is_callable')
|
|
|
|
->will($this->returnValue(false));
|
2015-07-30 13:32:22 +03:00
|
|
|
$this->setupClass
|
2016-07-13 13:23:44 +03:00
|
|
|
->expects($this->any())
|
2015-07-30 13:32:22 +03:00
|
|
|
->method('getAvailableDbDriversForPdo')
|
|
|
|
->will($this->returnValue([]));
|
2014-10-27 14:51:26 +03:00
|
|
|
$result = $this->setupClass->getSupportedDatabases();
|
|
|
|
|
|
|
|
$this->assertSame(array(), $result);
|
|
|
|
}
|
|
|
|
|
2015-07-29 21:14:28 +03:00
|
|
|
public function testGetSupportedDatabasesWithAllWorking() {
|
2014-10-27 14:51:26 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
|
|
|
->will($this->returnValue(
|
2015-07-29 19:19:31 +03:00
|
|
|
array('sqlite', 'mysql', 'pgsql', 'oci')
|
2014-10-27 14:51:26 +03:00
|
|
|
));
|
|
|
|
$this->setupClass
|
2016-07-13 13:23:44 +03:00
|
|
|
->expects($this->any())
|
2014-10-27 14:51:26 +03:00
|
|
|
->method('is_callable')
|
|
|
|
->will($this->returnValue(true));
|
2015-07-30 13:32:22 +03:00
|
|
|
$this->setupClass
|
2016-07-13 13:23:44 +03:00
|
|
|
->expects($this->any())
|
2015-07-30 13:32:22 +03:00
|
|
|
->method('getAvailableDbDriversForPdo')
|
2017-01-25 01:14:20 +03:00
|
|
|
->will($this->returnValue(['sqlite', 'mysql', 'pgsql']));
|
2014-10-27 14:51:26 +03:00
|
|
|
$result = $this->setupClass->getSupportedDatabases();
|
|
|
|
$expectedResult = array(
|
|
|
|
'sqlite' => 'SQLite',
|
|
|
|
'mysql' => 'MySQL/MariaDB',
|
|
|
|
'pgsql' => 'PostgreSQL',
|
2015-07-29 19:19:31 +03:00
|
|
|
'oci' => 'Oracle'
|
2014-10-27 14:51:26 +03: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 22:51:50 +03:00
|
|
|
}
|