Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-05-19 10:38:52 +0300
committerJoas Schilling <nickvergessen@owncloud.com>2016-05-19 10:38:52 +0300
commit9a4253ef7c34f9dc71a6a9f7828a10df769f0c32 (patch)
treefebe8415af243c7f69867d095a3f281c65071d40 /tests/lib/SetupTest.php
parent55fc6536d33bd044a72437ac61d3c5ade09111cb (diff)
Fix lib/
Diffstat (limited to 'tests/lib/SetupTest.php')
-rw-r--r--tests/lib/SetupTest.php135
1 files changed, 135 insertions, 0 deletions
diff --git a/tests/lib/SetupTest.php b/tests/lib/SetupTest.php
new file mode 100644
index 00000000000..e2723efd76a
--- /dev/null
+++ b/tests/lib/SetupTest.php
@@ -0,0 +1,135 @@
+<?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 OCP\IConfig;
+
+class SetupTest 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', 'getAvailableDbDriversForPdo'],
+ [$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->once())
+ ->method('is_callable')
+ ->will($this->returnValue(false));
+ $this->setupClass
+ ->expects($this->once())
+ ->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
+ ->expects($this->once())
+ ->method('class_exists')
+ ->will($this->returnValue(false));
+ $this->setupClass
+ ->expects($this->exactly(2))
+ ->method('is_callable')
+ ->will($this->returnValue(false));
+ $this->setupClass
+ ->expects($this->once())
+ ->method('getAvailableDbDriversForPdo')
+ ->will($this->returnValue([]));
+ $result = $this->setupClass->getSupportedDatabases();
+
+ $this->assertSame(array(), $result);
+ }
+
+ public function testGetSupportedDatabasesWithAllWorking() {
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValue')
+ ->will($this->returnValue(
+ array('sqlite', 'mysql', 'pgsql', '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(true));
+ $this->setupClass
+ ->expects($this->once())
+ ->method('getAvailableDbDriversForPdo')
+ ->will($this->returnValue(['mysql']));
+ $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('getSystemValue')
+ ->will($this->returnValue('NotAnArray'));
+ $this->setupClass->getSupportedDatabases();
+ }
+}