ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilObjUserPasswordTest Class Reference
+ Inheritance diagram for ilObjUserPasswordTest:
+ Collaboration diagram for ilObjUserPasswordTest:

Public Member Functions

 getTestDirectory ()
 
 setTestDirectory ($test_directory)
 
 getTestDirectoryUrl ()
 
 setTestDirectoryUrl ($test_directory_url)
 
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ()
 ilUserException More...
 
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ()
 ilUserException More...
 
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ()
 PHPUnit_Framework_Error More...
 
 testInstanceCanBeCreated ()
 
 testPasswordManagerEncodesRawPasswordWithSalt ()
 
 testPasswordManagerEncodesRawPasswordWithoutSalt ()
 
 testPasswordManagerVerifiesPassword ()
 
 testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ()
 
 testPasswordManagerReencodesPasswordIfReencodingIsNecessary ()
 
 testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ()
 
 testFactoryCanBeCreated ()
 
 testGettersOfFactoryShouldReturnWhatWasSetBySetters ()
 
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected ()
 ilUserException More...
 
 testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ()
 ilUserException More...
 
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ()
 ilUserException More...
 
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ()
 ilUserException More...
 
 testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ()
 
 testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ()
 

Data Fields

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

Protected Member Functions

 setUp ()
 Setup. More...
 
- Protected Member Functions inherited from ilUserBaseTest
 assertException ($exception_class)
 

Protected Attributes

 $test_directory
 
 $test_directory_url
 

Detailed Description

Definition at line 20 of file ilObjUserPasswordTest.php.

Member Function Documentation

◆ getTestDirectory()

ilObjUserPasswordTest::getTestDirectory ( )
Returns
vfs

Definition at line 45 of file ilObjUserPasswordTest.php.

References $test_directory.

◆ getTestDirectoryUrl()

ilObjUserPasswordTest::getTestDirectoryUrl ( )
Returns
string

Definition at line 61 of file ilObjUserPasswordTest.php.

References $test_directory_url.

Referenced by testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory(), testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation(), testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory(), testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory(), testFactoryCanBeCreated(), testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode(), testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode(), testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected(), testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound(), testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode(), testGettersOfFactoryShouldReturnWhatWasSetBySetters(), testInstanceCanBeCreated(), testPasswordManagerEncodesRawPasswordWithoutSalt(), testPasswordManagerEncodesRawPasswordWithSalt(), testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders(), testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders(), testPasswordManagerReencodesPasswordIfReencodingIsNecessary(), and testPasswordManagerVerifiesPassword().

+ Here is the caller graph for this function:

◆ setTestDirectory()

ilObjUserPasswordTest::setTestDirectory (   $test_directory)
Parameters
vfs\vfsStreamDirectory$test_directory

Definition at line 53 of file ilObjUserPasswordTest.php.

References $test_directory.

Referenced by setUp().

54  {
55  $this->test_directory = $test_directory;
56  }
+ Here is the caller graph for this function:

◆ setTestDirectoryUrl()

ilObjUserPasswordTest::setTestDirectoryUrl (   $test_directory_url)
Parameters
string$test_directory_url

Definition at line 69 of file ilObjUserPasswordTest.php.

References $test_directory_url.

Referenced by setUp().

70  {
71  $this->test_directory_url = $test_directory_url;
72  }
+ Here is the caller graph for this function:

◆ setUp()

ilObjUserPasswordTest::setUp ( )
protected

Setup.

Definition at line 77 of file ilObjUserPasswordTest.php.

References setTestDirectory(), and setTestDirectoryUrl().

78  {
79  vfs\vfsStream::setup();
80  $this->setTestDirectory(vfs\vfsStream::newDirectory('tests')->at(vfs\vfsStreamWrapper::getRoot()));
81  $this->setTestDirectoryUrl(vfs\vfsStream::url('root/tests'));
82 
83  parent::setUp();
84  }
setTestDirectory($test_directory)
setTestDirectoryUrl($test_directory_url)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ( )

ilUserException

Definition at line 394 of file ilObjUserPasswordTest.php.

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

