diff options
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/AllConfigTest.php | 21 | ||||
-rw-r--r-- | tests/lib/App/AppManagerTest.php | 50 | ||||
-rw-r--r-- | tests/lib/AppTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Config/LexiconTest.php | 57 | ||||
-rw-r--r-- | tests/lib/Config/TestConfigLexicon_I.php | 5 | ||||
-rw-r--r-- | tests/lib/Config/UserConfigTest.php | 13 | ||||
-rw-r--r-- | tests/lib/DB/AdapterTest.php | 2 |
7 files changed, 117 insertions, 33 deletions
diff --git a/tests/lib/AllConfigTest.php b/tests/lib/AllConfigTest.php index ba48a078713..9d204754d96 100644 --- a/tests/lib/AllConfigTest.php +++ b/tests/lib/AllConfigTest.php @@ -93,6 +93,27 @@ class AllConfigTest extends \Test\TestCase { $config->deleteUserValue('userSet', 'appSet', 'keySet'); } + /** + * This test needs to stay! Emails are expected to be lowercase due to performance reasons. + * This way we can skip the expensive casing change on the database. + */ + public function testSetUserValueSettingsEmail(): void { + $selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?'; + $config = $this->getConfig(); + + $config->setUserValue('userSet', 'settings', 'email', 'mixed.CASE@domain.COM'); + + $result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAll(); + + $this->assertEquals(1, count($result)); + $this->assertEquals([ + 'userid' => 'userSet', + 'appid' => 'settings', + 'configkey' => 'email', + 'configvalue' => 'mixed.case@domain.com' + ], $result[0]); + } + public function testSetUserValueWithPreCondition(): void { $config = $this->getConfig(); diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index 3dd5073731c..5cd141c16a9 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -12,6 +12,7 @@ namespace Test\App; use OC\App\AppManager; use OC\AppConfig; +use OC\Config\ConfigManager; use OCP\App\AppPathNotFoundException; use OCP\App\Events\AppDisableEvent; use OCP\App\Events\AppEnableEvent; @@ -36,10 +37,7 @@ use Test\TestCase; * @package Test\App */ class AppManagerTest extends TestCase { - /** - * @return AppConfig|MockObject - */ - protected function getAppConfig() { + protected function getAppConfig(): AppConfig&MockObject { $appConfig = []; $config = $this->createMock(AppConfig::class); @@ -86,33 +84,17 @@ class AppManagerTest extends TestCase { return $config; } - /** @var IUserSession|MockObject */ - protected $userSession; - - /** @var IConfig|MockObject */ - private $config; - - /** @var IGroupManager|MockObject */ - protected $groupManager; - - /** @var AppConfig|MockObject */ - protected $appConfig; - - /** @var ICache|MockObject */ - protected $cache; - - /** @var ICacheFactory|MockObject */ - protected $cacheFactory; - - /** @var IEventDispatcher|MockObject */ - protected $eventDispatcher; - - /** @var LoggerInterface|MockObject */ - protected $logger; - + protected IUserSession&MockObject $userSession; + private IConfig&MockObject $config; + protected IGroupManager&MockObject $groupManager; + protected AppConfig&MockObject $appConfig; + protected ICache&MockObject $cache; + protected ICacheFactory&MockObject $cacheFactory; + protected IEventDispatcher&MockObject $eventDispatcher; + protected LoggerInterface&MockObject $logger; protected IURLGenerator&MockObject $urlGenerator; - protected ServerVersion&MockObject $serverVersion; + protected ConfigManager&MockObject $configManager; /** @var IAppManager */ protected $manager; @@ -130,6 +112,7 @@ class AppManagerTest extends TestCase { $this->logger = $this->createMock(LoggerInterface::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->serverVersion = $this->createMock(ServerVersion::class); + $this->configManager = $this->createMock(ConfigManager::class); $this->overwriteService(AppConfig::class, $this->appConfig); $this->overwriteService(IURLGenerator::class, $this->urlGenerator); @@ -152,6 +135,7 @@ class AppManagerTest extends TestCase { $this->eventDispatcher, $this->logger, $this->serverVersion, + $this->configManager, ); } @@ -295,6 +279,7 @@ class AppManagerTest extends TestCase { $this->eventDispatcher, $this->logger, $this->serverVersion, + $this->configManager, ]) ->onlyMethods([ 'getAppPath', @@ -349,6 +334,7 @@ class AppManagerTest extends TestCase { $this->eventDispatcher, $this->logger, $this->serverVersion, + $this->configManager, ]) ->onlyMethods([ 'getAppPath', @@ -411,6 +397,7 @@ class AppManagerTest extends TestCase { $this->eventDispatcher, $this->logger, $this->serverVersion, + $this->configManager, ]) ->onlyMethods([ 'getAppPath', @@ -616,6 +603,7 @@ class AppManagerTest extends TestCase { $this->eventDispatcher, $this->logger, $this->serverVersion, + $this->configManager, ]) ->onlyMethods(['getAppInfo']) ->getMock(); @@ -676,6 +664,7 @@ class AppManagerTest extends TestCase { $this->eventDispatcher, $this->logger, $this->serverVersion, + $this->configManager, ]) ->onlyMethods(['getAppInfo']) ->getMock(); @@ -817,6 +806,7 @@ class AppManagerTest extends TestCase { $this->eventDispatcher, $this->logger, $this->serverVersion, + $this->configManager, ]) ->onlyMethods([ 'getAppInfo', @@ -848,6 +838,7 @@ class AppManagerTest extends TestCase { $this->eventDispatcher, $this->logger, $this->serverVersion, + $this->configManager, ]) ->onlyMethods([ 'getAppInfo', @@ -878,6 +869,7 @@ class AppManagerTest extends TestCase { $this->eventDispatcher, $this->logger, $this->serverVersion, + $this->configManager, ]) ->onlyMethods([ 'getAppInfo', diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php index 4813ea8c839..07205c730ce 100644 --- a/tests/lib/AppTest.php +++ b/tests/lib/AppTest.php @@ -10,6 +10,7 @@ namespace Test; use OC\App\AppManager; use OC\App\InfoParser; use OC\AppConfig; +use OC\Config\ConfigManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\IAppConfig; use OCP\ICacheFactory; @@ -573,6 +574,7 @@ class AppTest extends \Test\TestCase { Server::get(IEventDispatcher::class), Server::get(LoggerInterface::class), Server::get(ServerVersion::class), + \OCP\Server::get(ConfigManager::class), )); } diff --git a/tests/lib/Config/LexiconTest.php b/tests/lib/Config/LexiconTest.php index e9b763b1799..530767a7416 100644 --- a/tests/lib/Config/LexiconTest.php +++ b/tests/lib/Config/LexiconTest.php @@ -10,7 +10,9 @@ namespace Tests\lib\Config; use NCU\Config\Exceptions\TypeConflictException; use NCU\Config\Exceptions\UnknownKeyException; use NCU\Config\IUserConfig; +use OC\AppConfig; use OC\AppFramework\Bootstrap\Coordinator; +use OC\Config\ConfigManager; use OCP\Exceptions\AppConfigTypeConflictException; use OCP\Exceptions\AppConfigUnknownKeyException; use OCP\IAppConfig; @@ -25,8 +27,10 @@ use Test\TestCase; * @package Test */ class LexiconTest extends TestCase { + /** @var AppConfig */ private IAppConfig $appConfig; private IUserConfig $userConfig; + private ConfigManager $configManager; protected function setUp(): void { parent::setUp(); @@ -39,6 +43,7 @@ class LexiconTest extends TestCase { $this->appConfig = Server::get(IAppConfig::class); $this->userConfig = Server::get(IUserConfig::class); + $this->configManager = Server::get(ConfigManager::class); } protected function tearDown(): void { @@ -141,11 +146,61 @@ class LexiconTest extends TestCase { public function testUserLexiconSetException() { $this->expectException(UnknownKeyException::class); $this->userConfig->setValueString('user1', TestConfigLexicon_E::APPID, 'key_exception', 'new_value'); - $this->assertSame('', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key3', '')); + $this->assertSame('', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key5', '')); } public function testUserLexiconGetException() { $this->expectException(UnknownKeyException::class); $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key_exception'); } + + public function testAppConfigLexiconRenameSetNewValue() { + $this->assertSame(12345, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'key3', 123)); + $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'old_key3', 994); + $this->assertSame(994, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'key3', 123)); + } + + public function testAppConfigLexiconRenameSetOldValuePreMigration() { + $this->appConfig->ignoreLexiconAliases(true); + $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'old_key3', 993); + $this->appConfig->ignoreLexiconAliases(false); + $this->assertSame(12345, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'key3', 123)); + } + + public function testAppConfigLexiconRenameSetOldValuePostMigration() { + $this->appConfig->ignoreLexiconAliases(true); + $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'old_key3', 994); + $this->appConfig->ignoreLexiconAliases(false); + $this->configManager->migrateConfigLexiconKeys(TestConfigLexicon_I::APPID); + $this->assertSame(994, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'key3', 123)); + } + + public function testAppConfigLexiconRenameGetNewValue() { + $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'key3', 981); + $this->assertSame(981, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'old_key3', 123)); + } + + public function testAppConfigLexiconRenameGetOldValuePreMigration() { + $this->appConfig->ignoreLexiconAliases(true); + $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'key3', 984); + $this->assertSame(123, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'old_key3', 123)); + $this->appConfig->ignoreLexiconAliases(false); + } + + public function testAppConfigLexiconRenameGetOldValuePostMigration() { + $this->appConfig->ignoreLexiconAliases(true); + $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'key3', 987); + $this->appConfig->ignoreLexiconAliases(false); + $this->configManager->migrateConfigLexiconKeys(TestConfigLexicon_I::APPID); + $this->assertSame(987, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'old_key3', 123)); + } + + public function testAppConfigLexiconRenameInvertBoolean() { + $this->appConfig->ignoreLexiconAliases(true); + $this->appConfig->setValueBool(TestConfigLexicon_I::APPID, 'old_key4', true); + $this->appConfig->ignoreLexiconAliases(false); + $this->assertSame(true, $this->appConfig->getValueBool(TestConfigLexicon_I::APPID, 'key4')); + $this->configManager->migrateConfigLexiconKeys(TestConfigLexicon_I::APPID); + $this->assertSame(false, $this->appConfig->getValueBool(TestConfigLexicon_I::APPID, 'key4')); + } } diff --git a/tests/lib/Config/TestConfigLexicon_I.php b/tests/lib/Config/TestConfigLexicon_I.php index 497c62acecb..6fb7921b6e6 100644 --- a/tests/lib/Config/TestConfigLexicon_I.php +++ b/tests/lib/Config/TestConfigLexicon_I.php @@ -25,8 +25,9 @@ class TestConfigLexicon_I implements IConfigLexicon { public function getAppConfigs(): array { return [ new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IAppConfig::FLAG_SENSITIVE), - new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false) - + new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false), + new ConfigLexiconEntry('key3', ValueType::INT, 12345, 'test key', true, rename: 'old_key3'), + new ConfigLexiconEntry('key4', ValueType::BOOL, 12345, 'test key', true, rename: 'old_key4', options: ConfigLexiconEntry::RENAME_INVERT_BOOLEAN), ]; } diff --git a/tests/lib/Config/UserConfigTest.php b/tests/lib/Config/UserConfigTest.php index 865575374d8..e27e831f425 100644 --- a/tests/lib/Config/UserConfigTest.php +++ b/tests/lib/Config/UserConfigTest.php @@ -1241,6 +1241,19 @@ class UserConfigTest extends TestCase { } } + /** + * This test needs to stay! Emails are expected to be lowercase due to performance reasons. + * This way we can skip the expensive casing change on the database. + */ + public function testSetValueMixedWithSettingsEmail(): void { + $userConfig = $this->generateUserConfig(); + + $edited = $userConfig->setValueMixed('user1', 'settings', 'email', 'mixed.CASE@Nextcloud.com'); + $this->assertTrue($edited); + + $actual = $userConfig->getValueMixed('user1', 'settings', 'email'); + $this->assertEquals('mixed.case@nextcloud.com', $actual); + } public static function providerSetValueString(): array { return [ diff --git a/tests/lib/DB/AdapterTest.php b/tests/lib/DB/AdapterTest.php index 2fc7c5089a3..bf95ad26a97 100644 --- a/tests/lib/DB/AdapterTest.php +++ b/tests/lib/DB/AdapterTest.php @@ -16,7 +16,7 @@ class AdapterTest extends TestCase { public function setUp(): void { $this->connection = Server::get(IDBConnection::class); - $this->appId = uniqid('test_db_adapter', true); + $this->appId = substr(uniqid('test_db_adapter', true), 0, 32); } public function tearDown(): void { |