ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilObjUserPasswordTest Class Reference
+ Inheritance diagram for ilObjUserPasswordTest:
+ Collaboration diagram for ilObjUserPasswordTest:

Public Member Functions

 getTestDirectory ()
 
 setTestDirectory (vfs\vfsStreamDirectory $testDirectory)
 
 getTestDirectoryUrl ()
 
 setTestDirectoryUrl (string $testDirectoryUrl)
 
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ()
 
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ()
 
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ()
 
 testInstanceCanBeCreated ()
 
 testPasswordManagerEncodesRawPasswordWithSalt ()
 
 testPasswordManagerEncodesRawPasswordWithoutSalt ()
 
 testPasswordManagerVerifiesPassword ()
 
 testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ()
 
 testPasswordManagerReencodesPasswordIfReencodingIsNecessary ()
 
 testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ()
 
 testFactoryCanBeCreated ()
 
 testGettersOfFactoryShouldReturnWhatWasSetBySetters ()
 
 testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ()
 
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ()
 
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ()
 
 testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ()
 
 testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ()
 

Protected Member Functions

 setUp ()
 
- Protected Member Functions inherited from ilUserBaseTest
 assertException (string $exception_class)
 

Protected Attributes

vfs vfsStreamDirectory $testDirectory
 
string $testDirectoryUrl
 

Private Attributes

const PASSWORD = 'password'
 
const ENCODED_PASSWORD = 'encoded'
 

Detailed Description

Definition at line 36 of file ilObjUserPasswordTest.php.

Member Function Documentation

◆ getTestDirectory()

ilObjUserPasswordTest::getTestDirectory ( )

Definition at line 44 of file ilObjUserPasswordTest.php.

References $testDirectory.

44  : vfs\vfsStreamDirectory
45  {
46  return $this->testDirectory;
47  }
vfs vfsStreamDirectory $testDirectory

◆ getTestDirectoryUrl()

ilObjUserPasswordTest::getTestDirectoryUrl ( )

◆ setTestDirectory()

ilObjUserPasswordTest::setTestDirectory ( vfs\vfsStreamDirectory  $testDirectory)

Definition at line 49 of file ilObjUserPasswordTest.php.

References $testDirectory.

Referenced by setUp().

49  : void
50  {
51  $this->testDirectory = $testDirectory;
52  }
vfs vfsStreamDirectory $testDirectory
+ Here is the caller graph for this function:

◆ setTestDirectoryUrl()

ilObjUserPasswordTest::setTestDirectoryUrl ( string  $testDirectoryUrl)

Definition at line 59 of file ilObjUserPasswordTest.php.

References $testDirectoryUrl.

Referenced by setUp().

59  : void
60  {
61  $this->testDirectoryUrl = $testDirectoryUrl;
62  }
+ Here is the caller graph for this function:

◆ setUp()

ilObjUserPasswordTest::setUp ( )
protected

Definition at line 64 of file ilObjUserPasswordTest.php.

References setTestDirectory(), and setTestDirectoryUrl().

64  : void
65  {
66  vfs\vfsStream::setup();
67  $this->setTestDirectory(vfs\vfsStream::newDirectory('tests')->at(vfs\vfsStreamWrapper::getRoot()));
68  $this->setTestDirectoryUrl(vfs\vfsStream::url('root/tests'));
69 
70  parent::setUp();
71  }
setTestDirectoryUrl(string $testDirectoryUrl)
setTestDirectory(vfs\vfsStreamDirectory $testDirectory)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ( )
Exceptions
ilPasswordException
ilUserException

Definition at line 422 of file ilObjUserPasswordTest.php.

References $factory, ilUserBaseTest\assertException(), and getTestDirectoryUrl().

422  : void
423  {
424  $this->assertException(ilUserException::class);
426  'default_password_encoder' => 'md5',
427  'data_directory' => $this->getTestDirectoryUrl()
428  ]);
429  $factory->getEncoderByName('phpunit');
430  }
assertException(string $exception_class)
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ( )
Exceptions
ilUserException

Definition at line 76 of file ilObjUserPasswordTest.php.

References ilUserBaseTest\assertException(), and getTestDirectoryUrl().