395  {
396  $this->assertException(ilUserException::class);
398  'default_password_encoder' => 'md5',
399  'data_directory' => $this->getTestDirectoryUrl()
400  ));
401  $factory->getEncoderByName('phpunit');
402  }
assertException($exception_class)
$factory
Definition: metadata.php:43
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ( )

ilUserException

Definition at line 89 of file ilObjUserPasswordTest.php.

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

90  {
91  $this->assertException(ilUserException::class);
92  new ilUserPasswordManager(array('data_directory' => $this->getTestDirectoryUrl()));
93  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ( )

ilUserException

Definition at line 98 of file ilObjUserPasswordTest.php.

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

99  {
100  $this->assertException(ilUserException::class);
102  array(
103  'password_encoder' => 'md5',
104  'data_directory' => $this->getTestDirectoryUrl()
105  )
106  );
107  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ( )

PHPUnit_Framework_Error

Definition at line 112 of file ilObjUserPasswordTest.php.

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

113  {
114  $this->assertException(PHPUnit_Framework_Error::class);
115  try {
117  array(
118  'password_encoder' => 'md5',
119  'encoder_factory' => 'test',
120  'data_directory' => $this->getTestDirectoryUrl()
121  )
122  );
123  } catch (TypeError $e) {
124  throw new PHPUnit_Framework_Error($e->getMessage(), $e->getCode(), $e->getFile(), $e->getLine());
125  }
126  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testFactoryCanBeCreated()

ilObjUserPasswordTest::testFactoryCanBeCreated ( )

Definition at line 347 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

348  {
350  'data_directory' => $this->getTestDirectoryUrl()
351  ));
352  $this->assertInstanceOf('ilUserPasswordEncoderFactory', $factory);
353  }
$factory
Definition: metadata.php:43
+ Here is the call graph for this function:

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ( )

ilUserException

Definition at line 407 of file ilObjUserPasswordTest.php.

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

408  {
409  $this->assertException(ilUserException::class);
411  'data_directory' => $this->getTestDirectoryUrl()
412  ));
413  $factory->getEncoderByName('phpunit', true);
414  }
assertException($exception_class)
$factory
Definition: metadata.php:43
+ Here is the call graph for this function:

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ( )

ilUserException

Definition at line 419 of file ilObjUserPasswordTest.php.

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

420  {
421  $this->assertException(ilUserException::class);
423  'default_password_encoder' => 'phpunit',
424  'data_directory' => $this->getTestDirectoryUrl()
425  ));
426  $factory->getEncoderByName('phpunit', true);
427  }
assertException($exception_class)
$factory
Definition: metadata.php:43
+ Here is the call graph for this function:

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected ( )

ilUserException

Definition at line 382 of file ilObjUserPasswordTest.php.

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

383  {
384  $this->assertException(ilUserException::class);
386  'data_directory' => $this->getTestDirectoryUrl()
387  ));
388  $factory->setEncoders(array('phpunit'));
389  }
assertException($exception_class)
$factory
Definition: metadata.php:43
+ Here is the call graph for this function:

◆ testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound()

ilObjUserPasswordTest::testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ( )

Definition at line 448 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

449  {
450  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
451  $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
452 
454  'default_password_encoder' => $encoder->getName(),
455  'data_directory' => $this->getTestDirectoryUrl()
456  ));
457  $factory->setEncoders(array($encoder));
458  $this->assertEquals($encoder, $factory->getEncoderByName('mockencoder', true));
459  }
$factory
Definition: metadata.php:43
+ Here is the call graph for this function:

◆ testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ( )

Definition at line 432 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

433  {
434  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
435  $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
436 
438  'default_password_encoder' => $encoder->getName(),
439  'data_directory' => $this->getTestDirectoryUrl()
440  ));
441  $factory->setEncoders(array($encoder));
442  $this->assertEquals($encoder, $factory->getEncoderByName('phpunit', true));
443  }
$factory
Definition: metadata.php:43
+ Here is the call graph for this function:

◆ testGettersOfFactoryShouldReturnWhatWasSetBySetters()

ilObjUserPasswordTest::testGettersOfFactoryShouldReturnWhatWasSetBySetters ( )

Definition at line 358 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

