summaryrefslogtreecommitdiffstats
path: root/tests/settings
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-03-26 14:51:33 +0100
committerLukas Reschke <lukas@owncloud.com>2015-03-28 13:59:22 +0100
commit65202d2a18aca3b253ce5f3c7c9af17ee6d12e52 (patch)
tree04453d95db5dc3df386188cd85032052fded6db9 /tests/settings
parentd3752ca1e925c3aed46c13f7ea26c8f540db05e0 (diff)
downloadnextcloud-server-65202d2a18aca3b253ce5f3c7c9af17ee6d12e52.tar.gz
nextcloud-server-65202d2a18aca3b253ce5f3c7c9af17ee6d12e52.zip
Add check for activated local memcache
Also used the opportunity to refactor it into an AppFramework controller so that we can unit test it. Fixes https://github.com/owncloud/core/issues/14956
Diffstat (limited to 'tests/settings')
-rw-r--r--tests/settings/controller/CheckSetupControllerTest.php231
1 files changed, 231 insertions, 0 deletions
diff --git a/tests/settings/controller/CheckSetupControllerTest.php b/tests/settings/controller/CheckSetupControllerTest.php
new file mode 100644
index 00000000000..fc17d2adc49
--- /dev/null
+++ b/tests/settings/controller/CheckSetupControllerTest.php
@@ -0,0 +1,231 @@
+<?php
+/**
+ * @author Lukas Reschke <lukas@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Settings\Controller;
+
+use OCP\AppFramework\Http\DataResponse;
+use Test\TestCase;
+use OCP\IRequest;
+use OCP\IConfig;
+use OCP\Http\Client\IClientService;
+use OC_Util;
+
+/**
+ * Class CheckSetupControllerTest
+ *
+ * @package OC\Settings\Controller
+ */
+class CheckSetupControllerTest extends TestCase {
+ /** @var CheckSetupController */
+ private $checkSetupController;
+ /** @var IRequest */
+ private $request;
+ /** @var IConfig */
+ private $config;
+ /** @var IClientService */
+ private $clientService;
+ /** @var OC_Util */
+ private $util;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->request = $this->getMockBuilder('\OCP\IRequest')
+ ->disableOriginalConstructor()->getMock();
+ $this->config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()->getMock();
+ $this->config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()->getMock();
+ $this->clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService')
+ ->disableOriginalConstructor()->getMock();
+ $this->util = $this->getMockBuilder('\OC_Util')
+ ->disableOriginalConstructor()->getMock();
+
+ $this->checkSetupController = new CheckSetupController(
+ 'settings',
+ $this->request,
+ $this->config,
+ $this->clientService,
+ $this->util
+ );
+ }
+
+ public function testIsInternetConnectionWorkingDisabledViaConfig() {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('has_internet_connection', true)
+ ->will($this->returnValue(false));
+
+ $this->assertFalse(
+ \Test_Helper::invokePrivate(
+ $this->checkSetupController,
+ 'isInternetConnectionWorking'
+ )
+ );
+ }
+
+ public function testIsInternetConnectionWorkingCorrectly() {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('has_internet_connection', true)
+ ->will($this->returnValue(true));
+
+ $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ ->disableOriginalConstructor()->getMock();
+ $client->expects($this->at(0))
+ ->method('get')
+ ->with('https://www.owncloud.org/', []);
+ $client->expects($this->at(1))
+ ->method('get')
+ ->with('http://www.owncloud.org/', []);
+
+ $this->clientService->expects($this->once())
+ ->method('newClient')
+ ->will($this->returnValue($client));
+
+
+ $this->assertTrue(
+ \Test_Helper::invokePrivate(
+ $this->checkSetupController,
+ 'isInternetConnectionWorking'
+ )
+ );
+ }
+
+ public function testIsInternetConnectionHttpsFail() {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('has_internet_connection', true)
+ ->will($this->returnValue(true));
+
+ $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ ->disableOriginalConstructor()->getMock();
+ $client->expects($this->at(0))
+ ->method('get')
+ ->with('https://www.owncloud.org/', [])
+ ->will($this->throwException(new \Exception()));
+
+ $this->clientService->expects($this->once())
+ ->method('newClient')
+ ->will($this->returnValue($client));
+
+ $this->assertFalse(
+ \Test_Helper::invokePrivate(
+ $this->checkSetupController,
+ 'isInternetConnectionWorking'
+ )
+ );
+ }
+
+ public function testIsInternetConnectionHttpFail() {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('has_internet_connection', true)
+ ->will($this->returnValue(true));
+
+ $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ ->disableOriginalConstructor()->getMock();
+ $client->expects($this->at(0))
+ ->method('get')
+ ->with('https://www.owncloud.org/', []);
+ $client->expects($this->at(1))
+ ->method('get')
+ ->with('http://www.owncloud.org/', [])
+ ->will($this->throwException(new \Exception()));
+
+ $this->clientService->expects($this->once())
+ ->method('newClient')
+ ->will($this->returnValue($client));
+
+ $this->assertFalse(
+ \Test_Helper::invokePrivate(
+ $this->checkSetupController,
+ 'isInternetConnectionWorking'
+ )
+ );
+ }
+
+ public function testIsMemcacheConfiguredFalse() {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('memcache.local', null)
+ ->will($this->returnValue(null));
+
+ $this->assertFalse(
+ \Test_Helper::invokePrivate(
+ $this->checkSetupController,
+ 'isMemcacheConfigured'
+ )
+ );
+ }
+
+ public function testIsMemcacheConfiguredTrue() {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('memcache.local', null)
+ ->will($this->returnValue('SomeProvider'));
+
+ $this->assertTrue(
+ \Test_Helper::invokePrivate(
+ $this->checkSetupController,
+ 'isMemcacheConfigured'
+ )
+ );
+ }
+
+ public function testCheck() {
+ $this->config->expects($this->at(0))
+ ->method('getSystemValue')
+ ->with('has_internet_connection', true)
+ ->will($this->returnValue(true));
+ $this->config->expects($this->at(1))
+ ->method('getSystemValue')
+ ->with('memcache.local', null)
+ ->will($this->returnValue('SomeProvider'));
+
+ $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ ->disableOriginalConstructor()->getMock();
+ $client->expects($this->at(0))
+ ->method('get')
+ ->with('https://www.owncloud.org/', []);
+ $client->expects($this->at(1))
+ ->method('get')
+ ->with('http://www.owncloud.org/', [])
+ ->will($this->throwException(new \Exception()));
+
+ $this->clientService->expects($this->once())
+ ->method('newClient')
+ ->will($this->returnValue($client));
+
+ $this->util->expects($this->once())
+ ->method('isHtaccessWorking')
+ ->will($this->returnValue(true));
+
+ $expected = new DataResponse(
+ [
+ 'serverHasInternetConnection' => false,
+ 'dataDirectoryProtected' => true,
+ 'isMemcacheConfigured' => true,
+ ]
+ );
+ $this->assertEquals($expected, $this->checkSetupController->check());
+ }
+}