76  : void
77  {
78  $this->assertException(ilUserException::class);
79  new ilUserPasswordManager(['data_directory' => $this->getTestDirectoryUrl()]);
80  }
assertException(string $exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ( )
Exceptions
ilUserException

Definition at line 85 of file ilObjUserPasswordTest.php.

References ilUserBaseTest\assertException(), and getTestDirectoryUrl().

85  : void
86  {
87  $this->assertException(ilUserException::class);
89  'password_encoder' => 'md5',
90  'data_directory' => $this->getTestDirectoryUrl()
91  ]);
92  }
assertException(string $exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ( )
Exceptions
ilUserException

Definition at line 97 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

97  : void
98  {
99  $this->expectException(TypeError::class);
100  $this->expectExceptionMessageMatches('/' . ilUserPasswordEncoderFactory::class . '/');
101 
103  'password_encoder' => 'md5',
104  'encoder_factory' => 'test',
105  'data_directory' => $this->getTestDirectoryUrl()
106  ]);
107  }
+ Here is the call graph for this function:

◆ testFactoryCanBeCreated()

ilObjUserPasswordTest::testFactoryCanBeCreated ( )
Exceptions
ilPasswordException

Definition at line 364 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

364  : void
365  {
367  'data_directory' => $this->getTestDirectoryUrl()
368  ]);
369  $this->assertInstanceOf('ilUserPasswordEncoderFactory', $factory);
370  }
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ( )
Exceptions
ilPasswordException
ilUserException

Definition at line 436 of file ilObjUserPasswordTest.php.

References $factory, ilUserBaseTest\assertException(), and getTestDirectoryUrl().

436  : void
437  {
438  $this->assertException(ilUserException::class);
440  'data_directory' => $this->getTestDirectoryUrl()
441  ]);
442  $factory->getEncoderByName('phpunit', true);
443  }
assertException(string $exception_class)
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ( )
Exceptions
ilPasswordException
ilUserException

Definition at line 449 of file ilObjUserPasswordTest.php.

References $factory, ilUserBaseTest\assertException(), and getTestDirectoryUrl().

449  : void
450  {
451  $this->assertException(ilUserException::class);
453  'default_password_encoder' => 'phpunit',
454  'data_directory' => $this->getTestDirectoryUrl()
455  ]);
456  $factory->getEncoderByName('phpunit', true);
457  }
assertException(string $exception_class)
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:

◆ testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound()

ilObjUserPasswordTest::testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ( )
Exceptions
ilUserException
ilPasswordException
ReflectionException

Definition at line 482 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

482  : void
483  {
484  $encoder = $this->getMockBuilder(ilBasePasswordEncoder::class)->disableOriginalConstructor()->getMock();
485  $encoder->expects($this->atLeastOnce())->method('getName')->willReturn('mockencoder');
486 
488  'default_password_encoder' => $encoder->getName(),
489  'data_directory' => $this->getTestDirectoryUrl()
490  ]);
491  $factory->setEncoders([$encoder]);
492  $this->assertEquals($encoder, $factory->getEncoderByName('mockencoder', true));
493  }
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:

◆ testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ( )
Exceptions
ReflectionException
ilPasswordException
ilUserException

Definition at line 464 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

464  : void
465  {
466  $encoder = $this->getMockBuilder(ilBasePasswordEncoder::class)->disableOriginalConstructor()->getMock();
467  $encoder->expects($this->atLeastOnce())->method('getName')->willReturn('mockencoder');
468 
470  'default_password_encoder' => $encoder->getName(),
471  'data_directory' => $this->getTestDirectoryUrl()
472  ]);
473  $factory->setEncoders([$encoder]);
474  $this->assertEquals($encoder, $factory->getEncoderByName('phpunit', true));
475  }
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:

◆ testGettersOfFactoryShouldReturnWhatWasSetBySetters()

ilObjUserPasswordTest::testGettersOfFactoryShouldReturnWhatWasSetBySetters ( )
Exceptions
ReflectionException
ilPasswordException
ilUserException

Definition at line 377 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

377  : void
378  {
380  'default_password_encoder' => 'md5',
381  'data_directory' => $this->getTestDirectoryUrl()
382  ]);
383  $this->assertEquals('md5', $factory->getDefaultEncoder());
384 
385  $encoder = $this->getMockBuilder(ilBasePasswordEncoder::class)->disableOriginalConstructor()->getMock();
386  $encoder->expects($this->atLeastOnce())->method('getName')->willReturn('mockencoder');
387 
388  $second_mockencoder = $this->getMockBuilder(ilBasePasswordEncoder::class)->disableOriginalConstructor()->getMock();
389  $second_mockencoder->expects($this->atLeastOnce())->method('getName')->willReturn('second_mockencoder');
390 
391  $factory->setEncoders([$encoder, $second_mockencoder]);
392  $this->assertCount(2, $factory->getEncoders());
393  $this->assertCount(2, $factory->getSupportedEncoderNames());
394  $this->assertCount(
395  0,
396  array_diff(['mockencoder', 'second_mockencoder'], $factory->getSupportedEncoderNames())
397  );
398  $this->assertCount(
399  0,
400  array_diff($factory->getSupportedEncoderNames(), ['mockencoder', 'second_mockencoder'])
401  );
402  }
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilObjUserPasswordTest::testInstanceCanBeCreated ( )
Exceptions
ilUserException
ReflectionException

