11
11
12
12
namespace Symfony \Component \Security \Tests \Core \Authentication \Token ;
13
13
14
+ use Symfony \Component \Security \Core \Authentication \Token \AbstractToken ;
14
15
use Symfony \Component \Security \Core \Role \Role ;
16
+ use Symfony \Component \Security \Core \Role \SwitchUserRole ;
15
17
16
18
class TestUser
17
19
{
@@ -28,6 +30,31 @@ public function __toString()
28
30
}
29
31
}
30
32
33
+ class ConcreteToken extends AbstractToken
34
+ {
35
+ private $ credentials = 'credentials_value ' ;
36
+
37
+ public function __construct ($ user , array $ roles = array ())
38
+ {
39
+ parent ::__construct ($ roles );
40
+
41
+ $ this ->setUser ($ user );
42
+ }
43
+
44
+ public function serialize ()
45
+ {
46
+ return serialize (array ($ this ->credentials , parent ::serialize ()));
47
+ }
48
+
49
+ public function unserialize ($ serialized )
50
+ {
51
+ list ($ this ->credentials , $ parentStr ) = unserialize ($ serialized );
52
+ parent ::unserialize ($ parentStr );
53
+ }
54
+
55
+ public function getCredentials () {}
56
+ }
57
+
31
58
class AbstractTokenTest extends \PHPUnit_Framework_TestCase
32
59
{
33
60
public function testGetUsername ()
@@ -71,6 +98,20 @@ public function testSerialize()
71
98
$ this ->assertEquals ($ token ->getAttributes (), $ uToken ->getAttributes ());
72
99
}
73
100
101
+ public function testSerializeParent ()
102
+ {
103
+ $ user = new TestUser ('fabien ' );
104
+ $ token = new ConcreteToken ($ user , array ('ROLE_FOO ' ));
105
+
106
+ $ parentToken = new ConcreteToken ($ user , array (new SwitchUserRole ('ROLE_PREVIOUS ' , $ token )));
107
+ $ uToken = unserialize (serialize ($ parentToken ));
108
+
109
+ $ this ->assertEquals (
110
+ current ($ parentToken ->getRoles ())->getSource ()->getUser (),
111
+ current ($ uToken ->getRoles ())->getSource ()->getUser ()
112
+ );
113
+ }
114
+
74
115
/**
75
116
* @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::__construct
76
117
*/
0 commit comments