359  {
361  'default_password_encoder' => 'md5',
362  'data_directory' => $this->getTestDirectoryUrl()
363  ));
364  $this->assertEquals('md5', $factory->getDefaultEncoder());
365 
366  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
367  $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
368 
369  $second_mockencoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
370  $second_mockencoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('second_mockencoder'));
371 
372  $factory->setEncoders(array($encoder, $second_mockencoder));
373  $this->assertCount(2, $factory->getEncoders());
374  $this->assertCount(2, $factory->getSupportedEncoderNames());
375  $this->assertCount(0, array_diff(array('mockencoder', 'second_mockencoder'), $factory->getSupportedEncoderNames()));
376  $this->assertCount(0, array_diff($factory->getSupportedEncoderNames(), array('mockencoder', 'second_mockencoder')));
377  }
$factory
Definition: metadata.php:43
+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilObjUserPasswordTest::testInstanceCanBeCreated ( )

Definition at line 131 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

132  {
133  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
134  $factory_mock->expects($this->exactly(2))->method('getSupportedEncoderNames')->will($this->onConsecutiveCalls(
135  array(
136  'mockencoder', 'second_mockencoder'
137  ),
138  array(
139  'mockencoder'
140  )
141  ));
142 
143  $password_manager = new ilUserPasswordManager(
144  array(
145  'password_encoder' => 'md5',
146  'encoder_factory' => $factory_mock,
147  'data_directory' => $this->getTestDirectoryUrl()
148  )
149  );
150  $this->assertInstanceOf('ilUserPasswordManager', $password_manager);
151  $this->assertEquals('md5', $password_manager->getEncoderName());
152  $this->assertEquals($factory_mock, $password_manager->getEncoderFactory());
153 
154  $this->assertTrue($password_manager->isEncodingTypeSupported('second_mockencoder'));
155  $this->assertFalse($password_manager->isEncodingTypeSupported('second_mockencoder'));
156  }
+ Here is the call graph for this function:

◆ testPasswordManagerEncodesRawPasswordWithoutSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithoutSalt ( )

Definition at line 192 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl(), IL_PASSWD_CRYPTED, and Sabre\Event\once().

193  {
194  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
195  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
196  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
197 
198  $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->equalTo(null));
199  $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue(null));
200  $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
201  $user_mock->expects($this->once())->method('setPasswd')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(IL_PASSWD_CRYPTED));
202 
203  $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
204  $encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(false));
205  $encoder->expects($this->once())->method('encodePassword')->with($this->equalTo(self::PASSWORD), $this->equalTo(null))->will($this->returnValue(self::ENCODED_PASSWORD));
206 
207  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
208 
209  $password_manager = new ilUserPasswordManager(
210  array(
211  'password_encoder' => 'mockencoder',
212  'encoder_factory' => $factory_mock,
213  'data_directory' => $this->getTestDirectoryUrl()
214  )
215  );
216 
217  $password_manager->encodePassword($user_mock, self::PASSWORD);
218  }
const IL_PASSWD_CRYPTED
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testPasswordManagerEncodesRawPasswordWithSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithSalt ( )

Definition at line 161 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl(), IL_PASSWD_CRYPTED, and Sabre\Event\once().

162  {
163  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
164  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
165  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
166 
167  $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->isType('string'));
168  $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
169  $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
170  $user_mock->expects($this->once())->method('setPasswd')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(IL_PASSWD_CRYPTED));
171 
172  $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
173  $encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(true));
174  $encoder->expects($this->once())->method('encodePassword')->with($this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(self::ENCODED_PASSWORD));
175 
176  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
177 
178  $password_manager = new ilUserPasswordManager(
179  array(
180  'password_encoder' => 'mockencoder',
181  'encoder_factory' => $factory_mock,
182  'data_directory' => $this->getTestDirectoryUrl()
183  )
184  );
185 
186  $password_manager->encodePassword($user_mock, self::PASSWORD);
187  }
const IL_PASSWD_CRYPTED
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ( )

Definition at line 254 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl(), and Sabre\Event\once().

