ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilLDAPServerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 
30 class ilLDAPServerTest extends TestCase
31 {
32  private Container $dic;
33 
34  protected function setUp(): void
35  {
36  $this->dic = new Container();
37  $GLOBALS['DIC'] = $this->dic;
38 
39  $this->setGlobalVariable('lng', $this->getLanguageMock());
40  $this->setGlobalVariable(
41  'ilDB',
42  $this->getMockBuilder(ilDBInterface::class)->disableAutoReturnValueGeneration()->getMock()
43  );
44 
45  $this->setGlobalVariable(
46  'ilSetting',
47  $this->getMockBuilder(\ILIAS\Administration\Setting::class)->getMock()
48  );
49  $this->setGlobalVariable(
50  'ilErr',
51  $this->getMockBuilder(ilErrorHandling::class)->getMock()
52  );
53  parent::setUp();
54  }
55 
60  protected function setGlobalVariable(string $name, $value): void
61  {
62  global $DIC;
63 
64  $GLOBALS[$name] = $value;
65 
66  unset($DIC[$name]);
67  $DIC[$name] = static function ($c) use ($name) {
68  return $GLOBALS[$name];
69  };
70  }
71 
75  protected function getLanguageMock(): ilLanguage
76  {
77  $lng = $this
78  ->getMockBuilder(ilLanguage::class)
79  ->disableOriginalConstructor()
80  ->onlyMethods(['txt', 'getInstalledLanguages', 'loadLanguageModule'])
81  ->getMock();
82 
83  return $lng;
84  }
85 
86  public function testConstructorWithoutParam(): void
87  {
88  global $DIC;
89 
90  //setup some method calls
92  $setting = $DIC['ilSetting'];
93  $setting->method("get")->willReturnCallback(
94  function ($arg) {
95  if ($arg === 'session_handling_type') {
96  return (string) ilSession::SESSION_HANDLING_FIXED;
97  }
98  if ($arg === 'session_statistics') {
99  return "0";
100  }
101 
102  throw new \RuntimeException($arg);
103  }
104  );
106  $data = null;
107  $ilDB = $DIC['ilDB'];
108  $ilDB->expects($this->never())->method("quote");
109 
110  $server = new ilLDAPServer();
111  $this->assertFalse($server->isActive());
112  }
113 
114  public function testConstructorWithParameter(): void
115  {
116  global $DIC;
117 
118  //setup some method calls
120  $setting = $DIC['ilSetting'];
121  $setting->method("get")->willReturnCallback(
122  function ($arg) {
123  if ($arg === 'session_handling_type') {
124  return (string) ilSession::SESSION_HANDLING_FIXED;
125  }
126  if ($arg === 'session_statistics') {
127  return "0";
128  }
129 
130  throw new \RuntimeException($arg);
131  }
132  );
133 
135  $ilDB = $DIC['ilDB'];
136  $ilDB->expects($this->once())->method("quote")->with(1)->willReturn("1");
137 
138  $res = $this->getMockBuilder(ilDBStatement::class)->disableAutoReturnValueGeneration()->getMock();
139  $ilDB->method("query")->with(
140  "SELECT * FROM ldap_server_settings WHERE server_id = 1"
141  )->
142  willReturn($res);
143  $res->expects($this->exactly(2))->method("fetchRow")->willReturnOnConsecutiveCalls((object) array(
144  'active' => "true",
145  'name' => "testserver",
146  'url' => "ldap://testurl:389",
147  'version' => "3",
148  'base_dn' => "true",
149  'referrals' => "false",
150  'tls' => "false",
151  'bind_type' => "1",
152  'bind_user' => "nobody",
153  'bind_pass' => "password",
154  'search_base' => "dc=de",
155  'user_scope' => "1",
156  'user_attribute' => "user",
157  'filter' => ".",
158  'group_dn' => "dc=group",
159  'group_scope' => "1",
160  'group_filter' => "",
161  'group_member' => "",
162  'group_attribute' => "",
163  'group_optional' => "false",
164  'group_user_filter' => ".*",
165  'group_memberisdn' => "true",
166  'group_name' => "",
167  'sync_on_login' => "true",
168  'sync_per_cron' => "false",
169  'role_sync_active' => "true",
170  'role_bind_dn' => "rolebind",
171  'role_bind_pass' => "rolebindpwd",
172  'migration' => "true",
173  'authentication' => "true",
174  'authentication_type' => "1",
175  'username_filter' => ".*",
176  'escape_dn' => "false"
177  ), null);
178 
179  $server = new ilLDAPServer(1);
180  $this->assertTrue($server->isActive());
181  }
182 }
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider .
const SESSION_HANDLING_FIXED
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
global $DIC
Definition: feed.php:28
$GLOBALS["DIC"]
Definition: wac.php:31
$lng
setGlobalVariable(string $name, $value)
$server
Class ilSessionTest.