server/tests/lib/SetupTest.php

141 lines
4.2 KiB
PHP
Raw Normal View History

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