Definition at line 113 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

113  : void
114  {
115  $factory_mock = $this->getMockBuilder(ilUserPasswordEncoderFactory::class)->disableOriginalConstructor()->getMock();
116  $factory_mock->expects($this->exactly(2))->method('getSupportedEncoderNames')->will($this->onConsecutiveCalls(
117  [
118  'mockencoder',
119  'second_mockencoder'
120  ],
121  [
122  'mockencoder'
123  ]
124  ));
125 
126  $password_manager = new ilUserPasswordManager([
127  'password_encoder' => 'md5',
128  'encoder_factory' => $factory_mock,
129  'data_directory' => $this->getTestDirectoryUrl()
130  ]);
131  $this->assertInstanceOf('ilUserPasswordManager', $password_manager);
132  $this->assertEquals('md5', $password_manager->getEncoderName());
133  $this->assertEquals($factory_mock, $password_manager->getEncoderFactory());
134 
135  $this->assertTrue($password_manager->isEncodingTypeSupported('second_mockencoder'));
136  $this->assertFalse($password_manager->isEncodingTypeSupported('second_mockencoder'));
137  }
+ Here is the call graph for this function:

◆ testPasswordManagerEncodesRawPasswordWithoutSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithoutSalt ( )
Exceptions
ilUserException
ReflectionException

Definition at line 180 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl(), and ilObjUser\PASSWD_CRYPTED.

180  : void
181  {
182  $user_mock = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
183  $encoder = $this->getMockBuilder(ilBasePasswordEncoder::class)->disableOriginalConstructor()->getMock();
184  $factory_mock = $this->getMockBuilder(ilUserPasswordEncoderFactory::class)->disableOriginalConstructor()->getMock();
185 
186  $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->equalTo(null));
187  $user_mock->expects($this->once())->method('getPasswordSalt')->willReturn(null);
188  $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
189  $user_mock->expects($this->once())->method('setPasswd')->with(
190  $this->equalTo(self::ENCODED_PASSWORD),
191  $this->equalTo(ilObjUser::PASSWD_CRYPTED)
192  );
193 
194  $encoder->expects($this->once())->method('getName')->willReturn('mockencoder');
195  $encoder->expects($this->once())->method('requiresSalt')->willReturn(false);
196  $encoder->expects($this->once())->method('encodePassword')->with(
197  $this->equalTo(self::PASSWORD),
198  $this->equalTo(null)
199  )->willReturn(self::ENCODED_PASSWORD);
200 
201  $factory_mock->expects($this->once())->method('getEncoderByName')->willReturn($encoder);
202 
203  $password_manager = new ilUserPasswordManager([
204  'password_encoder' => 'mockencoder',
205  'encoder_factory' => $factory_mock,
206  'data_directory' => $this->getTestDirectoryUrl()
207  ]);
208 
209  $password_manager->encodePassword($user_mock, self::PASSWORD);
210  }
const PASSWD_CRYPTED
+ Here is the call graph for this function:

◆ testPasswordManagerEncodesRawPasswordWithSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithSalt ( )
Exceptions
ilUserException
ReflectionException

Definition at line 143 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl(), and ilObjUser\PASSWD_CRYPTED.

143  : void
144  {
145  $user_mock = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
146  $encoder = $this->getMockBuilder(ilBasePasswordEncoder::class)->disableOriginalConstructor()->getMock();
147  $factory_mock = $this->getMockBuilder(ilUserPasswordEncoderFactory::class)->disableOriginalConstructor()->getMock();
148 
149  $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->isType('string'));
150  $user_mock->expects($this->once())->method('getPasswordSalt')->willReturn('asuperrandomsalt');
151  $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
152  $user_mock->expects($this->once())->method('setPasswd')->with(
153  $this->equalTo(self::ENCODED_PASSWORD),
154  $this->equalTo(ilObjUser::PASSWD_CRYPTED)
155  );
156 
157  $encoder->expects($this->once())->method('getName')->willReturn('mockencoder');
158  $encoder->expects($this->once())->method('requiresSalt')->willReturn(true);
159  $encoder->expects($this->once())->method('encodePassword')
160  ->with(
161  $this->equalTo(self::PASSWORD),
162  $this->isType('string')
163  )->willReturn(self::ENCODED_PASSWORD);
164 
165  $factory_mock->expects($this->once())->method('getEncoderByName')->willReturn($encoder);
166 
167  $password_manager = new ilUserPasswordManager([
168  'password_encoder' => 'mockencoder',
169  'encoder_factory' => $factory_mock,
170  'data_directory' => $this->getTestDirectoryUrl()
171  ]);
172 
173  $password_manager->encodePassword($user_mock, self::PASSWORD);
174  }
const PASSWD_CRYPTED
+ Here is the call graph for this function:

