ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
StackedInputDataTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use PHPUnit\Framework\TestCase;
26use LogicException;
27
31class StackedInputDataTest extends TestCase
32{
34
35 public function setUp(): void
36 {
37 $input_a = new ArrayInputData([ "in_a" => "a", "in_both" => "a"]);
38 $input_b = new ArrayInputData([ "in_b" => "b", "in_both" => "b"]);
39 $this->input = new StackedInputData($input_a, $input_b);
40 }
41
42 public function testInvalidKeyWithoutDefault(): void
43 {
44 $test_key = 'test_key_1';
45 $this->expectException(LogicException::class);
46 $this->expectExceptionMessage("'$test_key' is not contained in stack of input.");
47 $this->input->get($test_key);
48 }
49
50 public function testInvalidKeyWithDefault(): void
51 {
52 $test_key = 'test_key_1';
53 $expected_value = 'expected_value_1';
54 $this->assertEquals(
55 $expected_value,
56 $this->input->getOr($test_key, $expected_value)
57 );
58 }
59
60 public function testInFirstOnly(): void
61 {
62 $this->assertEquals("a", $this->input->get("in_a"));
63 }
64
65 public function testInFirstOnlyWithDefault(): void
66 {
67 $this->assertEquals("a", $this->input->getOr("in_a", "default"));
68 }
69
70 public function testInSecondOnly(): void
71 {
72 $this->assertEquals("b", $this->input->get("in_b"));
73 }
74
75 public function testInSecondOnlyWithDefault(): void
76 {
77 $this->assertEquals("b", $this->input->getOr("in_b", "default"));
78 }
79
80 public function testInBothOnly(): void
81 {
82 $this->assertEquals("a", $this->input->get("in_both"));
83 }
84
85 public function testInBothOnlyWithDefault(): void
86 {
87 $this->assertEquals("a", $this->input->getOr("in_both", "default"));
88 }
89}
Implements interaction of input element with get data from psr-7 server request.