ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilChatroomServerSettingsTest.php
Go to the documentation of this file.
1 <?php
2 
8 {
12  protected $settings;
13 
14  protected function setUp()
15  {
16  if(defined('ILIAS_PHPUNIT_CONTEXT'))
17  {
18  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
19  ilUnitUtil::performInitialisation();
20  }
21  else
22  {
23  chdir(dirname(__FILE__));
24  chdir('../../../');
25  }
26 
27  require_once './Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
28  $this->settings = new ilChatroomServerSettings();
29  }
30 
31  public function testConstructor()
32  {
33  $this->assertInstanceOf('ilChatroomServerSettings', $this->settings);
34  }
35 
36  public function setterAndGettersProvider()
37  {
38  return array(
39  array('port', 'integer', 7373),
40  array('protocol', 'string', 'http://'), //@todo Remove :// from protocol
41  array('domain', 'string', '127.0.0.1'),
42 
43  array('authKey', 'string', 'cfdf79fc-4133-4f3b-882f-5162a87dc465'),
44  array('authSecret', 'string', 'f8072a49-0488-411f-be0a-723a762700ba'),
45  array('clientUrlEnabled', 'boolean', true),
46  array('clientUrl', 'string', 'http://proxy.localhost'),
47  array('iliasUrlEnabled', 'boolean', true),
48  array('iliasUrl', 'string', 'http://proxy.localhost'),
49  array('smiliesEnabled', 'boolean', false),
50 
51  //@TODO Remove this properties
52  array('instance', 'string', '123456'),
53  );
54  }
55 
62  public function testSettersAndGetters($property, $type, $value)
63  {
64  $setter = 'set' . ucfirst($property);
65  $getter = 'get' . ucfirst(($property));
66 
67  $this->assertTrue(method_exists($this->settings, $setter), sprintf('The Setter "%s" does not exist', $setter));
68  $this->assertTrue(method_exists($this->settings, $getter), sprintf('The Getter "%s" does not exist', $setter));
69 
70  $this->settings->$setter($value);
71  $actual = $this->settings->$getter();
72 
73  $this->assertEquals($value, $actual, sprintf('The expected value "%s" is not equals to "%s"', $value, $actual));
74 
75  if(class_exists($type))
76  {
77  $this->assertInstanceOf(
78  $type,
79  $actual,
80  sprintf('The actual return value is not an instance of "%s"', $type)
81  );
82  }
83  else
84  {
85  $this->assertInternalType($type, $actual, sprintf('The actual return value is not a type of "%s"', $type));
86  }
87  }
88 
89  public function testGetBaseUrl()
90  {
91  $protocol = 'http://';
92  $domain = '127.0.0.1';
93  $port = '7373';
94  $expected = sprintf('%s%s:%s', $protocol, $domain, $port);
95 
96  $this->settings->setProtocol($protocol);
97  $this->settings->setDomain($domain);
98  $this->settings->setPort($port);
99 
100  $this->assertEquals($expected, $this->settings->getBaseURL());
101  }
102 
104  {
105  $protocol = 'http://';
106  $domain = '127.0.0.1';
107  $clientDomain = 'proxy.localhost';
108  $port = '7373';
109  $expected = sprintf('%s%s:%s', $protocol, $clientDomain, $port);
110 
111  $this->settings->setClientUrlEnabled(true);
112  $this->settings->setProtocol($protocol);
113  $this->settings->setDomain($domain);
114  $this->settings->setPort($port);
115  $this->settings->setClientUrl(sprintf('%s:%s', $clientDomain, $port));
116 
117  $this->assertEquals($expected, $this->settings->generateClientUrl());
118  }
119 
121  {
122  $protocol = 'http://';
123  $domain = '127.0.0.1';
124  $clientDomain = 'proxy.localhost';
125  $port = '7373';
126  $expected = sprintf('%s%s:%s', $protocol, $domain, $port);
127 
128  $this->settings->setClientUrlEnabled(false);
129  $this->settings->setDomain($domain);
130  $this->settings->setPort($port);
131  $this->settings->setProtocol($protocol);
132  $this->settings->setClientUrl(sprintf('%s:%s', $clientDomain, $port));
133 
134  $this->assertEquals($expected, $this->settings->generateClientUrl());
135  }
136 
138  {
139  $protocol = 'http://';
140  $domain = '127.0.0.1';
141  $iliasDomain = 'proxy.localhost';
142  $port = '7373';
143  $expected = sprintf('%s%s:%s', $protocol, $iliasDomain, $port);
144 
145  $this->settings->setIliasUrlEnabled(true);
146  $this->settings->setProtocol($protocol);
147  $this->settings->setDomain($domain);
148  $this->settings->setPort($port);
149  $this->settings->setIliasUrl(sprintf('%s:%s', $iliasDomain, $port));
150 
151  $this->assertEquals($expected, $this->settings->generateIliasUrl());
152  }
153 
155  {
156  $protocol = 'http://';
157  $domain = '127.0.0.1';
158  $iliasDomain = 'proxy.localhost';
159  $port = '7373';
160  $expected = sprintf('%s%s:%s', $protocol, $domain, $port);
161 
162  $this->settings->setIliasUrlEnabled(false);
163  $this->settings->setDomain($domain);
164  $this->settings->setPort($port);
165  $this->settings->setProtocol($protocol);
166  $this->settings->setIliasUrl(sprintf('%s:%s', $iliasDomain, $port));
167 
168  $this->assertEquals($expected, $this->settings->generateIliasUrl());
169  }
170 
171  public function testGetUrl()
172  {
173  $protocol = 'http://';
174  $domain = '127.0.0.1';
175  $iliasDomain = 'proxy.localhost:8080';
176  $port = 7373;
177  $action = 'Heartbeat';
178  $instance = 'master';
179  $scope = 123;
180 
181  $this->settings->setProtocol($protocol . '');
182  $this->settings->setDomain($domain);
183  $this->settings->setPort($port);
184  $this->settings->setIliasUrl($iliasDomain);
185  $this->settings->setInstance($instance);
186 
187  $this->settings->setIliasUrlEnabled(false);
188  $expected = sprintf(
189  '%s%s:%s%s/%s/%s',
190  $protocol,
191  $domain,
192  $port,
194  $action,
195  $instance
196  );
197  $this->assertEquals($expected, $this->settings->getURL($action));
198 
199  $this->settings->setIliasUrlEnabled(false);
200  $expected = sprintf(
201  '%s%s:%s%s/%s/%s/%s',
202  $protocol,
203  $domain,
204  $port,
206  $action,
207  $instance,
208  $scope
209  );
210  $this->assertEquals($expected, $this->settings->getURL($action, $scope));
211 
212  $this->settings->setIliasUrlEnabled(true);
213  $expected = sprintf(
214  '%s%s%s/%s/%s',
215  $protocol,
216  $iliasDomain,
218  $action,
219  $instance
220  );
221  $this->assertEquals($expected, $this->settings->getURL($action));
222 
223  $this->settings->setIliasUrlEnabled(true);
224  $expected = sprintf(
225  '%s%s%s/%s/%s/%s',
226  $protocol,
227  $iliasDomain,
229  $action,
230  $instance,
231  $scope
232  );
233  $this->assertEquals($expected, $this->settings->getURL($action, $scope));
234  }
235 }
Create styles array
The data for the language used.
settings()
Definition: settings.php:2
Class ilChatroomServerSettings.
Class ilChatroomServerSettingsTest.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27