nextcloud/tests/lib/setup.php

135 lines
3.9 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.
*/
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;
/** @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->getMock('\OCP\IConfig');
$this->iniWrapper = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper');
$this->l10n = $this->getMock('\OCP\IL10N');
$this->defaults = $this->getMock('\OC_Defaults');
$this->logger = $this->getMock('\OCP\ILogger');
$this->random = $this->getMock('\OCP\Security\ISecureRandom');
$this->setupClass = $this->getMock('\OC\Setup',
['class_exists', 'is_callable'],
[$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random]);
}
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);
}
2015-07-29 21:14:28 +03:00
public function testGetSupportedDatabasesWithAllWorking() {
$this->config
->expects($this->once())
->method('getSystemValue')
->will($this->returnValue(
2015-07-29 19:19:31 +03:00
array('sqlite', 'mysql', 'pgsql', 'oci')
));
$this->setupClass
->expects($this->once())
->method('class_exists')
->will($this->returnValue(true));
$this->setupClass
2015-07-29 21:14:28 +03:00
->expects($this->exactly(3))
->method('is_callable')
->will($this->returnValue(true));
$result = $this->setupClass->getSupportedDatabases();
$expectedResult = array(
'sqlite' => 'SQLite',
'mysql' => 'MySQL/MariaDB',
'pgsql' => 'PostgreSQL',
2015-07-29 19:19:31 +03: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();
}
/**
* 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 = self::invokePrivate(
$this->setupClass,
'isCurrentHtaccess'
);
$this->assertTrue($result);
}
2015-02-21 22:51:50 +03:00
}