ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilChatroomServerSettingsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
27 
31  public static function setterAndGettersProvider(): array
32  {
33  $assertIsString = static function ($actual): void {
34  self::assertIsString($actual, 'The actual return value is not a type of "string"');
35  };
36 
37  $assertIsInteger = static function ($actual): void {
38  self::assertIsInt($actual, 'The actual return value is not a type of "int"');
39  };
40 
41  $assertIsBool = static function ($actual): void {
42  self::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  #[DataProvider('setterAndGettersProvider')]
66  public function testSettersAndGetters(string $property, callable $assertionCallback, $value): void
67  {
68  $setter = 'set' . ucfirst($property);
69  $getter = 'get' . ucfirst(($property));
70 
71  $this->assertTrue(method_exists($this->settings, $setter), sprintf('The Setter "%s" does not exist', $setter));
72  $this->assertTrue(method_exists($this->settings, $getter), sprintf('The Getter "%s" does not exist', $setter));
73 
74  $this->settings->$setter($value);
75  $actual = $this->settings->$getter();
76 
77  $this->assertSame($value, $actual, sprintf('The expected value "%s" is not equals to "%s"', $value, $actual));
78 
79  $assertionCallback($actual);
80  }
81 
82  public function testGetBaseUrl(): void
83  {
84  $protocol = 'http://';
85  $domain = '127.0.0.1';
86  $port = 7373;
87  $expected = sprintf('%s%s:%s', $protocol, $domain, $port);
88 
89  $this->settings->setProtocol($protocol);
90  $this->settings->setDomain($domain);
91  $this->settings->setPort($port);
92 
93  $this->assertSame($expected, $this->settings->getBaseURL());
94  }
95 
96  public function testGenerateClientUrlIfEnabled(): void
97  {
98  $protocol = 'http://';
99  $domain = '127.0.0.1';
100  $clientDomain = 'proxy.localhost';
101  $port = 7373;
102  $expected = sprintf('%s%s:%s', $protocol, $clientDomain, $port);
103 
104  $this->settings->setClientUrlEnabled(true);
105  $this->settings->setProtocol($protocol);
106  $this->settings->setDomain($domain);
107  $this->settings->setPort($port);
108  $this->settings->setClientUrl(sprintf('%s:%s', $clientDomain, $port));
109 
110  $this->assertSame($expected, $this->settings->generateClientUrl());
111  }
112 
113  public function testGenerateClientUrlIfDisabled(): void
114  {
115  $protocol = 'http://';
116  $domain = '127.0.0.1';
117  $clientDomain = 'proxy.localhost';
118  $port = 7373;
119  $expected = sprintf('%s%s:%s', $protocol, $domain, $port);
120 
121  $this->settings->setClientUrlEnabled(false);
122  $this->settings->setDomain($domain);
123  $this->settings->setPort($port);
124  $this->settings->setProtocol($protocol);
125  $this->settings->setClientUrl(sprintf('%s:%s', $clientDomain, $port));
126 
127  $this->assertSame($expected, $this->settings->generateClientUrl());
128  }
129 
130  public function testGenerateIliasUrlIfEnabled(): void
131  {
132  $protocol = 'http://';
133  $domain = '127.0.0.1';
134  $iliasDomain = 'proxy.localhost';
135  $port = 7373;
136  $expected = sprintf('%s%s:%s', $protocol, $iliasDomain, $port);
137 
138  $this->settings->setIliasUrlEnabled(true);
139  $this->settings->setProtocol($protocol);
140  $this->settings->setDomain($domain);
141  $this->settings->setPort($port);
142  $this->settings->setIliasUrl(sprintf('%s:%s', $iliasDomain, $port));
143 
144  $this->assertSame($expected, $this->settings->generateIliasUrl());
145  }
146 
147  public function testGenerateIliasUrlIfDisabled(): void
148  {
149  $protocol = 'http://';
150  $domain = '127.0.0.1';
151  $iliasDomain = 'proxy.localhost';
152  $port = 7373;
153  $expected = sprintf('%s%s:%s', $protocol, $domain, $port);
154 
155  $this->settings->setIliasUrlEnabled(false);
156  $this->settings->setDomain($domain);
157  $this->settings->setPort($port);
158  $this->settings->setProtocol($protocol);
159  $this->settings->setIliasUrl(sprintf('%s:%s', $iliasDomain, $port));
160 
161  $this->assertSame($expected, $this->settings->generateIliasUrl());
162  }
163 
164  public function testGetUrl(): void
165  {
166  $protocol = 'http://';
167  $domain = '127.0.0.1';
168  $iliasDomain = 'proxy.localhost:8080';
169  $port = 7373;
170  $action = 'Heartbeat';
171  $instance = 'master';
172  $scope = 123;
173 
174  $this->settings->setProtocol($protocol);
175  $this->settings->setDomain($domain);
176  $this->settings->setPort($port);
177  $this->settings->setIliasUrl($iliasDomain);
178  $this->settings->setInstance($instance);
179 
180  $this->settings->setIliasUrlEnabled(false);
181  $expected = sprintf(
182  '%s%s:%s%s/%s/%s',
183  $protocol,
184  $domain,
185  $port,
187  $action,
188  $instance
189  );
190  $this->assertSame($expected, $this->settings->getURL($action));
191 
192  $this->settings->setIliasUrlEnabled(false);
193  $expected = sprintf(
194  '%s%s:%s%s/%s/%s/%s',
195  $protocol,
196  $domain,
197  $port,
199  $action,
200  $instance,
201  $scope
202  );
203  $this->assertSame($expected, $this->settings->getURL($action, $scope));
204 
205  $this->settings->setIliasUrlEnabled(true);
206  $expected = sprintf(
207  '%s%s%s/%s/%s',
208  $protocol,
209  $iliasDomain,
211  $action,
212  $instance
213  );
214  $this->assertSame($expected, $this->settings->getURL($action));
215 
216  $this->settings->setIliasUrlEnabled(true);
217  $expected = sprintf(
218  '%s%s%s/%s/%s/%s',
219  $protocol,
220  $iliasDomain,
222  $action,
223  $instance,
224  $scope
225  );
226  $this->assertSame($expected, $this->settings->getURL($action, $scope));
227  }
228 
229  protected function setUp(): void
230  {
231  parent::setUp();
232 
233  $this->settings = new ilChatroomServerSettings();
234  }
235 }
$scope
Definition: ltiregstart.php:47
testSettersAndGetters(string $property, callable $assertionCallback, $value)