PasswordHasherFactoryTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Auth\PasswordHasherFactory;
  17. use Cake\Core\Plugin;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * Test case for PasswordHasherFactory
  21. *
  22. */
  23. class PasswordHasherFactoryTest extends TestCase
  24. {
  25. /**
  26. * test passwordhasher instance building
  27. *
  28. * @return void
  29. */
  30. public function testBuild()
  31. {
  32. $hasher = PasswordHasherFactory::build('Default');
  33. $this->assertInstanceof('Cake\Auth\DefaultPasswordHasher', $hasher);
  34. $hasher = PasswordHasherFactory::build([
  35. 'className' => 'Default',
  36. 'hashOptions' => ['foo' => 'bar']
  37. ]);
  38. $this->assertInstanceof('Cake\Auth\DefaultPasswordHasher', $hasher);
  39. $this->assertEquals(['foo' => 'bar'], $hasher->config('hashOptions'));
  40. Plugin::load('TestPlugin');
  41. $hasher = PasswordHasherFactory::build('TestPlugin.Legacy');
  42. $this->assertInstanceof('TestPlugin\Auth\LegacyPasswordHasher', $hasher);
  43. }
  44. /**
  45. * test build() throws exception for non existent hasher
  46. *
  47. * @expectedException \RuntimeException
  48. * @expectedExceptionMessage Password hasher class "FooBar" was not found.
  49. * @return void
  50. */
  51. public function testBuildException()
  52. {
  53. $hasher = PasswordHasherFactory::build('FooBar');
  54. }
  55. }