◆ testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ( )
Exceptions
ilUserException
ReflectionException

Definition at line 252 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

252  : void
253  {
254  $user_mock = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
255  $encoder = $this->getMockBuilder(ilBasePasswordEncoder::class)->disableOriginalConstructor()->getMock();
256  $factory_mock = $this->getMockBuilder(ilUserPasswordEncoderFactory::class)->disableOriginalConstructor()->getMock();
257 
258  $user_mock->expects($this->once())->method('getPasswordSalt')->willReturn('asuperrandomsalt');
259  $user_mock->expects($this->once())->method('getPasswordEncodingType')->willReturn('second_mockencoder');
260  $user_mock->expects($this->once())->method('getPasswd')->willReturn(self::ENCODED_PASSWORD);
261  $user_mock->expects($this->once())->method('resetPassword')->with(
262  $this->equalTo(self::PASSWORD),
263  $this->equalTo(self::PASSWORD)
264  );
265 
266  $encoder->expects($this->once())->method('getName')->willReturn('second_mockencoder');
267  $encoder->expects($this->once())->method('isPasswordValid')->with(
268  $this->equalTo(self::ENCODED_PASSWORD),
269  $this->equalTo(self::PASSWORD),
270  $this->isType('string')
271  )->willReturn(true);
272  $encoder->expects($this->never())->method('requiresReencoding')
273  ->with($this->equalTo(self::ENCODED_PASSWORD))
274  ->willReturn(false);
275 
276  $factory_mock->expects($this->once())->method('getEncoderByName')->willReturn($encoder);
277 
278  $password_manager = new ilUserPasswordManager([
279  'password_encoder' => 'mockencoder',
280  'encoder_factory' => $factory_mock,
281  'data_directory' => $this->getTestDirectoryUrl()
282  ]);
283 
284  $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
285  }
+ Here is the call graph for this function:

◆ testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ( )
Exceptions
ilUserException
ReflectionException

Definition at line 330 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

330  : void
331  {
332  $user_mock = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
333  $encoder = $this->getMockBuilder(ilBasePasswordEncoder::class)->disableOriginalConstructor()->getMock();
334  $factory_mock = $this->getMockBuilder(ilUserPasswordEncoderFactory::class)->disableOriginalConstructor()->getMock();
335 
336  $user_mock->expects($this->once())->method('getPasswordSalt')->willReturn('asuperrandomsalt');
337  $user_mock->expects($this->once())->method('getPasswordEncodingType')->willReturn('second_mockencoder');
338  $user_mock->expects($this->once())->method('getPasswd')->willReturn(self::ENCODED_PASSWORD);
339  $user_mock->expects($this->never())->method('resetPassword');
340 
341  $encoder->expects($this->once())->method('getName')->willReturn('second_mockencoder');
342  $encoder->expects($this->never())->method('requiresReencoding');
343  $encoder->expects($this->once())->method('isPasswordValid')
344  ->with(
345  $this->equalTo(self::ENCODED_PASSWORD),
346  $this->equalTo(self::PASSWORD),
347  $this->isType('string')
348  )->willReturn(false);
349 
350  $factory_mock->expects($this->once())->method('getEncoderByName')->willReturn($encoder);
351 
352  $password_manager = new ilUserPasswordManager([
353  'password_encoder' => 'mockencoder',
354  'encoder_factory' => $factory_mock,
355  'data_directory' => $this->getTestDirectoryUrl()
356  ]);
357 
358  $this->assertFalse($password_manager->verifyPassword($user_mock, self::PASSWORD));
359  }
+ Here is the call graph for this function:

◆ testPasswordManagerReencodesPasswordIfReencodingIsNecessary()

ilObjUserPasswordTest::testPasswordManagerReencodesPasswordIfReencodingIsNecessary ( )
Exceptions
ilUserException
ReflectionException

Definition at line 291 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

