123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836 |
- <?php
- declare(strict_types=1);
- /**
- * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-only
- */
- namespace Test\lib\Config;
- use NCU\Config\Exceptions\TypeConflictException;
- use NCU\Config\Exceptions\UnknownKeyException;
- use NCU\Config\IUserConfig;
- use NCU\Config\ValueType;
- use OC\Config\UserConfig;
- use OCP\IDBConnection;
- use OCP\Security\ICrypto;
- use Psr\Log\LoggerInterface;
- use Test\TestCase;
- /**
- * Class UserPreferencesTest
- *
- * @group DB
- *
- * @package Test
- */
- class UserConfigTest extends TestCase {
- protected IDBConnection $connection;
- private LoggerInterface $logger;
- private ICrypto $crypto;
- private array $originalPreferences;
- /**
- * @var array<string, array<string, array<array<string, string, int, bool, bool>>> [userId => [appId => prefKey, prefValue, valueType, lazy, sensitive]]]
- */
- private array $basePreferences =
- [
- 'user1' =>
- [
- 'app1' => [
- 'key1' => ['key1', 'value1'],
- 'key22' => ['key22', '31'],
- 'fast_string' => ['fast_string', 'f_value', ValueType::STRING],
- 'lazy_string' => ['lazy_string', 'l_value', ValueType::STRING, true],
- 'fast_string_sensitive' => [
- 'fast_string_sensitive', 'fs_value', ValueType::STRING, false, UserConfig::FLAG_SENSITIVE
- ],
- 'lazy_string_sensitive' => [
- 'lazy_string_sensitive', 'ls_value', ValueType::STRING, true, UserConfig::FLAG_SENSITIVE
- ],
- 'fast_int' => ['fast_int', 11, ValueType::INT],
- 'lazy_int' => ['lazy_int', 12, ValueType::INT, true],
- 'fast_int_sensitive' => ['fast_int_sensitive', 2024, ValueType::INT, false, UserConfig::FLAG_SENSITIVE],
- 'lazy_int_sensitive' => ['lazy_int_sensitive', 2048, ValueType::INT, true, UserConfig::FLAG_SENSITIVE],
- 'fast_float' => ['fast_float', 3.14, ValueType::FLOAT],
- 'lazy_float' => ['lazy_float', 3.14159, ValueType::FLOAT, true],
- 'fast_float_sensitive' => [
- 'fast_float_sensitive', 1.41, ValueType::FLOAT, false, UserConfig::FLAG_SENSITIVE
- ],
- 'lazy_float_sensitive' => [
- 'lazy_float_sensitive', 1.4142, ValueType::FLOAT, true, UserConfig::FLAG_SENSITIVE
- ],
- 'fast_array' => ['fast_array', ['year' => 2024], ValueType::ARRAY],
- 'lazy_array' => ['lazy_array', ['month' => 'October'], ValueType::ARRAY, true],
- 'fast_array_sensitive' => [
- 'fast_array_sensitive', ['password' => 'pwd'], ValueType::ARRAY, false, UserConfig::FLAG_SENSITIVE
- ],
- 'lazy_array_sensitive' => [
- 'lazy_array_sensitive', ['password' => 'qwerty'], ValueType::ARRAY, true, UserConfig::FLAG_SENSITIVE
- ],
- 'fast_boolean' => ['fast_boolean', true, ValueType::BOOL],
- 'fast_boolean_0' => ['fast_boolean_0', false, ValueType::BOOL],
- 'lazy_boolean' => ['lazy_boolean', true, ValueType::BOOL, true],
- 'lazy_boolean_0' => ['lazy_boolean_0', false, ValueType::BOOL, true],
- ],
- 'app2' => [
- 'key2' => ['key2', 'value2a', ValueType::STRING, false, 0, true],
- 'key3' => ['key3', 'value3', ValueType::STRING, true],
- 'key4' => ['key4', 'value4', ValueType::STRING, false, UserConfig::FLAG_SENSITIVE],
- 'key8' => ['key8', 11, ValueType::INT, false, 0, true],
- 'key9' => ['key9', 'value9a', ValueType::STRING],
- ],
- 'app3' => [
- 'key1' => ['key1', 'value123'],
- 'key3' => ['key3', 'value3'],
- 'key8' => ['key8', 12, ValueType::INT, false, UserConfig::FLAG_SENSITIVE, true],
- 'key9' => ['key9', 'value9b', ValueType::STRING, false, UserConfig::FLAG_SENSITIVE],
- 'key10' => ['key10', true, ValueType::BOOL, false, 0, true],
- ],
- 'only-lazy' => [
- 'key1' => ['key1', 'value456', ValueType::STRING, true, 0, true],
- 'key2' => ['key2', 'value2c', ValueType::STRING, true, UserConfig::FLAG_SENSITIVE],
- 'key3' => ['key3', 42, ValueType::INT, true],
- 'key4' => ['key4', 17.42, ValueType::FLOAT, true],
- 'key5' => ['key5', true, ValueType::BOOL, true],
- ]
- ],
- 'user2' =>
- [
- 'app1' => [
- '1' => ['1', 'value1'],
- '2' => ['2', 'value2', ValueType::STRING, true, UserConfig::FLAG_SENSITIVE],
- '3' => ['3', 17, ValueType::INT, true],
- '4' => ['4', 42, ValueType::INT, false, UserConfig::FLAG_SENSITIVE],
- '5' => ['5', 17.42, ValueType::FLOAT, false],
- '6' => ['6', true, ValueType::BOOL, false],
- ],
- 'app2' => [
- 'key2' => ['key2', 'value2b', ValueType::STRING, false, 0, true],
- 'key3' => ['key3', 'value3', ValueType::STRING, true],
- 'key4' => ['key4', 'value4', ValueType::STRING, false, UserConfig::FLAG_SENSITIVE],
- 'key8' => ['key8', 12, ValueType::INT, false, 0, true],
- ],
- 'app3' => [
- 'key10' => ['key10', false, ValueType::BOOL, false, 0, true],
- ],
- 'only-lazy' => [
- 'key1' => ['key1', 'value1', ValueType::STRING, true, 0, true]
- ]
- ],
- 'user3' =>
- [
- 'app2' => [
- 'key2' => ['key2', 'value2c', ValueType::MIXED, false, 0, true],
- 'key3' => ['key3', 'value3', ValueType::STRING, true, ],
- 'key4' => ['key4', 'value4', ValueType::STRING, false, UserConfig::FLAG_SENSITIVE],
- 'fast_string_sensitive' => [
- 'fast_string_sensitive', 'fs_value', ValueType::STRING, false, UserConfig::FLAG_SENSITIVE
- ],
- 'lazy_string_sensitive' => [
- 'lazy_string_sensitive', 'ls_value', ValueType::STRING, true, UserConfig::FLAG_SENSITIVE
- ],
- ],
- 'only-lazy' => [
- 'key3' => ['key3', 'value3', ValueType::STRING, true]
- ]
- ],
- 'user4' =>
- [
- 'app2' => [
- 'key1' => ['key1', 'value1'],
- 'key2' => ['key2', 'value2A', ValueType::MIXED, false, 0, true],
- 'key3' => ['key3', 'value3', ValueType::STRING, true,],
- 'key4' => ['key4', 'value4', ValueType::STRING, false, UserConfig::FLAG_SENSITIVE],
- ],
- 'app3' => [
- 'key10' => ['key10', true, ValueType::BOOL, false, 0, true],
- ],
- 'only-lazy' => [
- 'key1' => ['key1', 123, ValueType::INT, true, 0, true]
- ]
- ],
- 'user5' =>
- [
- 'app1' => [
- 'key1' => ['key1', 'value1']
- ],
- 'app2' => [
- 'key8' => ['key8', 12, ValueType::INT, false, 0, true]
- ],
- 'only-lazy' => [
- 'key1' => ['key1', 'value1', ValueType::STRING, true, 0, true]
- ]
- ],
- ];
- protected function setUp(): void {
- parent::setUp();
- $this->connection = \OCP\Server::get(IDBConnection::class);
- $this->logger = \OCP\Server::get(LoggerInterface::class);
- $this->crypto = \OCP\Server::get(ICrypto::class);
- // storing current preferences and emptying the data table
- $sql = $this->connection->getQueryBuilder();
- $sql->select('*')
- ->from('preferences');
- $result = $sql->executeQuery();
- $this->originalPreferences = $result->fetchAll();
- $result->closeCursor();
- $sql = $this->connection->getQueryBuilder();
- $sql->delete('preferences');
- $sql->executeStatement();
- $sql = $this->connection->getQueryBuilder();
- $sql->insert('preferences')
- ->values(
- [
- 'userid' => $sql->createParameter('userid'),
- 'appid' => $sql->createParameter('appid'),
- 'configkey' => $sql->createParameter('configkey'),
- 'configvalue' => $sql->createParameter('configvalue'),
- 'type' => $sql->createParameter('type'),
- 'lazy' => $sql->createParameter('lazy'),
- 'flags' => $sql->createParameter('flags'),
- 'indexed' => $sql->createParameter('indexed')
- ]
- );
- foreach ($this->basePreferences as $userId => $userData) {
- foreach ($userData as $appId => $appData) {
- foreach ($appData as $key => $row) {
- $value = $row[1];
- $type = ($row[2] ?? ValueType::MIXED)->value;
- if ($type === ValueType::ARRAY->value) {
- $value = json_encode($value);
- }
- if ($type === ValueType::BOOL->value && $value === false) {
- $value = '0';
- }
- $flags = $row[4] ?? 0;
- if ((UserConfig::FLAG_SENSITIVE & $flags) !== 0) {
- $value = self::invokePrivate(UserConfig::class, 'ENCRYPTION_PREFIX')
- . $this->crypto->encrypt((string)$value);
- } else {
- $indexed = (($row[5] ?? false) === true) ? $value : '';
- }
- $sql->setParameters(
- [
- 'userid' => $userId,
- 'appid' => $appId,
- 'configkey' => $row[0],
- 'configvalue' => $value,
- 'type' => $type,
- 'lazy' => (($row[3] ?? false) === true) ? 1 : 0,
- 'flags' => $flags,
- 'indexed' => $indexed ?? ''
- ]
- )->executeStatement();
- }
- }
- }
- }
- protected function tearDown(): void {
- $sql = $this->connection->getQueryBuilder();
- $sql->delete('preferences');
- $sql->executeStatement();
- $sql = $this->connection->getQueryBuilder();
- $sql->insert('preferences')
- ->values(
- [
- 'userid' => $sql->createParameter('userid'),
- 'appid' => $sql->createParameter('appid'),
- 'configkey' => $sql->createParameter('configkey'),
- 'configvalue' => $sql->createParameter('configvalue'),
- 'lazy' => $sql->createParameter('lazy'),
- 'type' => $sql->createParameter('type'),
- ]
- );
- foreach ($this->originalPreferences as $key => $configs) {
- $sql->setParameter('userid', $configs['userid'])
- ->setParameter('appid', $configs['appid'])
- ->setParameter('configkey', $configs['configkey'])
- ->setParameter('configvalue', $configs['configvalue'])
- ->setParameter('lazy', ($configs['lazy'] === '1') ? '1' : '0')
- ->setParameter('type', $configs['type']);
- $sql->executeStatement();
- }
- parent::tearDown();
- }
- /**
- * @param array $preLoading preload the 'fast' cache for a list of users)
- *
- * @return IUserConfig
- */
- private function generateUserConfig(array $preLoading = []): IUserConfig {
- $userConfig = new \OC\Config\UserConfig(
- $this->connection,
- $this->logger,
- $this->crypto,
- );
- $msg = ' generateUserConfig() failed to confirm cache status';
- // confirm cache status
- $status = $userConfig->statusCache();
- $this->assertSame([], $status['fastLoaded'], $msg);
- $this->assertSame([], $status['lazyLoaded'], $msg);
- $this->assertSame([], $status['fastCache'], $msg);
- $this->assertSame([], $status['lazyCache'], $msg);
- foreach ($preLoading as $preLoadUser) {
- // simple way to initiate the load of non-lazy preferences values in cache
- $userConfig->getValueString($preLoadUser, 'core', 'preload');
- // confirm cache status
- $status = $userConfig->statusCache();
- $this->assertSame(true, $status['fastLoaded'][$preLoadUser], $msg);
- $this->assertSame(false, $status['lazyLoaded'][$preLoadUser], $msg);
- $apps = array_values(array_diff(array_keys($this->basePreferences[$preLoadUser]), ['only-lazy']));
- $this->assertEqualsCanonicalizing($apps, array_keys($status['fastCache'][$preLoadUser]), $msg);
- $this->assertSame([], array_keys($status['lazyCache'][$preLoadUser]), $msg);
- }
- return $userConfig;
- }
- public function testGetUserIdsEmpty(): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEqualsCanonicalizing(array_keys($this->basePreferences), $userConfig->getUserIds());
- }
- public function testGetUserIds(): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEqualsCanonicalizing(['user1', 'user2', 'user5'], $userConfig->getUserIds('app1'));
- }
- public function testGetApps(): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEqualsCanonicalizing(
- array_keys($this->basePreferences['user1']), $userConfig->getApps('user1')
- );
- }
- public function testGetKeys(): void {
- $userConfig = $this->generateUserConfig(['user1']);
- $this->assertEqualsCanonicalizing(
- array_keys($this->basePreferences['user1']['app1']), $userConfig->getKeys('user1', 'app1')
- );
- }
- /**
- * @return array[]
- */
- public function providerHasKey(): array {
- return [
- ['user1', 'app1', 'key1', false, true],
- ['user0', 'app1', 'key1', false, false],
- ['user1', 'app1', 'key1', true, false],
- ['user1', 'app1', 'key0', false, false],
- ['user1', 'app1', 'key0', true, false],
- ['user1', 'app1', 'fast_string_sensitive', false, true],
- ['user1', 'app1', 'lazy_string_sensitive', true, true],
- ['user2', 'only-lazy', 'key1', false, false],
- ['user2', 'only-lazy', 'key1', true, true],
- ];
- }
- /**
- * @dataProvider providerHasKey
- */
- public function testHasKey(string $userId, string $appId, string $key, ?bool $lazy, bool $result): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEquals($result, $userConfig->hasKey($userId, $appId, $key, $lazy));
- }
- /**
- * @return array[]
- */
- public function providerIsSensitive(): array {
- return [
- ['user1', 'app1', 'key1', false, false, false],
- ['user0', 'app1', 'key1', false, false, true],
- ['user1', 'app1', 'key1', true, false, true],
- ['user1', 'app1', 'key1', null, false, false],
- ['user1', 'app1', 'key0', false, false, true],
- ['user1', 'app1', 'key0', true, false, true],
- ['user1', 'app1', 'fast_string_sensitive', false, true, false],
- ['user1', 'app1', 'lazy_string_sensitive', true, true, false],
- ['user1', 'app1', 'fast_string_sensitive', true, true, true],
- ['user1', 'app1', 'lazy_string_sensitive', false, true, true],
- ['user1', 'app1', 'lazy_string_sensitive', null, true, false],
- ['user2', 'only-lazy', 'key1', false, false, true],
- ['user2', 'only-lazy', 'key1', true, false, false],
- ['user2', 'only-lazy', 'key1', null, false, false],
- ];
- }
- /**
- * @dataProvider providerIsSensitive
- */
- public function testIsSensitive(
- string $userId,
- string $appId,
- string $key,
- ?bool $lazy,
- bool $result,
- bool $exception,
- ): void {
- $userConfig = $this->generateUserConfig();
- if ($exception) {
- $this->expectException(UnknownKeyException::class);
- }
- $this->assertEquals($result, $userConfig->isSensitive($userId, $appId, $key, $lazy));
- }
- /**
- * @return array[]
- */
- public function providerIsLazy(): array {
- return [
- ['user1', 'app1', 'key1', false, false],
- ['user0', 'app1', 'key1', false, true],
- ['user1', 'app1', 'key0', false, true],
- ['user1', 'app1', 'key0', false, true],
- ['user1', 'app1', 'fast_string_sensitive', false, false],
- ['user1', 'app1', 'lazy_string_sensitive', true, false],
- ['user2', 'only-lazy', 'key1', true, false],
- ];
- }
- /**
- * @dataProvider providerIsLazy
- */
- public function testIsLazy(
- string $userId,
- string $appId,
- string $key,
- bool $result,
- bool $exception,
- ): void {
- $userConfig = $this->generateUserConfig();
- if ($exception) {
- $this->expectException(UnknownKeyException::class);
- }
- $this->assertEquals($result, $userConfig->isLazy($userId, $appId, $key));
- }
- public function providerGetValues(): array {
- return [
- [
- 'user1', 'app1', '', true,
- [
- 'fast_array' => ['year' => 2024],
- 'fast_array_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'fast_boolean' => true,
- 'fast_boolean_0' => false,
- 'fast_float' => 3.14,
- 'fast_float_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'fast_int' => 11,
- 'fast_int_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'fast_string' => 'f_value',
- 'fast_string_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'key1' => 'value1',
- 'key22' => '31',
- 'lazy_array' => ['month' => 'October'],
- 'lazy_array_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'lazy_boolean' => true,
- 'lazy_boolean_0' => false,
- 'lazy_float' => 3.14159,
- 'lazy_float_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'lazy_int' => 12,
- 'lazy_int_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'lazy_string' => 'l_value',
- 'lazy_string_sensitive' => '***REMOVED SENSITIVE VALUE***',
- ]
- ],
- [
- 'user1', 'app1', '', false,
- [
- 'fast_array' => ['year' => 2024],
- 'fast_array_sensitive' => ['password' => 'pwd'],
- 'fast_boolean' => true,
- 'fast_boolean_0' => false,
- 'fast_float' => 3.14,
- 'fast_float_sensitive' => 1.41,
- 'fast_int' => 11,
- 'fast_int_sensitive' => 2024,
- 'fast_string' => 'f_value',
- 'fast_string_sensitive' => 'fs_value',
- 'key1' => 'value1',
- 'key22' => '31',
- 'lazy_array' => ['month' => 'October'],
- 'lazy_array_sensitive' => ['password' => 'qwerty'],
- 'lazy_boolean' => true,
- 'lazy_boolean_0' => false,
- 'lazy_float' => 3.14159,
- 'lazy_float_sensitive' => 1.4142,
- 'lazy_int' => 12,
- 'lazy_int_sensitive' => 2048,
- 'lazy_string' => 'l_value',
- 'lazy_string_sensitive' => 'ls_value'
- ]
- ],
- [
- 'user1', 'app1', 'fast_', true,
- [
- 'fast_array' => ['year' => 2024],
- 'fast_array_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'fast_boolean' => true,
- 'fast_boolean_0' => false,
- 'fast_float' => 3.14,
- 'fast_float_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'fast_int' => 11,
- 'fast_int_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'fast_string' => 'f_value',
- 'fast_string_sensitive' => '***REMOVED SENSITIVE VALUE***',
- ]
- ],
- [
- 'user1', 'app1', 'fast_', false,
- [
- 'fast_array' => ['year' => 2024],
- 'fast_array_sensitive' => ['password' => 'pwd'],
- 'fast_boolean' => true,
- 'fast_boolean_0' => false,
- 'fast_float' => 3.14,
- 'fast_float_sensitive' => 1.41,
- 'fast_int' => 11,
- 'fast_int_sensitive' => 2024,
- 'fast_string' => 'f_value',
- 'fast_string_sensitive' => 'fs_value',
- ]
- ],
- [
- 'user1', 'app1', 'key1', true,
- [
- 'key1' => 'value1',
- ]
- ],
- [
- 'user2', 'app1', '', false,
- [
- '1' => 'value1',
- '4' => 42,
- '5' => 17.42,
- '6' => true,
- '2' => 'value2',
- '3' => 17,
- ]
- ],
- [
- 'user2', 'app1', '', true,
- [
- '1' => 'value1',
- '4' => '***REMOVED SENSITIVE VALUE***',
- '5' => 17.42,
- '6' => true,
- '2' => '***REMOVED SENSITIVE VALUE***',
- '3' => 17,
- ]
- ],
- ];
- }
- /**
- * @dataProvider providerGetValues
- */
- public function testGetValues(
- string $userId,
- string $appId,
- string $prefix,
- bool $filtered,
- array $result,
- ): void {
- $userConfig = $this->generateUserConfig();
- $this->assertJsonStringEqualsJsonString(
- json_encode($result), json_encode($userConfig->getValues($userId, $appId, $prefix, $filtered))
- );
- }
- public function providerGetAllValues(): array {
- return [
- [
- 'user2', false,
- [
- 'app1' => [
- '1' => 'value1',
- '4' => 42,
- '5' => 17.42,
- '6' => true,
- '2' => 'value2',
- '3' => 17,
- ],
- 'app2' => [
- 'key2' => 'value2b',
- 'key3' => 'value3',
- 'key4' => 'value4',
- 'key8' => 12,
- ],
- 'app3' => [
- 'key10' => false,
- ],
- 'only-lazy' => [
- 'key1' => 'value1',
- ]
- ],
- ],
- [
- 'user2', true,
- [
- 'app1' => [
- '1' => 'value1',
- '4' => '***REMOVED SENSITIVE VALUE***',
- '5' => 17.42,
- '6' => true,
- '2' => '***REMOVED SENSITIVE VALUE***',
- '3' => 17,
- ],
- 'app2' => [
- 'key2' => 'value2b',
- 'key3' => 'value3',
- 'key4' => '***REMOVED SENSITIVE VALUE***',
- 'key8' => 12,
- ],
- 'app3' => [
- 'key10' => false,
- ],
- 'only-lazy' => [
- 'key1' => 'value1',
- ]
- ],
- ],
- [
- 'user3', true,
- [
- 'app2' => [
- 'key2' => 'value2c',
- 'key3' => 'value3',
- 'key4' => '***REMOVED SENSITIVE VALUE***',
- 'fast_string_sensitive' => '***REMOVED SENSITIVE VALUE***',
- 'lazy_string_sensitive' => '***REMOVED SENSITIVE VALUE***',
- ],
- 'only-lazy' => [
- 'key3' => 'value3',
- ]
- ],
- ],
- [
- 'user3', false,
- [
- 'app2' => [
- 'key2' => 'value2c',
- 'key3' => 'value3',
- 'key4' => 'value4',
- 'fast_string_sensitive' => 'fs_value',
- 'lazy_string_sensitive' => 'ls_value',
- ],
- 'only-lazy' => [
- 'key3' => 'value3',
- ]
- ],
- ],
- ];
- }
- /**
- * @dataProvider providerGetAllValues
- */
- public function testGetAllValues(
- string $userId,
- bool $filtered,
- array $result,
- ): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEqualsCanonicalizing($result, $userConfig->getAllValues($userId, $filtered));
- }
- public function providerSearchValuesByApps(): array {
- return [
- [
- 'user1', 'key1', false, null,
- [
- 'app1' => 'value1',
- 'app3' => 'value123'
- ]
- ],
- [
- 'user1', 'key1', true, null,
- [
- 'only-lazy' => 'value456'
- ]
- ],
- [
- 'user1', 'key8', false, null,
- [
- 'app2' => 11,
- 'app3' => 12,
- ]
- ],
- [
- 'user1', 'key9', false, ValueType::INT,
- [
- 'app2' => 0,
- 'app3' => 0,
- ]
- ]
- ];
- }
- /**
- * @dataProvider providerSearchValuesByApps
- */
- public function testSearchValuesByApps(
- string $userId,
- string $key,
- bool $lazy,
- ?ValueType $typedAs,
- array $result,
- ): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEquals($result, $userConfig->getValuesByApps($userId, $key, $lazy, $typedAs));
- }
- public function providerSearchValuesByUsers(): array {
- return [
- [
- 'app2', 'key2', null, null,
- [
- 'user1' => 'value2a',
- 'user2' => 'value2b',
- 'user3' => 'value2c',
- 'user4' => 'value2A'
- ]
- ],
- [
- 'app2', 'key2', null, ['user1', 'user3'],
- [
- 'user1' => 'value2a',
- 'user3' => 'value2c',
- ]
- ],
- [
- 'app2', 'key2', ValueType::INT, ['user1', 'user3'],
- [
- 'user1' => 0,
- 'user3' => 0,
- ]
- ],
- [
- 'app2', 'key8', ValueType::INT, null,
- [
- 'user1' => 11,
- 'user2' => 12,
- 'user5' => 12,
- ]
- ],
- ];
- }
- /**
- * @dataProvider providerSearchValuesByUsers
- */
- public function testSearchValuesByUsers(
- string $app,
- string $key,
- ?ValueType $typedAs = null,
- ?array $userIds = null,
- array $result = [],
- ): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEqualsCanonicalizing(
- $result, $userConfig->getValuesByUsers($app, $key, $typedAs, $userIds)
- );
- }
- public function providerSearchValuesByValueString(): array {
- return [
- ['app2', 'key2', 'value2a', false, ['user1']],
- ['app2', 'key2', 'value2A', false, ['user4']],
- ['app2', 'key2', 'value2A', true, ['user1', 'user4']]
- ];
- }
- /**
- * @dataProvider providerSearchValuesByValueString
- */
- public function testSearchUsersByValueString(
- string $app,
- string $key,
- string|array $value,
- bool $ci,
- array $result,
- ): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEqualsCanonicalizing($result, iterator_to_array($userConfig->searchUsersByValueString($app, $key, $value, $ci)));
- }
- public function providerSearchValuesByValueInt(): array {
- return [
- ['app3', 'key8', 12, []], // sensitive value, cannot search
- ['app2', 'key8', 12, ['user2', 'user5']], // sensitive value, cannot search
- ['only-lazy', 'key1', 123, ['user4']],
- ];
- }
- /**
- * @dataProvider providerSearchValuesByValueInt
- */
- public function testSearchUsersByValueInt(
- string $app,
- string $key,
- int $value,
- array $result,
- ): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEqualsCanonicalizing($result, iterator_to_array($userConfig->searchUsersByValueInt($app, $key, $value)));
- }
- public function providerSearchValuesByValues(): array {
- return [
- ['app2', 'key2', ['value2a', 'value2b'], ['user1', 'user2']],
- ['app2', 'key2', ['value2a', 'value2c'], ['user1', 'user3']],
- ];
- }
- /**
- * @dataProvider providerSearchValuesByValues
- */
- public function testSearchUsersByValues(
- string $app,
- string $key,
- array $values,
- array $result,
- ): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEqualsCanonicalizing($result, iterator_to_array($userConfig->searchUsersByValues($app, $key, $values)));
- }
- public function providerSearchValuesByValueBool(): array {
- return [
- ['app3', 'key10', true, ['user1', 'user4']],
- ['app3', 'key10', false, ['user2']],
- ];
- }
- /**
- * @dataProvider providerSearchValuesByValueBool
- */
- public function testSearchUsersByValueBool(
- string $app,
- string $key,
- bool $value,
- array $result,
- ): void {
- $userConfig = $this->generateUserConfig();
- $this->assertEqualsCanonicalizing($result, iterator_to_array($userConfig->searchUsersByValueBool($app, $key, $value)));
- }
- public function providerGetValueMixed(): array {
- return [
- [
- ['user1'], 'user1', 'app1', 'key0', 'default_because_unknown_key', true,
- 'default_because_unknown_key'
- ],
- [
- null, 'user1', 'app1', 'key0', 'default_because_unknown_key', true,
- 'default_because_unknown_key'
- ],
- [
- ['user1'], 'user1', 'app1', 'key0', 'default_because_unknown_key', false,
- 'default_because_unknown_key'
- ],
- [
- null, 'user1', 'app1', 'key0', 'default_because_unknown_key', false,
- 'default_because_unknown_key'
- ],
- [['user1'], 'user1', 'app1', 'fast_string', 'default_because_unknown_key', false, 'f_value'],
- [null, 'user1', 'app1', 'fast_string', 'default_because_unknown_key', false, 'f_value'],
- [['user1'], 'user1', 'app1', 'fast_string', 'default_because_unknown_key', true, 'f_value'],
- // because non-lazy are already loaded
- [
- null, 'user1', 'app1', 'fast_string', 'default_because_unknown_key', true,
- 'default_because_unknown_key'
- ],
- [
- ['user1'], 'user1', 'app1', 'lazy_string', 'default_because_unknown_key', false,
- 'default_because_unknown_key'
- ],
- [
- null, 'user1', 'app1', 'lazy_string', 'default_because_unknown_key', false,
- 'default_because_unknown_key'
- ],
- [['user1'], 'user1', 'app1', 'lazy_string', 'default_because_unknown_key', true, 'l_value'],
- [null, 'user1', 'app1', 'lazy_string', 'default_because_unknown_key', true, 'l_value'],
- [
- ['user1'], 'user1', 'app1', 'fast_string_sensitive', 'default_because_unknown_key', false,
- 'fs_value'
- ],
- [
- null, 'user1', 'app1', 'fast_string_sensitive', 'default_because_unknown_key', false,
- 'fs_value'
- ],
- [
- ['user1'], 'user1', 'app1', 'fast_string_sensitive', 'default_because_unknown_key', true,
- 'fs_value'
- ],
- [
- null, 'user1', 'app1', 'fast_string_sensitive', 'default_because_unknown_key', true,
- 'default_because_unknown_key'
- ],
- [
- ['user1'], 'user1', 'app1', 'lazy_string_sensitive', 'default_because_unknown_key', false,
- 'default_because_unknown_key'
- ],
- [
- null, 'user1', 'app1', 'lazy_string_sensitive', 'default_because_unknown_key', false,
- 'default_because_unknown_key'
- ],
- [
- ['user1'], 'user1', 'app1', 'lazy_string_sensitive', 'default_because_unknown_key', true,
- 'ls_value'
- ],
- [null, 'user1', 'app1', 'lazy_string_sensitive', 'default_because_unknown_key', true, 'ls_value'],
- ];
- }
- /**
- * @dataProvider providerGetValueMixed
- */
- public function testGetValueMixed(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- string $default,
- bool $lazy,
- string $result,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals($result, $userConfig->getValueMixed($userId, $app, $key, $default, $lazy));
- }
- /**
- * @dataProvider providerGetValueMixed
- */
- public function testGetValueString(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- string $default,
- bool $lazy,
- string $result,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals($result, $userConfig->getValueString($userId, $app, $key, $default, $lazy));
- }
- public function providerGetValueInt(): array {
- return [
- [['user1'], 'user1', 'app1', 'key0', 54321, true, 54321],
- [null, 'user1', 'app1', 'key0', 54321, true, 54321],
- [['user1'], 'user1', 'app1', 'key0', 54321, false, 54321],
- [null, 'user1', 'app1', 'key0', 54321, false, 54321],
- [null, 'user1', 'app1', 'key22', 54321, false, 31],
- [['user1'], 'user1', 'app1', 'fast_int', 54321, false, 11],
- [null, 'user1', 'app1', 'fast_int', 54321, false, 11],
- [['user1'], 'user1', 'app1', 'fast_int', 54321, true, 11],
- [null, 'user1', 'app1', 'fast_int', 54321, true, 54321],
- [['user1'], 'user1', 'app1', 'fast_int_sensitive', 54321, false, 2024],
- [null, 'user1', 'app1', 'fast_int_sensitive', 54321, false, 2024],
- [['user1'], 'user1', 'app1', 'fast_int_sensitive', 54321, true, 2024],
- [null, 'user1', 'app1', 'fast_int_sensitive', 54321, true, 54321],
- [['user1'], 'user1', 'app1', 'lazy_int', 54321, false, 54321],
- [null, 'user1', 'app1', 'lazy_int', 54321, false, 54321],
- [['user1'], 'user1', 'app1', 'lazy_int', 54321, true, 12],
- [null, 'user1', 'app1', 'lazy_int', 54321, true, 12],
- [['user1'], 'user1', 'app1', 'lazy_int_sensitive', 54321, false, 54321],
- [null, 'user1', 'app1', 'lazy_int_sensitive', 54321, false, 54321],
- [['user1'], 'user1', 'app1', 'lazy_int_sensitive', 54321, true, 2048],
- [null, 'user1', 'app1', 'lazy_int_sensitive', 54321, true, 2048],
- ];
- }
- /**
- * @dataProvider providerGetValueInt
- */
- public function testGetValueInt(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- int $default,
- bool $lazy,
- int $result,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals($result, $userConfig->getValueInt($userId, $app, $key, $default, $lazy));
- }
- public function providerGetValueFloat(): array {
- return [
- [['user1'], 'user1', 'app1', 'key0', 54.321, true, 54.321],
- [null, 'user1', 'app1', 'key0', 54.321, true, 54.321],
- [['user1'], 'user1', 'app1', 'key0', 54.321, false, 54.321],
- [null, 'user1', 'app1', 'key0', 54.321, false, 54.321],
- [['user1'], 'user1', 'app1', 'fast_float', 54.321, false, 3.14],
- [null, 'user1', 'app1', 'fast_float', 54.321, false, 3.14],
- [['user1'], 'user1', 'app1', 'fast_float', 54.321, true, 3.14],
- [null, 'user1', 'app1', 'fast_float', 54.321, true, 54.321],
- [['user1'], 'user1', 'app1', 'fast_float_sensitive', 54.321, false, 1.41],
- [null, 'user1', 'app1', 'fast_float_sensitive', 54.321, false, 1.41],
- [['user1'], 'user1', 'app1', 'fast_float_sensitive', 54.321, true, 1.41],
- [null, 'user1', 'app1', 'fast_float_sensitive', 54.321, true, 54.321],
- [['user1'], 'user1', 'app1', 'lazy_float', 54.321, false, 54.321],
- [null, 'user1', 'app1', 'lazy_float', 54.321, false, 54.321],
- [['user1'], 'user1', 'app1', 'lazy_float', 54.321, true, 3.14159],
- [null, 'user1', 'app1', 'lazy_float', 54.321, true, 3.14159],
- [['user1'], 'user1', 'app1', 'lazy_float_sensitive', 54.321, false, 54.321],
- [null, 'user1', 'app1', 'lazy_float_sensitive', 54.321, false, 54.321],
- [['user1'], 'user1', 'app1', 'lazy_float_sensitive', 54.321, true, 1.4142],
- [null, 'user1', 'app1', 'lazy_float_sensitive', 54.321, true, 1.4142],
- ];
- }
- /**
- * @dataProvider providerGetValueFloat
- */
- public function testGetValueFloat(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- float $default,
- bool $lazy,
- float $result,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals($result, $userConfig->getValueFloat($userId, $app, $key, $default, $lazy));
- }
- public function providerGetValueBool(): array {
- return [
- [['user1'], 'user1', 'app1', 'key0', false, true, false],
- [null, 'user1', 'app1', 'key0', false, true, false],
- [['user1'], 'user1', 'app1', 'key0', true, true, true],
- [null, 'user1', 'app1', 'key0', true, true, true],
- [['user1'], 'user1', 'app1', 'key0', false, false, false],
- [null, 'user1', 'app1', 'key0', false, false, false],
- [['user1'], 'user1', 'app1', 'key0', true, false, true],
- [null, 'user1', 'app1', 'key0', true, false, true],
- [['user1'], 'user1', 'app1', 'fast_boolean', false, false, true],
- [null, 'user1', 'app1', 'fast_boolean', false, false, true],
- [['user1'], 'user1', 'app1', 'fast_boolean_0', false, false, false],
- [null, 'user1', 'app1', 'fast_boolean_0', false, false, false],
- [['user1'], 'user1', 'app1', 'fast_boolean', true, false, true],
- [null, 'user1', 'app1', 'fast_boolean', true, false, true],
- [['user1'], 'user1', 'app1', 'fast_boolean_0', true, false, false],
- [null, 'user1', 'app1', 'fast_boolean_0', true, false, false],
- [['user1'], 'user1', 'app1', 'fast_boolean', false, true, true],
- [null, 'user1', 'app1', 'fast_boolean', false, true, false],
- [['user1'], 'user1', 'app1', 'fast_boolean_0', false, true, false],
- [null, 'user1', 'app1', 'fast_boolean_0', false, true, false],
- [['user1'], 'user1', 'app1', 'fast_boolean', true, true, true],
- [null, 'user1', 'app1', 'fast_boolean', true, true, true],
- [['user1'], 'user1', 'app1', 'fast_boolean_0', true, true, false],
- [null, 'user1', 'app1', 'fast_boolean_0', true, true, true],
- [['user1'], 'user1', 'app1', 'lazy_boolean', false, false, false],
- [null, 'user1', 'app1', 'lazy_boolean', false, false, false],
- [['user1'], 'user1', 'app1', 'lazy_boolean_0', false, false, false],
- [null, 'user1', 'app1', 'lazy_boolean_0', false, false, false],
- [['user1'], 'user1', 'app1', 'lazy_boolean', true, false, true],
- [null, 'user1', 'app1', 'lazy_boolean', true, false, true],
- [['user1'], 'user1', 'app1', 'lazy_boolean_0', true, false, true],
- [null, 'user1', 'app1', 'lazy_boolean_0', true, false, true],
- [['user1'], 'user1', 'app1', 'lazy_boolean', false, true, true],
- [null, 'user1', 'app1', 'lazy_boolean', false, true, true],
- [['user1'], 'user1', 'app1', 'lazy_boolean_0', false, true, false],
- [null, 'user1', 'app1', 'lazy_boolean_0', false, true, false],
- [['user1'], 'user1', 'app1', 'lazy_boolean', true, true, true],
- [null, 'user1', 'app1', 'lazy_boolean', true, true, true],
- [['user1'], 'user1', 'app1', 'lazy_boolean_0', true, true, false],
- [null, 'user1', 'app1', 'lazy_boolean_0', true, true, false],
- ];
- }
- /**
- * @dataProvider providerGetValueBool
- */
- public function testGetValueBool(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- bool $default,
- bool $lazy,
- bool $result,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals($result, $userConfig->getValueBool($userId, $app, $key, $default, $lazy));
- }
- public function providerGetValueArray(): array {
- return [
- [
- ['user1'], 'user1', 'app1', 'key0', ['default_because_unknown_key'], true,
- ['default_because_unknown_key']
- ],
- [
- null, 'user1', 'app1', 'key0', ['default_because_unknown_key'], true,
- ['default_because_unknown_key']
- ],
- [
- ['user1'], 'user1', 'app1', 'key0', ['default_because_unknown_key'], false,
- ['default_because_unknown_key']
- ],
- [
- null, 'user1', 'app1', 'key0', ['default_because_unknown_key'], false,
- ['default_because_unknown_key']
- ],
- ];
- }
- /**
- * @dataProvider providerGetValueArray
- */
- public function testGetValueArray(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- array $default,
- bool $lazy,
- array $result,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEqualsCanonicalizing(
- $result, $userConfig->getValueArray($userId, $app, $key, $default, $lazy)
- );
- }
- public function providerGetValueType(): array {
- return [
- [null, 'user1', 'app1', 'key1', false, ValueType::MIXED],
- [null, 'user1', 'app1', 'key1', true, null, UnknownKeyException::class],
- [null, 'user1', 'app1', 'fast_string', true, ValueType::STRING, UnknownKeyException::class],
- [['user1'], 'user1', 'app1', 'fast_string', true, ValueType::STRING],
- [null, 'user1', 'app1', 'fast_string', false, ValueType::STRING],
- [null, 'user1', 'app1', 'lazy_string', true, ValueType::STRING],
- [null, 'user1', 'app1', 'lazy_string', false, ValueType::STRING, UnknownKeyException::class],
- [
- null, 'user1', 'app1', 'fast_string_sensitive', true, ValueType::STRING,
- UnknownKeyException::class
- ],
- [['user1'], 'user1', 'app1', 'fast_string_sensitive', true, ValueType::STRING],
- [null, 'user1', 'app1', 'fast_string_sensitive', false, ValueType::STRING],
- [null, 'user1', 'app1', 'lazy_string_sensitive', true, ValueType::STRING],
- [
- null, 'user1', 'app1', 'lazy_string_sensitive', false, ValueType::STRING,
- UnknownKeyException::class
- ],
- [null, 'user1', 'app1', 'fast_int', true, ValueType::INT, UnknownKeyException::class],
- [['user1'], 'user1', 'app1', 'fast_int', true, ValueType::INT],
- [null, 'user1', 'app1', 'fast_int', false, ValueType::INT],
- [null, 'user1', 'app1', 'lazy_int', true, ValueType::INT],
- [null, 'user1', 'app1', 'lazy_int', false, ValueType::INT, UnknownKeyException::class],
- [null, 'user1', 'app1', 'fast_float', true, ValueType::FLOAT, UnknownKeyException::class],
- [['user1'], 'user1', 'app1', 'fast_float', true, ValueType::FLOAT],
- [null, 'user1', 'app1', 'fast_float', false, ValueType::FLOAT],
- [null, 'user1', 'app1', 'lazy_float', true, ValueType::FLOAT],
- [null, 'user1', 'app1', 'lazy_float', false, ValueType::FLOAT, UnknownKeyException::class],
- [null, 'user1', 'app1', 'fast_boolean', true, ValueType::BOOL, UnknownKeyException::class],
- [['user1'], 'user1', 'app1', 'fast_boolean', true, ValueType::BOOL],
- [null, 'user1', 'app1', 'fast_boolean', false, ValueType::BOOL],
- [null, 'user1', 'app1', 'lazy_boolean', true, ValueType::BOOL],
- [null, 'user1', 'app1', 'lazy_boolean', false, ValueType::BOOL, UnknownKeyException::class],
- ];
- }
- /**
- * @dataProvider providerGetValueType
- */
- public function testGetValueType(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- ?bool $lazy,
- ?ValueType $result,
- ?string $exception = null,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- if ($exception !== null) {
- $this->expectException($exception);
- }
- $type = $userConfig->getValueType($userId, $app, $key, $lazy);
- if ($exception === null) {
- $this->assertEquals($result->value, $type->value);
- }
- }
- public function providerSetValueMixed(): array {
- return [
- [null, 'user1', 'app1', 'key1', 'value', false, false, true],
- [null, 'user1', 'app1', 'key1', '12345', true, false, true],
- [null, 'user1', 'app1', 'key1', '12345', true, true, true],
- [null, 'user1', 'app1', 'key1', 'value1', false, false, false],
- [null, 'user1', 'app1', 'key1', 'value1', true, false, true],
- [null, 'user1', 'app1', 'key1', 'value1', false, true, true],
- [
- null, 'user1', 'app1', 'fast_string', 'f_value_2', false, false, true,
- TypeConflictException::class
- ],
- [
- null, 'user1', 'app1', 'fast_string', 'f_value', true, false, true,
- TypeConflictException::class
- ],
- [null, 'user1', 'app1', 'fast_string', 'f_value', true, true, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_int', 'n_value', false, false, true, TypeConflictException::class],
- [
- null, 'user1', 'app1', 'fast_float', 'n_value', false, false, true,
- TypeConflictException::class
- ],
- [
- null, 'user1', 'app1', 'lazy_string', 'l_value_2', false, false, true,
- TypeConflictException::class
- ],
- [null, 'user1', 'app1', 'lazy_string', 'l_value', true, false, false],
- [null, 'user1', 'app1', 'lazy_string', 'l_value', true, true, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_int', 'l_value', false, false, true, TypeConflictException::class],
- [
- null, 'user1', 'app1', 'lazy_float', 'l_value', false, false, true,
- TypeConflictException::class
- ],
- ];
- }
- /**
- * @dataProvider providerSetValueMixed
- */
- public function testSetValueMixed(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- string $value,
- bool $lazy,
- bool $sensitive,
- bool $result,
- ?string $exception = null,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- if ($exception !== null) {
- $this->expectException($exception);
- }
- $edited = $userConfig->setValueMixed($userId, $app, $key, $value, $lazy, ($sensitive) ? 1 : 0);
- if ($exception === null) {
- $this->assertEquals($result, $edited);
- }
- }
- public function providerSetValueString(): array {
- return [
- [null, 'user1', 'app1', 'key1', 'value', false, false, true],
- [null, 'user1', 'app1', 'key1', '12345', true, false, true],
- [null, 'user1', 'app1', 'key1', '12345', true, true, true],
- [null, 'user1', 'app1', 'key1', 'value1', false, false, false],
- [null, 'user1', 'app1', 'key1', 'value1', true, false, true],
- [null, 'user1', 'app1', 'key1', 'value1', false, true, true],
- [null, 'user1', 'app1', 'fast_string', 'f_value_2', false, false, true],
- [null, 'user1', 'app1', 'fast_string', 'f_value', false, false, false],
- [null, 'user1', 'app1', 'fast_string', 'f_value', true, false, true],
- [null, 'user1', 'app1', 'fast_string', 'f_value', true, true, true],
- [null, 'user1', 'app1', 'lazy_string', 'l_value_2', false, false, true],
- [null, 'user1', 'app1', 'lazy_string', 'l_value', true, false, false],
- [null, 'user1', 'app1', 'lazy_string', 'l_value', true, true, true],
- [null, 'user1', 'app1', 'fast_string_sensitive', 'fs_value', false, true, false],
- [null, 'user1', 'app1', 'fast_string_sensitive', 'fs_value', true, true, true],
- [null, 'user1', 'app1', 'fast_string_sensitive', 'fs_value', true, false, true],
- [null, 'user1', 'app1', 'lazy_string_sensitive', 'ls_value', false, true, true],
- [null, 'user1', 'app1', 'lazy_string_sensitive', 'ls_value', true, true, false],
- [null, 'user1', 'app1', 'lazy_string_sensitive', 'ls_value', true, false, false],
- [null, 'user1', 'app1', 'lazy_string_sensitive', 'ls_value_2', true, false, true],
- [null, 'user1', 'app1', 'fast_int', 'n_value', false, false, true, TypeConflictException::class],
- [
- null, 'user1', 'app1', 'fast_float', 'n_value', false, false, true,
- TypeConflictException::class
- ],
- [
- null, 'user1', 'app1', 'fast_float', 'n_value', false, false, true,
- TypeConflictException::class
- ],
- [null, 'user1', 'app1', 'lazy_int', 'n_value', false, false, true, TypeConflictException::class],
- [
- null, 'user1', 'app1', 'lazy_boolean', 'n_value', false, false, true,
- TypeConflictException::class
- ],
- [
- null, 'user1', 'app1', 'lazy_float', 'n_value', false, false, true,
- TypeConflictException::class
- ],
- ];
- }
- /**
- * @dataProvider providerSetValueString
- */
- public function testSetValueString(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- string $value,
- bool $lazy,
- bool $sensitive,
- bool $result,
- ?string $exception = null,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- if ($exception !== null) {
- $this->expectException($exception);
- }
- $edited = $userConfig->setValueString($userId, $app, $key, $value, $lazy, ($sensitive) ? 1 : 0);
- if ($exception !== null) {
- return;
- }
- $this->assertEquals($result, $edited);
- if ($result) {
- $this->assertEquals($value, $userConfig->getValueString($userId, $app, $key, $value, $lazy));
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals($value, $userConfig->getValueString($userId, $app, $key, $value, $lazy));
- }
- }
- public function providerSetValueInt(): array {
- return [
- [null, 'user1', 'app1', 'key1', 12345, false, false, true],
- [null, 'user1', 'app1', 'key1', 12345, true, false, true],
- [null, 'user1', 'app1', 'key1', 12345, true, true, true],
- [null, 'user1', 'app1', 'fast_int', 11, false, false, false],
- [null, 'user1', 'app1', 'fast_int', 111, false, false, true],
- [null, 'user1', 'app1', 'fast_int', 111, true, false, true],
- [null, 'user1', 'app1', 'fast_int', 111, false, true, true],
- [null, 'user1', 'app1', 'fast_int', 11, true, false, true],
- [null, 'user1', 'app1', 'fast_int', 11, false, true, true],
- [null, 'user1', 'app1', 'lazy_int', 12, false, false, true],
- [null, 'user1', 'app1', 'lazy_int', 121, false, false, true],
- [null, 'user1', 'app1', 'lazy_int', 121, true, false, true],
- [null, 'user1', 'app1', 'lazy_int', 121, false, true, true],
- [null, 'user1', 'app1', 'lazy_int', 12, true, false, false],
- [null, 'user1', 'app1', 'lazy_int', 12, false, true, true],
- [null, 'user1', 'app1', 'fast_string', 12345, false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_string', 12345, false, false, false, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_string', 12345, true, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_string', 12345, true, true, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_string', 12345, false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_string', 12345, true, false, false, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_string', 12345, true, true, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_float', 12345, false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_float', 12345, false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_boolean', 12345, false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_float', 12345, false, false, true, TypeConflictException::class],
- ];
- }
- /**
- * @dataProvider providerSetValueInt
- */
- public function testSetValueInt(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- int $value,
- bool $lazy,
- bool $sensitive,
- bool $result,
- ?string $exception = null,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- if ($exception !== null) {
- $this->expectException($exception);
- }
- $edited = $userConfig->setValueInt($userId, $app, $key, $value, $lazy, ($sensitive) ? 1 : 0);
- if ($exception !== null) {
- return;
- }
- $this->assertEquals($result, $edited);
- if ($result) {
- $this->assertEquals($value, $userConfig->getValueInt($userId, $app, $key, $value, $lazy));
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals($value, $userConfig->getValueInt($userId, $app, $key, $value, $lazy));
- }
- }
- public function providerSetValueFloat(): array {
- return [
- [null, 'user1', 'app1', 'key1', 12.345, false, false, true],
- [null, 'user1', 'app1', 'key1', 12.345, true, false, true],
- [null, 'user1', 'app1', 'key1', 12.345, true, true, true],
- [null, 'user1', 'app1', 'fast_float', 3.14, false, false, false],
- [null, 'user1', 'app1', 'fast_float', 3.15, false, false, true],
- [null, 'user1', 'app1', 'fast_float', 3.15, true, false, true],
- [null, 'user1', 'app1', 'fast_float', 3.15, false, true, true],
- [null, 'user1', 'app1', 'fast_float', 3.14, true, false, true],
- [null, 'user1', 'app1', 'fast_float', 3.14, false, true, true],
- [null, 'user1', 'app1', 'lazy_float', 3.14159, false, false, true],
- [null, 'user1', 'app1', 'lazy_float', 3.14158, false, false, true],
- [null, 'user1', 'app1', 'lazy_float', 3.14158, true, false, true],
- [null, 'user1', 'app1', 'lazy_float', 3.14158, false, true, true],
- [null, 'user1', 'app1', 'lazy_float', 3.14159, true, false, false],
- [null, 'user1', 'app1', 'lazy_float', 3.14159, false, true, true],
- [null, 'user1', 'app1', 'fast_string', 12.345, false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_string', 12.345, false, false, false, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_string', 12.345, true, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_string', 12.345, true, true, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_string', 12.345, false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_string', 12.345, true, false, false, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_array', 12.345, true, true, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_int', 12.345, false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_int', 12.345, false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_boolean', 12.345, false, false, true, TypeConflictException::class],
- ];
- }
- /**
- * @dataProvider providerSetValueFloat
- */
- public function testSetValueFloat(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- float $value,
- bool $lazy,
- bool $sensitive,
- bool $result,
- ?string $exception = null,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- if ($exception !== null) {
- $this->expectException($exception);
- }
- $edited = $userConfig->setValueFloat($userId, $app, $key, $value, $lazy, ($sensitive) ? 1 : 0);
- if ($exception !== null) {
- return;
- }
- $this->assertEquals($result, $edited);
- if ($result) {
- $this->assertEquals($value, $userConfig->getValueFloat($userId, $app, $key, $value, $lazy));
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals($value, $userConfig->getValueFloat($userId, $app, $key, $value, $lazy));
- }
- }
- public function providerSetValueArray(): array {
- return [
- [null, 'user1', 'app1', 'key1', [], false, false, true],
- [null, 'user1', 'app1', 'key1', [], true, false, true],
- [null, 'user1', 'app1', 'key1', [], true, true, true],
- [null, 'user1', 'app1', 'fast_array', ['year' => 2024], false, false, false],
- [null, 'user1', 'app1', 'fast_array', [], false, false, true],
- [null, 'user1', 'app1', 'fast_array', [], true, false, true],
- [null, 'user1', 'app1', 'fast_array', [], false, true, true],
- [null, 'user1', 'app1', 'fast_array', ['year' => 2024], true, false, true],
- [null, 'user1', 'app1', 'fast_array', ['year' => 2024], false, true, true],
- [null, 'user1', 'app1', 'lazy_array', ['month' => 'October'], false, false, true],
- [null, 'user1', 'app1', 'lazy_array', ['month' => 'September'], false, false, true],
- [null, 'user1', 'app1', 'lazy_array', ['month' => 'September'], true, false, true],
- [null, 'user1', 'app1', 'lazy_array', ['month' => 'September'], false, true, true],
- [null, 'user1', 'app1', 'lazy_array', ['month' => 'October'], true, false, false],
- [null, 'user1', 'app1', 'lazy_array', ['month' => 'October'], false, true, true],
- [null, 'user1', 'app1', 'fast_string', [], false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_string', [], false, false, false, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_string', [], true, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_string', [], true, true, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_string', [], false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_string', [], true, false, false, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_string', [], true, true, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_int', [], false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'fast_int', [], false, false, true, TypeConflictException::class],
- [null, 'user1', 'app1', 'lazy_boolean', [], false, false, true, TypeConflictException::class],
- ];
- }
- /**
- * @dataProvider providerSetValueArray
- */
- public function testSetValueArray(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- array $value,
- bool $lazy,
- bool $sensitive,
- bool $result,
- ?string $exception = null,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- if ($exception !== null) {
- $this->expectException($exception);
- }
- $edited = $userConfig->setValueArray($userId, $app, $key, $value, $lazy, ($sensitive) ? 1 : 0);
- if ($exception !== null) {
- return;
- }
- $this->assertEquals($result, $edited);
- if ($result) {
- $this->assertEqualsCanonicalizing(
- $value, $userConfig->getValueArray($userId, $app, $key, $value, $lazy)
- );
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEqualsCanonicalizing(
- $value, $userConfig->getValueArray($userId, $app, $key, $value, $lazy)
- );
- }
- }
- public function providerUpdateSensitive(): array {
- return [
- [null, 'user1', 'app1', 'key1', false, false],
- [['user1'], 'user1', 'app1', 'key1', false, false],
- [null, 'user1', 'app1', 'key1', true, true],
- [['user1'], 'user1', 'app1', 'key1', true, true],
- ];
- }
- /**
- * @dataProvider providerUpdateSensitive
- */
- public function testUpdateSensitive(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- bool $sensitive,
- bool $result,
- ?string $exception = null,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- if ($exception !== null) {
- $this->expectException($exception);
- }
- $edited = $userConfig->updateSensitive($userId, $app, $key, $sensitive);
- if ($exception !== null) {
- return;
- }
- $this->assertEquals($result, $edited);
- if ($result) {
- $this->assertEquals($sensitive, $userConfig->isSensitive($userId, $app, $key));
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals($sensitive, $userConfig->isSensitive($userId, $app, $key));
- if ($sensitive) {
- $this->assertEquals(true, str_starts_with(
- $userConfig->statusCache()['fastCache'][$userId][$app][$key] ??
- $userConfig->statusCache()['lazyCache'][$userId][$app][$key],
- '$UserConfigEncryption$')
- );
- }
- }
- }
- public function providerUpdateGlobalSensitive(): array {
- return [[true], [false]];
- }
- /**
- * @dataProvider providerUpdateGlobalSensitive
- */
- public function testUpdateGlobalSensitive(bool $sensitive): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $app = 'app2';
- if ($sensitive) {
- $key = 'key2';
- $value = 'value2a';
- } else {
- $key = 'key4';
- $value = 'value4';
- }
- $this->assertEquals($value, $userConfig->getValueString('user1', $app, $key));
- foreach (['user1', 'user2', 'user3', 'user4'] as $userId) {
- $userConfig->getValueString($userId, $app, $key); // cache loading for userId
- $this->assertEquals(
- !$sensitive, str_starts_with(
- $userConfig->statusCache()['fastCache'][$userId][$app][$key] ??
- $userConfig->statusCache()['lazyCache'][$userId][$app][$key],
- '$UserConfigEncryption$'
- )
- );
- }
- $userConfig->updateGlobalSensitive($app, $key, $sensitive);
- $this->assertEquals($value, $userConfig->getValueString('user1', $app, $key));
- foreach (['user1', 'user2', 'user3', 'user4'] as $userId) {
- $this->assertEquals($sensitive, $userConfig->isSensitive($userId, $app, $key));
- // should only work if updateGlobalSensitive drop cache
- $this->assertEquals($sensitive, str_starts_with(
- $userConfig->statusCache()['fastCache'][$userId][$app][$key] ??
- $userConfig->statusCache()['lazyCache'][$userId][$app][$key],
- '$UserConfigEncryption$')
- );
- }
- }
- public function providerUpdateLazy(): array {
- return [
- [null, 'user1', 'app1', 'key1', false, false],
- [['user1'], 'user1', 'app1', 'key1', false, false],
- [null, 'user1', 'app1', 'key1', true, true],
- [['user1'], 'user1', 'app1', 'key1', true, true],
- ];
- }
- /**
- * @dataProvider providerUpdateLazy
- */
- public function testUpdateLazy(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- bool $lazy,
- bool $result,
- ?string $exception = null,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- if ($exception !== null) {
- $this->expectException($exception);
- }
- $edited = $userConfig->updateLazy($userId, $app, $key, $lazy);
- if ($exception !== null) {
- return;
- }
- $this->assertEquals($result, $edited);
- if ($result) {
- $this->assertEquals($lazy, $userConfig->isLazy($userId, $app, $key));
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals($lazy, $userConfig->isLazy($userId, $app, $key));
- }
- }
- public function providerUpdateGlobalLazy(): array {
- return [[true], [false]];
- }
- /**
- * @dataProvider providerUpdateGlobalLazy
- */
- public function testUpdateGlobalLazy(bool $lazy): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $app = 'app2';
- if ($lazy) {
- $key = 'key4';
- $value = 'value4';
- } else {
- $key = 'key3';
- $value = 'value3';
- }
- $this->assertEquals($value, $userConfig->getValueString('user1', $app, $key, '', !$lazy));
- foreach (['user1', 'user2', 'user3', 'user4'] as $userId) {
- $this->assertEquals(!$lazy, $userConfig->isLazy($userId, $app, $key));
- }
- $userConfig->updateGlobalLazy($app, $key, $lazy);
- $this->assertEquals($value, $userConfig->getValueString('user1', $app, $key, '', $lazy));
- foreach (['user1', 'user2', 'user3', 'user4'] as $userId) {
- $this->assertEquals($lazy, $userConfig->isLazy($userId, $app, $key));
- }
- }
- public function providerGetDetails(): array {
- return [
- [
- 'user3', 'app2', 'key2',
- [
- 'userId' => 'user3',
- 'app' => 'app2',
- 'key' => 'key2',
- 'value' => 'value2c',
- 'type' => 0,
- 'lazy' => false,
- 'typeString' => 'mixed',
- 'sensitive' => false
- ]
- ],
- [
- 'user1', 'app1', 'lazy_int',
- [
- 'userId' => 'user1',
- 'app' => 'app1',
- 'key' => 'lazy_int',
- 'value' => 12,
- 'type' => 2,
- 'lazy' => true,
- 'typeString' => 'int',
- 'sensitive' => false
- ]
- ],
- [
- 'user1', 'app1', 'fast_float_sensitive',
- [
- 'userId' => 'user1',
- 'app' => 'app1',
- 'key' => 'fast_float_sensitive',
- 'value' => 1.41,
- 'type' => 3,
- 'lazy' => false,
- 'typeString' => 'float',
- 'sensitive' => true
- ]
- ],
- ];
- }
- /**
- * @dataProvider providerGetDetails
- */
- public function testGetDetails(string $userId, string $app, string $key, array $result): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEqualsCanonicalizing($result, $userConfig->getDetails($userId, $app, $key));
- }
- public function providerDeletePreference(): array {
- return [
- [null, 'user1', 'app1', 'key22'],
- [['user1'], 'user1', 'app1', 'fast_string_sensitive'],
- [null, 'user1', 'app1', 'lazy_array_sensitive'],
- [['user2'], 'user1', 'app1', 'lazy_array_sensitive'],
- [null, 'user2', 'only-lazy', 'key1'],
- [['user2'], 'user2', 'only-lazy', 'key1'],
- ];
- }
- /**
- * @dataProvider providerDeletePreference
- */
- public function testDeletePreference(
- ?array $preload,
- string $userId,
- string $app,
- string $key,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $lazy = $userConfig->isLazy($userId, $app, $key);
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals(true, $userConfig->hasKey($userId, $app, $key, $lazy));
- $userConfig->deleteUserConfig($userId, $app, $key);
- $this->assertEquals(false, $userConfig->hasKey($userId, $app, $key, $lazy));
- $userConfig = $this->generateUserConfig($preload ?? []);
- $this->assertEquals(false, $userConfig->hasKey($userId, $app, $key, $lazy));
- }
- public function providerDeleteKey(): array {
- return [
- [null, 'app2', 'key3'],
- [['user1'], 'app2', 'key3'],
- [null, 'only-lazy', 'key1'],
- [['user2'], 'only-lazy', 'key1'],
- [null, 'app2', 'lazy_string_sensitive'],
- [['user3', 'user1'], 'app2', 'lazy_string_sensitive'],
- ];
- }
- /**
- * @dataProvider providerDeleteKey
- */
- public function testDeleteKey(
- ?array $preload,
- string $app,
- string $key,
- ): void {
- $userConfig = $this->generateUserConfig($preload ?? []);
- $userConfig->deleteKey($app, $key);
- foreach (['user1', 'user2', 'user3', 'user4'] as $userId) {
- $this->assertEquals(false, $userConfig->hasKey($userId, $app, $key, null));
- $userConfigTemp = $this->generateUserConfig($preload ?? []);
- $this->assertEquals(false, $userConfigTemp->hasKey($userId, $app, $key, null));
- }
- }
- public function testDeleteApp(): void {
- $userConfig = $this->generateUserConfig();
- $userConfig->deleteApp('only-lazy');
- foreach (['user1', 'user2', 'user3', 'user4'] as $userId) {
- $this->assertEquals(false, in_array('only-lazy', $userConfig->getApps($userId)));
- $userConfigTemp = $this->generateUserConfig();
- $this->assertEquals(false, in_array('only-lazy', $userConfigTemp->getApps($userId)));
- }
- }
- public function testDeleteAllPreferences(): void {
- $userConfig = $this->generateUserConfig();
- $userConfig->deleteAllUserConfig('user1');
- $this->assertEqualsCanonicalizing([], $userConfig->getApps('user1'));
- $userConfig = $this->generateUserConfig();
- $this->assertEqualsCanonicalizing([], $userConfig->getApps('user1'));
- }
- public function testClearCache(): void {
- $userConfig = $this->generateUserConfig(['user1', 'user2']);
- $userConfig->clearCache('user1');
- $this->assertEquals(true, $userConfig->statusCache()['fastLoaded']['user2']);
- $this->assertEquals(false, $userConfig->statusCache()['fastLoaded']['user1']);
- $this->assertEquals('value2a', $userConfig->getValueString('user1', 'app2', 'key2'));
- $this->assertEquals(false, $userConfig->statusCache()['lazyLoaded']['user1']);
- $this->assertEquals(true, $userConfig->statusCache()['fastLoaded']['user1']);
- }
- public function testClearCacheAll(): void {
- $userConfig = $this->generateUserConfig(['user1', 'user2']);
- $userConfig->clearCacheAll();
- $this->assertEqualsCanonicalizing(
- [
- 'fastLoaded' => [],
- 'fastCache' => [],
- 'lazyLoaded' => [],
- 'lazyCache' => [],
- 'valueTypes' => [],
- ],
- $userConfig->statusCache()
- );
- }
- }
|