19declare(strict_types=1);
38use PHPUnit\Framework\Attributes\BackupGlobals;
39use PHPUnit\Framework\Attributes\DataProvider;
40use PHPUnit\Framework\TestCase;
49 protected function setUp(): void
52 $language = $this->getMockBuilder(\ilLanguage::class)
53 ->disableOriginalConstructor()
62 $subjects = $this->createStub(AuthenticatedSubjectResolver::class);
63 $subjects->method(
'supportsPersistentStorage')->willReturn(
false);
64 $services = $this->createMock(Services::class);
65 $services->method(
'session')->willReturn($store);
66 $services->expects($this->never())->method(
'persistentFor');
72 $this->assertFalse($this->adapter->offsetExists(
'view_state'));
74 $this->adapter->offsetSet(
'view_state', [
'sort' =>
'title',
'page' => 2]);
76 $this->assertTrue($this->adapter->offsetExists(
'view_state'));
77 $this->assertSame([
'sort' =>
'title',
'page' => 2], $this->adapter->offsetGet(
'view_state'));
82 $this->adapter->offsetSet(
'view_state', [
'page' => 2]);
84 $this->adapter->offsetUnset(
'view_state');
86 $this->assertFalse($this->adapter->offsetExists(
'view_state'));
87 $this->assertNull($this->adapter->offsetGet(
'view_state'));
94 #[DataProvider('storageIdsUsedByTheUi')]
97 $this->adapter->offsetSet($storage_id, [
'sort' =>
'title']);
99 $this->assertSame([
'sort' =>
'title'], $this->adapter->offsetGet($storage_id));
108 'data table' => [Data::STORAGE_ID_PREFIX .
'my_table'],
116 $this->expectException(\InvalidArgumentException::class);
117 $this->expectExceptionMessage(
'Offset needs to be of type string.');
119 $this->adapter->offsetExists(42);
124 $store = $this->createMock(Store::class);
125 $store->expects($this->once())->method(
'has')->with(
'view_state')->willReturn(
true);
126 $subjects = $this->createStub(AuthenticatedSubjectResolver::class);
127 $subjects->method(
'supportsPersistentStorage')->willReturn(
true);
128 $services = $this->createMock(Services::class);
129 $services->expects($this->once())
130 ->method(
'persistentFor')
131 ->with($subjects, [
'ui',
'storage'])
132 ->willReturn($store);
133 $services->expects($this->never())->method(
'session');
140 $store = $this->createMock(Store::class);
141 $store->expects($this->once())->method(
'has')->with(
'view_state')->willReturn(
false);
142 $subjects = $this->createStub(AuthenticatedSubjectResolver::class);
143 $subjects->method(
'supportsPersistentStorage')->willReturn(
false);
144 $services = $this->createMock(Services::class);
145 $services->expects($this->once())->method(
'session')->with([
'ui',
'storage'])->willReturn($store);
146 $services->expects($this->never())->method(
'persistentFor');
153 $subjects = $this->createMock(AuthenticatedSubjectResolver::class);
154 $subjects->expects($this->never())->method(
'supportsPersistentStorage');
155 $services = $this->createMock(Services::class);
156 $services->expects($this->never())->method($this->anything());
166 $session_store = $this->createMock(Store::class);
167 $session_store->expects($this->once())->method(
'set')->with(
'view_state', [
'page' => 1]);
168 $persistent_store = $this->createMock(Store::class);
169 $persistent_store->expects($this->once())->method(
'set')->with(
'view_state', [
'page' => 2]);
170 $subjects = $this->createStub(AuthenticatedSubjectResolver::class);
171 $subjects->method(
'supportsPersistentStorage')->willReturnOnConsecutiveCalls(
false,
true);
172 $services = $this->createStub(Services::class);
173 $services->method(
'session')->willReturn($session_store);
174 $services->method(
'persistentFor')->willReturn($persistent_store);
177 $adapter->
offsetSet(
'view_state', [
'page' => 1]);
183 $store = $this->createMock(Store::class);
184 $store->expects($this->once())
188 $this->callback(
static function (
Transformation $transformation):
bool {
189 return $transformation->
transform([
'sort' =>
'title']) === [
'sort' =>
'title']
190 && $transformation->
transform(
null) ===
null;
193 ->willReturn([
'sort' =>
'title']);
194 $subjects = $this->createStub(AuthenticatedSubjectResolver::class);
195 $subjects->method(
'supportsPersistentStorage')->willReturn(
false);
196 $services = $this->createStub(Services::class);
197 $services->method(
'session')->willReturn($store);
Keeps key-value storage in the ILIAS session.
Adapts key-value storage to the UI ArrayAccess contract.
offsetSet(mixed $offset, mixed $value)
The rules every storage key has to follow.
A store bound to one namespace of one repository.
Isolates the keys of one consumer from every other consumer of a storage.
Translates between the values a consumer works with and the strings a repository stores.
testALoginAfterTheAdapterWasBuiltSwitchesToThePersistentStore()
The adapter may be built before the user logs in within the same request.
testAFullyAuthenticatedUserUsesThePersistentSubjectStore()
static storageIdsUsedByTheUi()
UiStorageAdapter $adapter
testOffsetGetPassesTheIdentityTransformation()
testAnAnonymousActorUsesTheSessionStore()
testNoStoreIsChosenWhileTheAdapterIsBuilt()
testANonStringOffsetIsRejected()
testAViewStateSurvivesAWriteAndReadCycle()
testTheStorageIdsOfTheUiAreAccepted(string $storage_id)
The UI builds its storage ids from class names, so the storage has to accept backslashes.
testUnsetRemovesTheEntry()
Resolves the current fully authenticated ILIAS user to a KeyValueStorage subject.
Entry point to the namespace-scoped key-value storages of ILIAS.
Key-value store scoped to one namespace.