ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
WrapperTest.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\HTTP;
20
23
29{
30 protected Factory $refinery;
31 protected array $get = ['key_one' => 1, 'key_two' => 2];
32 protected array $post = ['key_one' => 1, 'key_two' => 2];
33 protected array $cookie = ['key_one' => 1, 'key_two' => 2];
34
38 #[\Override]
39 protected function setUp(): void
40 {
41 parent::setUp();
42 $language = $this->getMockBuilder('\ilLanguage')
43 ->disableOriginalConstructor()
44 ->getMock();
45
46 $this->refinery = new Factory(new \ILIAS\Data\Factory(), $language);
47 }
48
49
50 public function testWrapperfactory(): void
51 {
52 $wrapper_factory = new WrapperFactory($this->request_interface);
53
54 // Query
55 $this->request_interface->expects($this->once())
56 ->method('getQueryParams')
57 ->willReturn([]);
58
59 $wrapper_factory->query();
60
61 // Post
62 $this->request_interface->expects($this->once())
63 ->method('getParsedBody')
64 ->willReturn([]);
65
66 $wrapper_factory->post();
67
68 // Cookie
69 $this->request_interface->expects($this->once())
70 ->method('getCookieParams')
71 ->willReturn([]);
72
73 $wrapper_factory->cookie();
74 }
75
76 public function testQuery(): void
77 {
78 $wrapper_factory = new WrapperFactory($this->request_interface);
79
80 $this->request_interface->expects($this->once())
81 ->method('getQueryParams')
82 ->willReturn($this->get);
83
84 $query = $wrapper_factory->query();
85
86 $this->assertTrue($query->has('key_one'));
87 $this->assertTrue($query->has('key_two'));
88 $this->assertFalse($query->has('key_three'));
89 $this->assertSame(['key_one', 'key_two'], $query->keys());
90
91 $string_trafo = $this->refinery->kindlyTo()->string();
92 $int_trafo = $this->refinery->kindlyTo()->int();
93
94 $this->assertEquals("1", $query->retrieve('key_one', $string_trafo));
95 $this->assertIsString($query->retrieve('key_one', $string_trafo));
96
97 $this->assertEquals(1, $query->retrieve('key_one', $string_trafo));
98 $this->assertIsInt($query->retrieve('key_one', $int_trafo));
99 }
100
101 public function testPost(): void
102 {
103 $wrapper_factory = new WrapperFactory($this->request_interface);
104
105 $this->request_interface->expects($this->once())
106 ->method('getParsedBody')
107 ->willReturn($this->post);
108
109 $post = $wrapper_factory->post();
110
111 $this->assertTrue($post->has('key_one'));
112 $this->assertTrue($post->has('key_two'));
113 $this->assertFalse($post->has('key_three'));
114 $this->assertSame(['key_one', 'key_two'], $post->keys());
115
116 $string_trafo = $this->refinery->kindlyTo()->string();
117 $int_trafo = $this->refinery->kindlyTo()->int();
118
119 $this->assertEquals("1", $post->retrieve('key_one', $string_trafo));
120 $this->assertIsString($post->retrieve('key_one', $string_trafo));
121
122 $this->assertEquals(1, $post->retrieve('key_one', $string_trafo));
123 $this->assertIsInt($post->retrieve('key_one', $int_trafo));
124 }
125
126 public function testCookie(): void
127 {
128 $wrapper_factory = new WrapperFactory($this->request_interface);
129
130 $this->request_interface->expects($this->once())
131 ->method('getCookieParams')
132 ->willReturn($this->cookie);
133
134 $cookie = $wrapper_factory->cookie();
135
136 $this->assertTrue($cookie->has('key_one'));
137 $this->assertTrue($cookie->has('key_two'));
138 $this->assertFalse($cookie->has('key_three'));
139 $this->assertSame(['key_one', 'key_two'], $cookie->keys());
140
141 $string_trafo = $this->refinery->kindlyTo()->string();
142 $int_trafo = $this->refinery->kindlyTo()->int();
143
144 $this->assertEquals("1", $cookie->retrieve('key_one', $string_trafo));
145 $this->assertIsString($cookie->retrieve('key_one', $string_trafo));
146
147 $this->assertEquals(1, $cookie->retrieve('key_one', $string_trafo));
148 $this->assertIsInt($cookie->retrieve('key_one', $int_trafo));
149 }
150}
Builds data types.
Definition: Factory.php:36
Class WrapperTest.
Definition: WrapperTest.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.