291  : void
292  {
293  $user_mock = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
294  $encoder = $this->getMockBuilder(ilBasePasswordEncoder::class)->disableOriginalConstructor()->getMock();
295  $factory_mock = $this->getMockBuilder(ilUserPasswordEncoderFactory::class)->disableOriginalConstructor()->getMock();
296 
297  $user_mock->expects($this->once())->method('getPasswordSalt')->willReturn('asuperrandomsalt');
298  $user_mock->expects($this->once())->method('getPasswordEncodingType')->willReturn('mockencoder');
299  $user_mock->expects($this->exactly(2))->method('getPasswd')->willReturn(self::ENCODED_PASSWORD);
300  $user_mock->expects($this->once())->method('resetPassword')->with(
301  $this->equalTo(self::PASSWORD),
302  $this->equalTo(self::PASSWORD)
303  );
304 
305  $encoder->expects($this->once())->method('getName')->willReturn('mockencoder');
306  $encoder->expects($this->once())->method('isPasswordValid')->with(
307  $this->equalTo(self::ENCODED_PASSWORD),
308  $this->equalTo(self::PASSWORD),
309  $this->isType('string')
310  )->willReturn(true);
311  $encoder->expects($this->once())->method('requiresReencoding')
312  ->with($this->equalTo(self::ENCODED_PASSWORD))
313  ->willReturn(true);
314 
315  $factory_mock->expects($this->once())->method('getEncoderByName')->willReturn($encoder);
316 
317  $password_manager = new ilUserPasswordManager([
318  'password_encoder' => 'mockencoder',
319  'encoder_factory' => $factory_mock,
320  'data_directory' => $this->getTestDirectoryUrl()
321  ]);
322 
323  $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
324  }
+ Here is the call graph for this function:

◆ testPasswordManagerVerifiesPassword()

ilObjUserPasswordTest::testPasswordManagerVerifiesPassword ( )
Exceptions
ilUserException
ReflectionException

Definition at line 216 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

216  : void
217  {
218  $user_mock = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
219  $encoder = $this->getMockBuilder(ilBasePasswordEncoder::class)->disableOriginalConstructor()->getMock();
220  $factory_mock = $this->getMockBuilder(ilUserPasswordEncoderFactory::class)->disableOriginalConstructor()->getMock();
221 
222  $user_mock->expects($this->atLeast(1))->method('getPasswordSalt')->willReturn('asuperrandomsalt');
223  $user_mock->expects($this->atLeast(1))->method('getPasswordEncodingType')->willReturn('mockencoder');
224  $user_mock->expects($this->atLeast(1))->method('getPasswd')->willReturn(self::ENCODED_PASSWORD);
225  $user_mock->expects($this->never())->method('resetPassword');
226 
227  $encoder->expects($this->once())->method('getName')->willReturn('mockencoder');
228  $encoder->expects($this->once())->method('isPasswordValid')->with(
229  $this->equalTo(self::ENCODED_PASSWORD),
230  $this->equalTo(self::PASSWORD),
231  $this->isType('string')
232  )->willReturn(true);
233  $encoder->expects($this->once())->method('requiresReencoding')
234  ->with($this->equalTo(self::ENCODED_PASSWORD))
235  ->willReturn(false);
236 
237  $factory_mock->expects($this->once())->method('getEncoderByName')->willReturn($encoder);
238 
239  $password_manager = new ilUserPasswordManager([
240  'password_encoder' => 'mockencoder',
241  'encoder_factory' => $factory_mock,
242  'data_directory' => $this->getTestDirectoryUrl()
243  ]);
244 
245  $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
246  }
+ Here is the call graph for this function:

Field Documentation

◆ $testDirectory

vfs vfsStreamDirectory ilObjUserPasswordTest::$testDirectory
protected

Definition at line 41 of file ilObjUserPasswordTest.php.

Referenced by getTestDirectory(), and setTestDirectory().

◆ $testDirectoryUrl

string ilObjUserPasswordTest::$testDirectoryUrl
protected

Definition at line 42 of file ilObjUserPasswordTest.php.

Referenced by getTestDirectoryUrl(), and setTestDirectoryUrl().

◆ ENCODED_PASSWORD

const ilObjUserPasswordTest::ENCODED_PASSWORD = 'encoded'
private

Definition at line 39 of file ilObjUserPasswordTest.php.

◆ PASSWORD

const ilObjUserPasswordTest::PASSWORD = 'password'
private

Definition at line 38 of file ilObjUserPasswordTest.php.


The documentation for this class was generated from the following file: