PasswordHasherFactoryTest.php 1.9 KB

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