ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
StateTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2020 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
7 
8 class StateTest extends TestCase
9 {
10  public function testGetNullValue()
11  {
12  $state = new State();
13  $this->assertNull($state->getValueFor('invalid_key'));
14  return $state;
15  }
16 
20  public function testValue(State $state)
21  {
22  $key = 'key';
23  $value = 'value';
24  $state = $state->withValueFor($key, $value);
25  $this->assertEquals($value, $state->getValueFor($key));
26  return $state;
27  }
28 
32  public function testSerialize(State $state)
33  {
34  $expected = json_encode(['key' => 'value']);
35  $this->assertEquals($expected, $state->serialize());
36  }
37 
41  public function testRemoveValue(State $state)
42  {
43  $state = $state->withValueFor('keep', 'this');
44  $state = $state->withoutKey('key');
45  $expected = json_encode(['keep' => 'this']);
46  $this->assertEquals($expected, $state->serialize());
47  }
48 }
withValueFor(string $key, string $value)
Set a value for a key of the state.
Definition: State.php:20
getValueFor(string $key)
Get the value for the given key.
Definition: State.php:40
testValue(State $state)
testGetNullValue
Definition: StateTest.php:20
testGetNullValue()
Definition: StateTest.php:10
testSerialize(State $state)
testValue
Definition: StateTest.php:32
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:9
serialize()
Get the key-value store as string.
Definition: State.php:51
testRemoveValue(State $state)
testValue
Definition: StateTest.php:41
withoutKey(string $key)
Remove the key-value-pair.
Definition: State.php:30