1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FilteredTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_input\Filtered; |
8
|
|
|
use kalanis\kw_input\Interfaces; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class EntryArraysTest extends CommonTestClass |
12
|
|
|
{ |
13
|
|
|
public function testProcess(): void |
14
|
|
|
{ |
15
|
|
|
$variables = new Filtered\EntryArrays([ |
16
|
|
|
ExEntry::init(Interfaces\IEntry::SOURCE_GET, 'foo', 'val1'), |
17
|
|
|
ExEntry::init(Interfaces\IEntry::SOURCE_GET, 'bar', ['bal1', 'bal2']), |
18
|
|
|
ExEntry::init(Interfaces\IEntry::SOURCE_GET, 'baz', true), |
19
|
|
|
ExEntry::init(Interfaces\IEntry::SOURCE_GET, 'aff', 42), |
20
|
|
|
ExEntry::init(Interfaces\IEntry::SOURCE_EXTERNAL, 'uhb', 'feaht'), |
21
|
|
|
]); |
22
|
|
|
|
23
|
|
|
/** @var Interfaces\IEntry[] $entries */ |
24
|
|
|
$entries = $variables->getInArray(null, [Interfaces\IEntry::SOURCE_GET]); |
25
|
|
|
$input = new Filtered\FilterAdapter($variables, [Interfaces\IEntry::SOURCE_GET]); |
26
|
|
|
$this->assertNotEmpty(iterator_to_array($input->getIterator())); |
27
|
|
|
$this->assertNotEmpty(count($entries)); |
28
|
|
|
|
29
|
|
|
$this->assertTrue(isset($entries['foo'])); |
30
|
|
|
$this->assertEquals('foo', $entries['foo']->getKey()); |
31
|
|
|
$this->assertEquals('val1', $entries['foo']->getValue()); |
32
|
|
|
$this->assertEquals(Interfaces\IEntry::SOURCE_GET, $entries['foo']->getSource()); |
33
|
|
|
|
34
|
|
|
$this->assertTrue($input->offsetExists('bar')); |
35
|
|
|
$this->assertEquals('bar', $input->offsetGet('bar')->getKey()); |
36
|
|
|
$this->assertEquals(['bal1', 'bal2'], $input->offsetGet('bar')->getValue()); |
37
|
|
|
$this->assertEquals(Interfaces\IEntry::SOURCE_GET, $input->offsetGet('bar')->getSource()); |
38
|
|
|
|
39
|
|
|
$this->assertTrue(isset($input->baz)); |
|
|
|
|
40
|
|
|
$this->assertEquals('baz', $input->baz->getKey()); |
|
|
|
|
41
|
|
|
$this->assertEquals(true, $input->baz->getValue()); |
42
|
|
|
$this->assertEquals(Interfaces\IEntry::SOURCE_GET, $input->baz->getSource()); |
43
|
|
|
|
44
|
|
|
$this->assertTrue($input->offsetExists('aff')); |
45
|
|
|
$this->assertEquals('aff', $input->offsetGet('aff')->getKey()); |
46
|
|
|
$this->assertEquals(42, $input->offsetGet('aff')->getValue()); |
47
|
|
|
$this->assertEquals(Interfaces\IEntry::SOURCE_GET, $input->offsetGet('aff')->getSource()); |
48
|
|
|
|
49
|
|
|
$this->assertFalse($input->offsetExists('uhb')); |
50
|
|
|
$input->offsetSet('uhb', 'feaht'); |
51
|
|
|
$this->assertEquals('feaht', $input->offsetGet('uhb')->getValue()); |
52
|
|
|
$this->assertEquals(Interfaces\IEntry::SOURCE_EXTERNAL, $input->offsetGet('uhb')->getSource()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|