PasswordHasherFactoryTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Auth;
  16. use Cake\Core\Plugin;
  17. use Cake\Auth\PasswordHasherFactory;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * Test case for PasswordHasherFactory
  21. *
  22. */
  23. class PasswordHasherFactoryTest extends TestCase {
  24. /**
  25. * test passwordhasher instance building
  26. *
  27. * @return void
  28. */
  29. public function testBuild() {
  30. $hasher = PasswordHasherFactory::build('Default');
  31. $this->assertInstanceof('Cake\Auth\DefaultPasswordHasher', $hasher);
  32. $hasher = PasswordHasherFactory::build([
  33. 'className' => 'Default',
  34. 'hashOptions' => ['foo' =>' bar']
  35. ]);
  36. $this->assertInstanceof('Cake\Auth\DefaultPasswordHasher', $hasher);
  37. $this->assertEquals(['foo' =>' bar'], $hasher->config('hashOptions'));
  38. Plugin::load('TestPlugin');
  39. $hasher = PasswordHasherFactory::build('TestPlugin.Legacy');
  40. $this->assertInstanceof('TestPlugin\Auth\LegacyPasswordHasher', $hasher);
  41. }
  42. /**
  43. * test build() throws exception for non existent hasher
  44. *
  45. * @expectedException \RuntimeException
  46. * @expectedExceptionMessage Password hasher class "FooBar" was not found.
  47. * @return void
  48. */
  49. public function testBuildException() {
  50. $hasher = PasswordHasherFactory::build('FooBar');
  51. }
  52. }