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