ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilLDAPServerTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use PHPUnit\Framework\MockObject\MockObject;
23use PHPUnit\Framework\TestCase;
24
28class ilLDAPServerTest extends TestCase
29{
30 private Container $dic;
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)->disableOriginalConstructor()->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_statistics') {
94 return "0";
95 }
96
97 throw new \RuntimeException($arg);
98 }
99 );
101 $data = null;
102 $ilDB = $DIC['ilDB'];
103 $ilDB->expects($this->never())->method("quote");
104
105 $server = new ilLDAPServer();
106 $this->assertFalse($server->isActive());
107 }
108
109 public function testConstructorWithParameter(): void
110 {
111 global $DIC;
112
113 //setup some method calls
115 $setting = $DIC['ilSetting'];
116 $setting->method("get")->willReturnCallback(
117 function ($arg) {
118 if ($arg === 'session_statistics') {
119 return "0";
120 }
121
122 throw new \RuntimeException($arg);
123 }
124 );
125
127 $ilDB = $DIC['ilDB'];
128 $ilDB->expects($this->once())->method("quote")->with(1)->willReturn("1");
129
130 $res = $this->getMockBuilder(ilDBStatement::class)->disableAutoReturnValueGeneration()->getMock();
131 $ilDB->method("query")->with(
132 "SELECT * FROM ldap_server_settings WHERE server_id = 1"
133 )->
134 willReturn($res);
135 $res->expects($this->exactly(2))->method("fetchRow")->willReturnOnConsecutiveCalls((object) array(
136 'active' => "true",
137 'name' => "testserver",
138 'url' => "ldap://testurl:389",
139 'version' => "3",
140 'base_dn' => "true",
141 'referrals' => "false",
142 'tls' => "false",
143 'bind_type' => "1",
144 'bind_user' => "nobody",
145 'bind_pass' => "password",
146 'search_base' => "dc=de",
147 'user_scope' => "1",
148 'user_attribute' => "user",
149 'filter' => ".",
150 'group_dn' => "dc=group",
151 'group_scope' => "1",
152 'group_filter' => "",
153 'group_member' => "",
154 'group_attribute' => "",
155 'group_optional' => "false",
156 'group_user_filter' => ".*",
157 'group_memberisdn' => "true",
158 'group_name' => "",
159 'sync_on_login' => "true",
160 'sync_per_cron' => "false",
161 'role_sync_active' => "true",
162 'role_bind_dn' => "rolebind",
163 'role_bind_pass' => "rolebindpwd",
164 'migration' => "true",
165 'authentication' => "true",
166 'authentication_type' => "1",
167 'username_filter' => ".*",
168 'escape_dn' => "false"
169 ), null);
170
171 $server = new ilLDAPServer(1);
172 $this->assertTrue($server->isActive());
173 }
174}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Class ilSessionTest.
setGlobalVariable(string $name, $value)
language handling
$c
Definition: deliver.php:25
$res
Definition: ltiservices.php:69
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$server
Definition: shib_login.php:28
$GLOBALS["DIC"]
Definition: wac.php:54