ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
WrapperTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace ILIAS\HTTP;
4 
7 
8 /******************************************************************************
9  *
10  * This file is part of ILIAS, a powerful learning management system.
11  *
12  * ILIAS is licensed with the GPL-3.0, you should have received a copy
13  * of said license along with the source code.
14  *
15  * If this is not the case or you just want to try ILIAS, you'll find
16  * us at:
17  * https://www.ilias.de
18  * https://github.com/ILIAS-eLearning
19  *
20  *****************************************************************************/
26 {
27  protected Factory $refinery;
28  protected array $get = ['key_one' => 1, 'key_two' => 2];
29  protected array $post = ['key_one' => 1, 'key_two' => 2];
30  protected array $cookie = ['key_one' => 1, 'key_two' => 2];
31 
35  protected function setUp(): void
36  {
37  parent::setUp();
38  $language = $this->getMockBuilder('\ilLanguage')
39  ->disableOriginalConstructor()
40  ->getMock();
41 
42  $this->refinery = new Factory(new \ILIAS\Data\Factory(), $language);
43  }
44 
45 
46  public function testWrapperfactory(): void
47  {
48  $wrapper_factory = new WrapperFactory($this->request_interface);
49 
50  // Query
51  $this->request_interface->expects($this->once())
52  ->method('getQueryParams')
53  ->willReturn([]);
54 
55  $wrapper_factory->query();
56 
57  // Post
58  $this->request_interface->expects($this->once())
59  ->method('getParsedBody')
60  ->willReturn([]);
61 
62  $wrapper_factory->post();
63 
64  // Cookie
65  $this->request_interface->expects($this->once())
66  ->method('getCookieParams')
67  ->willReturn([]);
68 
69  $wrapper_factory->cookie();
70  }
71 
72  public function testQuery(): void
73  {
74  $wrapper_factory = new WrapperFactory($this->request_interface);
75 
76  $this->request_interface->expects($this->once())
77  ->method('getQueryParams')
78  ->willReturn($this->get);
79 
80  $query = $wrapper_factory->query();
81 
82  $this->assertTrue($query->has('key_one'));
83  $this->assertTrue($query->has('key_two'));
84  $this->assertFalse($query->has('key_three'));
85  $this->assertEquals(['key_one', 'key_two'], $query->keys());
86 
87  $string_trafo = $this->refinery->kindlyTo()->string();
88  $int_trafo = $this->refinery->kindlyTo()->int();
89 
90  $this->assertEquals("1", $query->retrieve('key_one', $string_trafo));
91  $this->assertIsString($query->retrieve('key_one', $string_trafo));
92 
93  $this->assertEquals(1, $query->retrieve('key_one', $string_trafo));
94  $this->assertIsInt($query->retrieve('key_one', $int_trafo));
95  }
96 
97  public function testPost(): void
98  {
99  $wrapper_factory = new WrapperFactory($this->request_interface);
100 
101  $this->request_interface->expects($this->once())
102  ->method('getParsedBody')
103  ->willReturn($this->post);
104 
105  $post = $wrapper_factory->post();
106 
107  $this->assertTrue($post->has('key_one'));
108  $this->assertTrue($post->has('key_two'));
109  $this->assertFalse($post->has('key_three'));
110  $this->assertEquals(['key_one', 'key_two'], $post->keys());
111 
112  $string_trafo = $this->refinery->kindlyTo()->string();
113  $int_trafo = $this->refinery->kindlyTo()->int();
114 
115  $this->assertEquals("1", $post->retrieve('key_one', $string_trafo));
116  $this->assertIsString($post->retrieve('key_one', $string_trafo));
117 
118  $this->assertEquals(1, $post->retrieve('key_one', $string_trafo));
119  $this->assertIsInt($post->retrieve('key_one', $int_trafo));
120  }
121 
122  public function testCookie(): void
123  {
124  $wrapper_factory = new WrapperFactory($this->request_interface);
125 
126  $this->request_interface->expects($this->once())
127  ->method('getCookieParams')
128  ->willReturn($this->cookie);
129 
130  $cookie = $wrapper_factory->cookie();
131 
132  $this->assertTrue($cookie->has('key_one'));
133  $this->assertTrue($cookie->has('key_two'));
134  $this->assertFalse($cookie->has('key_three'));
135  $this->assertEquals(['key_one', 'key_two'], $cookie->keys());
136 
137  $string_trafo = $this->refinery->kindlyTo()->string();
138  $int_trafo = $this->refinery->kindlyTo()->int();
139 
140  $this->assertEquals("1", $cookie->retrieve('key_one', $string_trafo));
141  $this->assertIsString($cookie->retrieve('key_one', $string_trafo));
142 
143  $this->assertEquals(1, $cookie->retrieve('key_one', $string_trafo));
144  $this->assertIsInt($cookie->retrieve('key_one', $int_trafo));
145  }
146 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
array array array $cookie
Definition: WrapperTest.php:30
Interface Observer Contains several chained tasks and infos about them.
array array array setUp()
Definition: WrapperTest.php:35
Class WrapperTest.
Definition: WrapperTest.php:25