ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
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
25class ilLDAPServerTest extends TestCase
26{
27 private ?Container $dic = null;
28
29 protected function setUp(): void
30 {
31 global $DIC;
32
33 $this->dic = is_object($DIC) ? clone $DIC : $DIC;
34
35 $DIC = new Container();
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
52 $logger = $this
53 ->getMockBuilder(ilLogger::class)
54 ->disableOriginalConstructor()
55 ->getMock();
56 $logger_factory = $this->getMockBuilder(ilLoggerFactory::class)->disableOriginalConstructor()->getMock();
57 $logger_factory
58 ->expects($this->once())
59 ->method('getComponentLogger')
60 ->willReturn($logger);
61 $this->setGlobalVariable(
62 ilLoggerFactory::class,
63 $logger_factory
64 );
65
66 parent::setUp();
67 }
68
69 protected function tearDown(): void
70 {
71 global $DIC;
72
74
75 parent::tearDown();
76 }
77
78 protected function setGlobalVariable(string $name, mixed $value): void
79 {
80 global $DIC;
81
82 $GLOBALS[$name] = $value;
83
84 unset($DIC[$name]);
85 $DIC[$name] = static fn(Container $c) => $GLOBALS[$name];
86 }
87
88 protected function getLanguageMock(): MockObject&ilLanguage
89 {
90 $lng = $this
91 ->getMockBuilder(ilLanguage::class)
92 ->disableOriginalConstructor()
93 ->onlyMethods(['txt', 'getInstalledLanguages', 'loadLanguageModule'])
94 ->getMock();
95
96 return $lng;
97 }
98
99 public function testConstructorWithoutParam(): void
100 {
101 global $DIC;
102
104 $ilDB = $DIC['ilDB'];
105 $ilDB
106 ->expects($this->never())
107 ->method('quote');
108
109 $server = new ilLDAPServer();
110 $this->assertFalse($server->isActive());
111 }
112
113 public function testConstructorWithParameter(): void
114 {
115 global $DIC;
116
118 $ilDB = $DIC['ilDB'];
119 $ilDB->expects($this->once())->method('quote')->with(1)->willReturn('1');
120
121 $res = $this->getMockBuilder(ilDBStatement::class)->disableAutoReturnValueGeneration()->getMock();
122 $ilDB
123 ->expects($this->once())
124 ->method('query')
125 ->with(
126 'SELECT * FROM ldap_server_settings WHERE server_id = 1'
127 )
128 ->willReturn($res);
129 $res
130 ->expects($this->exactly(2))
131 ->method('fetchRow')
132 ->willReturnOnConsecutiveCalls(
133 (object) [
134 'active' => 'true',
135 'name' => 'testserver',
136 'url' => 'ldap://testurl:389',
137 'version' => '3',
138 'base_dn' => 'true',
139 'referrals' => 'false',
140 'tls' => 'false',
141 'bind_type' => '1',
142 'bind_user' => 'nobody',
143 'bind_pass' => 'password',
144 'search_base' => 'dc=de',
145 'user_scope' => '1',
146 'user_attribute' => 'user',
147 'filter' => '.',
148 'group_dn' => 'dc=group',
149 'group_scope' => '1',
150 'group_filter' => '',
151 'group_member' => '',
152 'group_attribute' => '',
153 'group_optional' => 'false',
154 'group_user_filter' => '.*',
155 'group_memberisdn' => 'true',
156 'group_name' => '',
157 'sync_on_login' => 'true',
158 'sync_per_cron' => 'false',
159 'role_sync_active' => 'true',
160 'role_bind_dn' => 'rolebind',
161 'role_bind_pass' => 'rolebindpwd',
162 'migration' => 'true',
163 'authentication' => 'true',
164 'authentication_type' => '1',
165 'username_filter' => '.*',
166 'escape_dn' => 'false'
167 ],
168 null
169 );
170
171 $server = new ilLDAPServer(1);
172 $this->assertTrue($server->isActive());
173 }
174}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
setGlobalVariable(string $name, mixed $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:26
global $DIC
Definition: shib_login.php:26
$server
Definition: shib_login.php:28
$GLOBALS["DIC"]
Definition: wac.php:54