ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
WrapperTest.php
Go to the documentation of this file.
1<?php
2
3namespace ILIAS\HTTP;
4
6require_once "AbstractBaseTest.php";
9
10/******************************************************************************
11 *
12 * This file is part of ILIAS, a powerful learning management system.
13 *
14 * ILIAS is licensed with the GPL-3.0, you should have received a copy
15 * of said license along with the source code.
16 *
17 * If this is not the case or you just want to try ILIAS, you'll find
18 * us at:
19 * https://www.ilias.de
20 * https://github.com/ILIAS-eLearning
21 *
22 *****************************************************************************/
28{
29 protected Factory $refinery;
30 protected array $get = ['key_one' => 1, 'key_two' => 2];
31 protected array $post = ['key_one' => 1, 'key_two' => 2];
32 protected array $cookie = ['key_one' => 1, 'key_two' => 2];
33
37 protected function setUp(): void
38 {
39 parent::setUp();
40 $language = $this->getMockBuilder('\ilLanguage')
41 ->disableOriginalConstructor()
42 ->getMock();
43
44 $this->refinery = new Factory(new \ILIAS\Data\Factory(), $language);
45 }
46
47
48 public function testWrapperfactory(): void
49 {
50 $wrapper_factory = new WrapperFactory($this->request_interface);
51
52 // Query
53 $this->request_interface->expects($this->once())
54 ->method('getQueryParams')
55 ->willReturn([]);
56
57 $wrapper_factory->query();
58
59 // Post
60 $this->request_interface->expects($this->once())
61 ->method('getParsedBody')
62 ->willReturn([]);
63
64 $wrapper_factory->post();
65
66 // Cookie
67 $this->request_interface->expects($this->once())
68 ->method('getCookieParams')
69 ->willReturn([]);
70
71 $wrapper_factory->cookie();
72 }
73
74 public function testQuery(): void
75 {
76 $wrapper_factory = new WrapperFactory($this->request_interface);
77
78 $this->request_interface->expects($this->once())
79 ->method('getQueryParams')
80 ->willReturn($this->get);
81
82 $query = $wrapper_factory->query();
83
84 $this->assertTrue($query->has('key_one'));
85 $this->assertTrue($query->has('key_two'));
86 $this->assertFalse($query->has('key_three'));
87
88 $string_trafo = $this->refinery->kindlyTo()->string();
89 $int_trafo = $this->refinery->kindlyTo()->int();
90
91 $this->assertEquals("1", $query->retrieve('key_one', $string_trafo));
92 $this->assertIsString($query->retrieve('key_one', $string_trafo));
93
94 $this->assertEquals(1, $query->retrieve('key_one', $string_trafo));
95 $this->assertIsInt($query->retrieve('key_one', $int_trafo));
96 }
97
98 public function testPost(): void
99 {
100 $wrapper_factory = new WrapperFactory($this->request_interface);
101
102 $this->request_interface->expects($this->once())
103 ->method('getParsedBody')
104 ->willReturn($this->post);
105
106 $post = $wrapper_factory->post();
107
108 $this->assertTrue($post->has('key_one'));
109 $this->assertTrue($post->has('key_two'));
110 $this->assertFalse($post->has('key_three'));
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
136 $string_trafo = $this->refinery->kindlyTo()->string();
137 $int_trafo = $this->refinery->kindlyTo()->int();
138
139 $this->assertEquals("1", $cookie->retrieve('key_one', $string_trafo));
140 $this->assertIsString($cookie->retrieve('key_one', $string_trafo));
141
142 $this->assertEquals(1, $cookie->retrieve('key_one', $string_trafo));
143 $this->assertIsInt($cookie->retrieve('key_one', $int_trafo));
144 }
145}
Builds data types.
Definition: Factory.php:21
Class AbstractBaseTest.
Class WrapperTest.
Definition: WrapperTest.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
$query