ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilChatroomServerSettingsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 class ilChatroomServerSettingsTest extends TestCase
28 {
30 
31  public function setterAndGettersProvider(): array
32  {
33  $assertIsString = function ($actual): void {
34  $this->assertIsString($actual, 'The actual return value is not a type of "string"');
35  };
36 
37  $assertIsInteger = function ($actual): void {
38  $this->assertIsInt($actual, 'The actual return value is not a type of "int"');
39  };
40 
41  $assertIsBool = function ($actual): void {
42  $this->assertIsBool($actual, 'The actual return value is not a type of "bool"');
43  };
44 
45  return [
46  ['port', $assertIsInteger, 7373],
47  ['protocol', $assertIsString, 'http://'],
48  ['domain', $assertIsString, '127.0.0.1'],
49 
50  ['authKey', $assertIsString, 'cfdf79fc-4133-4f3b-882f-5162a87dc465'],
51  ['authSecret', $assertIsString, 'f8072a49-0488-411f-be0a-723a762700ba'],
52  ['clientUrlEnabled', $assertIsBool, true],
53  ['clientUrl', $assertIsString, 'http://proxy.localhost'],
54  ['iliasUrlEnabled', $assertIsBool, true],
55  ['iliasUrl', $assertIsString, 'http://proxy.localhost'],
56  //@TODO Remove this properties
57  ['instance', $assertIsString, '123456'],
58  ];
59  }
60 
65  public function testSettersAndGetters(string $property, callable $assertionCallback, $value): void
66  {
67  $setter = 'set' . ucfirst($property);
68  $getter = 'get' . ucfirst(($property));
69 
70  $this->assertTrue(method_exists($this->settings, $setter), sprintf('The Setter "%s" does not exist', $setter));
71  $this->assertTrue(method_exists($this->settings, $getter), sprintf('The Getter "%s" does not exist', $setter));
72 
73  $this->settings->$setter($value);
74  $actual = $this->settings->$getter();
75 
76  $this->assertSame($value, $actual, sprintf('The expected value "%s" is not equals to "%s"', $value, $actual));
77 
78  $assertionCallback($actual);
79  }
80 
81  public function testGetBaseUrl(): void
82  {
83  $protocol = 'http://';
84  $domain = '127.0.0.1';
85  $port = 7373;
86  $expected = sprintf('%s%s:%s', $protocol, $domain, $port);
87 
88  $this->settings->setProtocol($protocol);
89  $this->settings->setDomain($domain);
90  $this->settings->setPort($port);
91 
92  $this->assertSame($expected, $this->settings->getBaseURL());
93  }
94 
95  public function testGenerateClientUrlIfEnabled(): void
96  {
97  $protocol = 'http://';
98  $domain = '127.0.0.1';
99  $clientDomain = 'proxy.localhost';
100  $port = 7373;
101  $expected = sprintf('%s%s:%s', $protocol, $clientDomain, $port);
102 
103  $this->settings->setClientUrlEnabled(true);
104  $this->settings->setProtocol($protocol);
105  $this->settings->setDomain($domain);
106  $this->settings->setPort($port);
107  $this->settings->setClientUrl(sprintf('%s:%s', $clientDomain, $port));
108 
109  $this->assertSame($expected, $this->settings->generateClientUrl());
110  }
111 
112  public function testGenerateClientUrlIfDisabled(): void
113  {
114  $protocol = 'http://';
115  $domain = '127.0.0.1';
116  $clientDomain = 'proxy.localhost';
117  $port = 7373;
118  $expected = sprintf('%s%s:%s', $protocol, $domain, $port);
119 
120  $this->settings->setClientUrlEnabled(false);
121  $this->settings->setDomain($domain);
122  $this->settings->setPort($port);
123  $this->settings->setProtocol($protocol);
124  $this->settings->setClientUrl(sprintf('%s:%s', $clientDomain, $port));
125 
126  $this->assertSame($expected, $this->settings->generateClientUrl());
127  }
128 
129  public function testGenerateIliasUrlIfEnabled(): void
130  {
131  $protocol = 'http://';
132  $domain = '127.0.0.1';
133  $iliasDomain = 'proxy.localhost';
134  $port = 7373;
135  $expected = sprintf('%s%s:%s', $protocol, $iliasDomain, $port);
136 
137  $this->settings->setIliasUrlEnabled(true);
138  $this->settings->setProtocol($protocol);
139  $this->settings->setDomain($domain);
140  $this->settings->setPort($port);
141  $this->settings->setIliasUrl(sprintf('%s:%s', $iliasDomain, $port));
142 
143  $this->assertSame($expected, $this->settings->generateIliasUrl());
144  }
145 
146  public function testGenerateIliasUrlIfDisabled(): void
147  {
148  $protocol = 'http://';
149  $domain = '127.0.0.1';
150  $iliasDomain = 'proxy.localhost';
151  $port = 7373;
152  $expected = sprintf('%s%s:%s', $protocol, $domain, $port);
153 
154  $this->settings->setIliasUrlEnabled(false);
155  $this->settings->setDomain($domain);
156  $this->settings->setPort($port);
157  $this->settings->setProtocol($protocol);
158  $this->settings->setIliasUrl(sprintf('%s:%s', $iliasDomain, $port));
159 
160  $this->assertSame($expected, $this->settings->generateIliasUrl());
161  }
162 
163  public function testGetUrl(): void
164  {
165  $protocol = 'http://';
166  $domain = '127.0.0.1';
167  $iliasDomain = 'proxy.localhost:8080';
168  $port = 7373;
169  $action = 'Heartbeat';
170  $instance = 'master';
171  $scope = 123;
172 
173  $this->settings->setProtocol($protocol);
174  $this->settings->setDomain($domain);
175  $this->settings->setPort($port);
176  $this->settings->setIliasUrl($iliasDomain);
177  $this->settings->setInstance($instance);
178 
179  $this->settings->setIliasUrlEnabled(false);
180  $expected = sprintf(
181  '%s%s:%s%s/%s/%s',
182  $protocol,
183  $domain,
184  $port,
186  $action,
187  $instance
188  );
189  $this->assertSame($expected, $this->settings->getURL($action));
190 
191  $this->settings->setIliasUrlEnabled(false);
192  $expected = sprintf(
193  '%s%s:%s%s/%s/%s/%s',
194  $protocol,
195  $domain,
196  $port,
198  $action,
199  $instance,
200  $scope
201  );
202  $this->assertSame($expected, $this->settings->getURL($action, $scope));
203 
204  $this->settings->setIliasUrlEnabled(true);
205  $expected = sprintf(
206  '%s%s%s/%s/%s',
207  $protocol,
208  $iliasDomain,
210  $action,
211  $instance
212  );
213  $this->assertSame($expected, $this->settings->getURL($action));
214 
215  $this->settings->setIliasUrlEnabled(true);
216  $expected = sprintf(
217  '%s%s%s/%s/%s/%s',
218  $protocol,
219  $iliasDomain,
221  $action,
222  $instance,
223  $scope
224  );
225  $this->assertSame($expected, $this->settings->getURL($action, $scope));
226  }
227 
228  protected function setUp(): void
229  {
230  parent::setUp();
231 
232  $this->settings = new ilChatroomServerSettings();
233  }
234 }
$scope
Definition: ltiregstart.php:53
Class ilChatroomServerSettings.
Class ilChatroomServerSettingsTest.
testSettersAndGetters(string $property, callable $assertionCallback, $value)