|
3
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the FOSUserBundle package. |
|
|
5 |
* |
|
|
6 |
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace FOS\UserBundle\Tests\Security\Encoder; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder; |
|
|
15 |
use FOS\UserBundle\Security\Encoder\EncoderFactory; |
|
|
16 |
|
|
|
17 |
class EncoderFactoryTest extends \PHPUnit_Framework_TestCase |
|
|
18 |
{ |
|
|
19 |
/** |
|
|
20 |
* @covers FOS\UserBundle\Security\Encoder\EncoderFactory::getEncoder |
|
|
21 |
* @covers FOS\UserBundle\Security\Encoder\EncoderFactory::createEncoder |
|
|
22 |
*/ |
|
|
23 |
public function testGetEncoderWithUserAccount() |
|
|
24 |
{ |
|
|
25 |
$factory = new EncoderFactory( |
|
|
26 |
'Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder', |
|
|
27 |
false, |
|
|
28 |
1, |
|
|
29 |
$this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface') |
|
|
30 |
); |
|
|
31 |
|
|
|
32 |
$userAccount = $this->getMock('FOS\UserBundle\Model\UserInterface'); |
|
|
33 |
|
|
|
34 |
$userAccount->expects($this->once()) |
|
|
35 |
->method('getAlgorithm') |
|
|
36 |
->will($this->returnValue('sha512')); |
|
|
37 |
|
|
|
38 |
$encoder = $factory->getEncoder($userAccount); |
|
|
39 |
|
|
|
40 |
$expectedEncoder = new MessageDigestPasswordEncoder('sha512', false, 1); |
|
|
41 |
|
|
|
42 |
$this->assertEquals($expectedEncoder->encodePassword('foo', 'bar'), $encoder->encodePassword('foo', 'bar')); |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
public function testGetEncoderWithGenericAccount() |
|
|
46 |
{ |
|
|
47 |
$genericFactory = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface'); |
|
|
48 |
$encoder = $this->getMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface'); |
|
|
49 |
|
|
|
50 |
$genericFactory |
|
|
51 |
->expects($this->once()) |
|
|
52 |
->method('getEncoder') |
|
|
53 |
->will($this->returnValue($encoder)) |
|
|
54 |
; |
|
|
55 |
|
|
|
56 |
$factory = new EncoderFactory(null , false, 1, $genericFactory); |
|
|
57 |
|
|
|
58 |
$this->assertSame($encoder, $factory->getEncoder($this->getMock('Symfony\Component\Security\Core\User\UserInterface'))); |
|
|
59 |
} |
|
|
60 |
} |