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