From 9bfc108b79f793ed5dd6812d1ca193a38ba02231 Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Tue, 17 Apr 2018 20:03:26 +0200 Subject: Cleanup and fix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Settings/Admin/Overview.php | 5 -- lib/private/Settings/Admin/Server.php | 56 ------------ tests/lib/Settings/Admin/AdditionalTest.php | 127 --------------------------- tests/lib/Settings/Admin/MailTest.php | 128 ++++++++++++++++++++++++++++ tests/lib/Settings/ManagerTest.php | 30 ++++--- 5 files changed, 144 insertions(+), 202 deletions(-) delete mode 100644 tests/lib/Settings/Admin/AdditionalTest.php create mode 100644 tests/lib/Settings/Admin/MailTest.php diff --git a/lib/private/Settings/Admin/Overview.php b/lib/private/Settings/Admin/Overview.php index 7d0cf107539..6e186dc6f98 100644 --- a/lib/private/Settings/Admin/Overview.php +++ b/lib/private/Settings/Admin/Overview.php @@ -127,13 +127,8 @@ class Overview implements ISettings { 'OutdatedCacheWarning' => $outdatedCaches, 'fileLockingType' => $fileLockingType, 'suggestedOverwriteCliUrl' => $suggestedOverwriteCliUrl, - - // Background jobs - 'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'), 'lastcron' => $this->config->getAppValue('core', 'lastcron', false), 'cronErrors' => $this->config->getAppValue('core', 'cronErrors'), - 'cli_based_cron_possible' => function_exists('posix_getpwuid'), - 'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '', ]; return new TemplateResponse('settings', 'settings/admin/overview', $parameters, ''); diff --git a/lib/private/Settings/Admin/Server.php b/lib/private/Settings/Admin/Server.php index 0b9c042e4f2..1ebea8a4dcd 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -74,63 +74,7 @@ class Server implements ISettings { * @return TemplateResponse */ public function getForm() { - try { - if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) { - $invalidTransactionIsolationLevel = false; - } else { - $invalidTransactionIsolationLevel = $this->db->getTransactionIsolation() !== Connection::TRANSACTION_READ_COMMITTED; - } - } catch (DBALException $e) { - // ignore - $invalidTransactionIsolationLevel = false; - } - - $envPath = getenv('PATH'); - - // warn if outdated version of a memcache module is used - $caches = [ - 'apcu' => ['name' => $this->l->t('APCu'), 'version' => '4.0.6'], - 'redis' => ['name' => $this->l->t('Redis'), 'version' => '2.2.5'], - ]; - $outdatedCaches = []; - foreach ($caches as $php_module => $data) { - $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<'); - if ($isOutdated) { - $outdatedCaches[$php_module] = $data; - } - } - - if ($this->lockingProvider instanceof NoopLockingProvider) { - $fileLockingType = 'none'; - } else if ($this->lockingProvider instanceof DBLockingProvider) { - $fileLockingType = 'db'; - } else { - $fileLockingType = 'cache'; - } - - $suggestedOverwriteCliUrl = ''; - if ($this->config->getSystemValue('overwrite.cli.url', '') === '') { - $suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT; - if (!$this->config->getSystemValue('config_is_read_only', false)) { - // Set the overwrite URL when it was not set yet. - $this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl); - $suggestedOverwriteCliUrl = ''; - } - } - $parameters = [ - // Diagnosis - 'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(), - 'isLocaleWorking' => \OC_Util::isSetLocaleWorking(), - 'isAnnotationsWorking' => \OC_Util::isAnnotationsWorking(), - 'checkForWorkingWellKnownSetup' => $this->config->getSystemValue('check_for_working_wellknown_setup', true), - 'has_fileinfo' => \OC_Util::fileInfoLoaded(), - 'invalidTransactionIsolationLevel' => $invalidTransactionIsolationLevel, - 'getenvServerNotWorking' => empty($envPath), - 'OutdatedCacheWarning' => $outdatedCaches, - 'fileLockingType' => $fileLockingType, - 'suggestedOverwriteCliUrl' => $suggestedOverwriteCliUrl, - // Background jobs 'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'), 'lastcron' => $this->config->getAppValue('core', 'lastcron', false), diff --git a/tests/lib/Settings/Admin/AdditionalTest.php b/tests/lib/Settings/Admin/AdditionalTest.php deleted file mode 100644 index 4a254da060b..00000000000 --- a/tests/lib/Settings/Admin/AdditionalTest.php +++ /dev/null @@ -1,127 +0,0 @@ - - * - * @author Lukas Reschke - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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 - * along with this program. If not, see . - * - */ - -namespace Test\Settings\Admin; - -use OC\Settings\Admin\Additional; -use OCP\AppFramework\Http\TemplateResponse; -use OCP\IConfig; -use Test\TestCase; - -class AdditionalTest extends TestCase { - /** @var Additional */ - private $admin; - /** @var IConfig */ - private $config; - - public function setUp() { - parent::setUp(); - $this->config = $this->getMockBuilder(IConfig::class)->getMock(); - - $this->admin = new Additional( - $this->config - ); - } - - public function testGetForm() { - $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('mail_domain', '') - ->willReturn('mx.nextcloud.com'); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('mail_from_address', '') - ->willReturn('no-reply@nextcloud.com'); - $this->config - ->expects($this->at(2)) - ->method('getSystemValue') - ->with('mail_smtpmode', '') - ->willReturn('php'); - $this->config - ->expects($this->at(3)) - ->method('getSystemValue') - ->with('mail_smtpsecure', '') - ->willReturn(true); - $this->config - ->expects($this->at(4)) - ->method('getSystemValue') - ->with('mail_smtphost', '') - ->willReturn('smtp.nextcloud.com'); - $this->config - ->expects($this->at(5)) - ->method('getSystemValue') - ->with('mail_smtpport', '') - ->willReturn(25); - $this->config - ->expects($this->at(6)) - ->method('getSystemValue') - ->with('mail_smtpauthtype', '') - ->willReturn('login'); - $this->config - ->expects($this->at(7)) - ->method('getSystemValue') - ->with('mail_smtpauth', false) - ->willReturn(true); - $this->config - ->expects($this->at(8)) - ->method('getSystemValue') - ->with('mail_smtpname', '') - ->willReturn('smtp.sender.com'); - $this->config - ->expects($this->at(9)) - ->method('getSystemValue') - ->with('mail_smtppassword', '') - ->willReturn('mypassword'); - - $expected = new TemplateResponse( - 'settings', - 'settings/admin/additional-mail', - [ - 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'), - 'mail_domain' => 'mx.nextcloud.com', - 'mail_from_address' => 'no-reply@nextcloud.com', - 'mail_smtpmode' => 'php', - 'mail_smtpsecure' => true, - 'mail_smtphost' => 'smtp.nextcloud.com', - 'mail_smtpport' => 25, - 'mail_smtpauthtype' => 'login', - 'mail_smtpauth' => true, - 'mail_smtpname' => 'smtp.sender.com', - 'mail_smtppassword' => '********', - ], - '' - ); - - $this->assertEquals($expected, $this->admin->getForm()); - } - - public function testGetSection() { - $this->assertSame('additional', $this->admin->getSection()); - } - - public function testGetPriority() { - $this->assertSame(0, $this->admin->getPriority()); - } -} diff --git a/tests/lib/Settings/Admin/MailTest.php b/tests/lib/Settings/Admin/MailTest.php new file mode 100644 index 00000000000..445aa942059 --- /dev/null +++ b/tests/lib/Settings/Admin/MailTest.php @@ -0,0 +1,128 @@ + + * + * @author Lukas Reschke + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see . + * + */ + +namespace Test\Settings\Admin; + +use OC\Settings\Admin\Additional; +use OC\Settings\Admin\Mail; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use Test\TestCase; + +class MailTest extends TestCase { + /** @var Additional */ + private $admin; + /** @var IConfig */ + private $config; + + public function setUp() { + parent::setUp(); + $this->config = $this->getMockBuilder(IConfig::class)->getMock(); + + $this->admin = new Mail( + $this->config + ); + } + + public function testGetForm() { + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('mail_domain', '') + ->willReturn('mx.nextcloud.com'); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('mail_from_address', '') + ->willReturn('no-reply@nextcloud.com'); + $this->config + ->expects($this->at(2)) + ->method('getSystemValue') + ->with('mail_smtpmode', '') + ->willReturn('php'); + $this->config + ->expects($this->at(3)) + ->method('getSystemValue') + ->with('mail_smtpsecure', '') + ->willReturn(true); + $this->config + ->expects($this->at(4)) + ->method('getSystemValue') + ->with('mail_smtphost', '') + ->willReturn('smtp.nextcloud.com'); + $this->config + ->expects($this->at(5)) + ->method('getSystemValue') + ->with('mail_smtpport', '') + ->willReturn(25); + $this->config + ->expects($this->at(6)) + ->method('getSystemValue') + ->with('mail_smtpauthtype', '') + ->willReturn('login'); + $this->config + ->expects($this->at(7)) + ->method('getSystemValue') + ->with('mail_smtpauth', false) + ->willReturn(true); + $this->config + ->expects($this->at(8)) + ->method('getSystemValue') + ->with('mail_smtpname', '') + ->willReturn('smtp.sender.com'); + $this->config + ->expects($this->at(9)) + ->method('getSystemValue') + ->with('mail_smtppassword', '') + ->willReturn('mypassword'); + + $expected = new TemplateResponse( + 'settings', + 'settings/admin/additional-mail', + [ + 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'), + 'mail_domain' => 'mx.nextcloud.com', + 'mail_from_address' => 'no-reply@nextcloud.com', + 'mail_smtpmode' => 'php', + 'mail_smtpsecure' => true, + 'mail_smtphost' => 'smtp.nextcloud.com', + 'mail_smtpport' => 25, + 'mail_smtpauthtype' => 'login', + 'mail_smtpauth' => true, + 'mail_smtpname' => 'smtp.sender.com', + 'mail_smtppassword' => '********', + ], + '' + ); + + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('additional', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(0, $this->admin->getPriority()); + } +} diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index b218a347e85..d51a57598b3 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -115,24 +115,25 @@ class ManagerTest extends TestCase { $this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class); - $this->url->expects($this->exactly(6)) + $this->url->expects($this->exactly(7)) ->method('imagePath') ->willReturnMap([ - ['settings', 'admin.svg', '1'], + ['settings', 'admin.svg', '0'], + ['core', 'actions/settings-dark.svg', '1'], ['core', 'actions/share.svg', '2'], ['core', 'actions/password.svg', '3'], - ['core', 'actions/settings-dark.svg', '4'], - ['settings', 'help.svg', '5'], + ['settings', 'help.svg', '4'], ]); $this->assertEquals([ - 0 => [new Section('server', 'Basic settings', 0, '1')], + 0 => [new Section('overview', 'Overview', 0, '0')], + 1 => [new Section('server', 'Basic settings', 0, '1')], 5 => [new Section('sharing', 'Sharing', 0, '2')], 10 => [new Section('security', 'Security', 0, '3')], 45 => [new Section('encryption', 'Encryption', 0, '3')], 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], - 98 => [new Section('additional', 'Additional settings', 0, '4')], - 99 => [new Section('tips-tricks', 'Tips & tricks', 0, '5')], + 98 => [new Section('additional', 'Additional settings', 0, '1')], + 99 => [new Section('tips-tricks', 'Tips & tricks', 0, '4')], ], $this->manager->getAdminSections()); } @@ -166,23 +167,24 @@ class ManagerTest extends TestCase { ->method('t') ->will($this->returnArgument(0)); - $this->url->expects($this->exactly(6)) + $this->url->expects($this->exactly(7)) ->method('imagePath') ->willReturnMap([ - ['settings', 'admin.svg', '1'], + ['settings', 'admin.svg', '0'], + ['core', 'actions/settings-dark.svg', '1'], ['core', 'actions/share.svg', '2'], ['core', 'actions/password.svg', '3'], - ['core', 'actions/settings-dark.svg', '4'], - ['settings', 'help.svg', '5'], + ['settings', 'help.svg', '4'], ]); $this->assertEquals([ - 0 => [new Section('server', 'Basic settings', 0, '1')], + 0 => [new Section('overview', 'Overview', 0, '0')], + 1 => [new Section('server', 'Basic settings', 0, '1')], 5 => [new Section('sharing', 'Sharing', 0, '2')], 10 => [new Section('security', 'Security', 0, '3')], 45 => [new Section('encryption', 'Encryption', 0, '3')], - 98 => [new Section('additional', 'Additional settings', 0, '4')], - 99 => [new Section('tips-tricks', 'Tips & tricks', 0, '5')], + 98 => [new Section('additional', 'Additional settings', 0, '1')], + 99 => [new Section('tips-tricks', 'Tips & tricks', 0, '4')], ], $this->manager->getAdminSections()); } -- cgit v1.2.3