255  {
256  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
257  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
258  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
259 
260  $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
261  $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
262  $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
263  $user_mock->expects($this->once())->method('resetPassword')->with($this->equalTo(self::PASSWORD), $this->equalTo(self::PASSWORD));
264 
265  $encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
266  $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
267  $encoder->expects($this->never())->method('requiresReencoding')->with($this->equalTo(self::ENCODED_PASSWORD))->will($this->returnValue(false));
268 
269  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
270 
271  $password_manager = new ilUserPasswordManager(
272  array(
273  'password_encoder' => 'mockencoder',
274  'encoder_factory' => $factory_mock,
275  'data_directory' => $this->getTestDirectoryUrl()
276  )
277  );
278 
279  $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
280  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ( )

Definition at line 316 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl(), and Sabre\Event\once().

317  {
318  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
319  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
320  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
321 
322  $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
323  $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
324  $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
325  $user_mock->expects($this->never())->method('resetPassword');
326 
327  $encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
328  $encoder->expects($this->never())->method('requiresReencoding');
329  $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(false));
330 
331  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
332 
333  $password_manager = new ilUserPasswordManager(
334  array(
335  'password_encoder' => 'mockencoder',
336  'encoder_factory' => $factory_mock,
337  'data_directory' => $this->getTestDirectoryUrl()
338  )
339  );
340 
341  $this->assertFalse($password_manager->verifyPassword($user_mock, self::PASSWORD));
342  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testPasswordManagerReencodesPasswordIfReencodingIsNecessary()

ilObjUserPasswordTest::testPasswordManagerReencodesPasswordIfReencodingIsNecessary ( )

Definition at line 285 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl(), and Sabre\Event\once().

286  {
287  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
288  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
289  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
290 
291  $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
292  $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('mockencoder'));
293  $user_mock->expects($this->exactly(2))->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
294  $user_mock->expects($this->once())->method('resetPassword')->with($this->equalTo(self::PASSWORD), $this->equalTo(self::PASSWORD));
295 
296  $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
297  $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
298  $encoder->expects($this->once())->method('requiresReencoding')->with($this->equalTo(self::ENCODED_PASSWORD))->will($this->returnValue(true));
299 
300  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
301 
302  $password_manager = new ilUserPasswordManager(
303  array(
304  'password_encoder' => 'mockencoder',
305  'encoder_factory' => $factory_mock,
306  'data_directory' => $this->getTestDirectoryUrl()
307  )
308  );
309 
310  $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
311  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testPasswordManagerVerifiesPassword()

ilObjUserPasswordTest::testPasswordManagerVerifiesPassword ( )

Definition at line 223 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl(), and Sabre\Event\once().

224  {
225  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
226  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
227  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
228 
229  $user_mock->expects($this->atLeast(1))->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
230  $user_mock->expects($this->atLeast(1))->method('getPasswordEncodingType')->will($this->returnValue('mockencoder'));
231  $user_mock->expects($this->atLeast(1))->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
232  $user_mock->expects($this->never())->method('resetPassword');
233 
234  $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
235  $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
236  $encoder->expects($this->once())->method('requiresReencoding')->with($this->equalTo(self::ENCODED_PASSWORD))->will($this->returnValue(false));
237 
238  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
239 
240  $password_manager = new ilUserPasswordManager(
241  array(
242  'password_encoder' => 'mockencoder',
243  'encoder_factory' => $factory_mock,
244  'data_directory' => $this->getTestDirectoryUrl()
245  )
246  );
247 
248  $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
249  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

Field Documentation

◆ $test_directory

ilObjUserPasswordTest::$test_directory
protected

Definition at line 35 of file ilObjUserPasswordTest.php.

Referenced by getTestDirectory(), and setTestDirectory().

◆ $test_directory_url

ilObjUserPasswordTest::$test_directory_url
protected

Definition at line 40 of file ilObjUserPasswordTest.php.

Referenced by getTestDirectoryUrl(), and setTestDirectoryUrl().

◆ ENCODED_PASSWORD

const ilObjUserPasswordTest::ENCODED_PASSWORD = 'encoded'

Definition at line 30 of file ilObjUserPasswordTest.php.

◆ PASSWORD

const ilObjUserPasswordTest::PASSWORD = 'password'

Definition at line 25 of file ilObjUserPasswordTest.php.


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