@@ -35,25 +35,55 @@ public function testGetSecurity()
35
35
$ this ->assertSame ($ securityContext , $ this ->globals ->getSecurity ());
36
36
}
37
37
38
- public function testGetUser ()
38
+ public function testGetUserNoTokenStorage ()
39
39
{
40
- // missing test cases to return null, only happy flow tested
41
- $ securityContext = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface ' );
40
+ $ this ->assertNull ($ this ->globals ->getUser ());
41
+ }
42
+
43
+ public function testGetUserNoToken ()
44
+ {
45
+ $ tokenStorage = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface ' );
46
+ $ this ->container ->set ('security.token_storage ' , $ tokenStorage );
47
+ $ this ->assertNull ($ this ->globals ->getUser ());
48
+ }
49
+
50
+ /**
51
+ * @dataProvider getUserProvider
52
+ */
53
+ public function testGetUser ($ user , $ expectedUser )
54
+ {
55
+ $ tokenStorage = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface ' );
42
56
$ token = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' );
43
- $ user = $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' );
44
57
45
- $ this ->container ->set ('security.token_storage ' , $ securityContext );
58
+ $ this ->container ->set ('security.token_storage ' , $ tokenStorage );
46
59
47
60
$ token
48
61
->expects ($ this ->once ())
49
62
->method ('getUser ' )
50
63
->will ($ this ->returnValue ($ user ));
51
64
52
- $ securityContext
65
+ $ tokenStorage
53
66
->expects ($ this ->once ())
54
67
->method ('getToken ' )
55
68
->will ($ this ->returnValue ($ token ));
56
69
57
- $ this ->assertSame ($ user , $ this ->globals ->getUser ());
70
+ $ this ->assertSame ($ expectedUser , $ this ->globals ->getUser ());
71
+ }
72
+
73
+ public function getUserProvider ()
74
+ {
75
+ $ user = $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' );
76
+ $ std = new \stdClass ();
77
+ $ token = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' );
78
+
79
+ return array (
80
+ array ($ user , $ user ),
81
+ array ($ std , $ std ),
82
+ array ($ token , $ token ),
83
+ array ('Anon. ' , null ),
84
+ array (null , null ),
85
+ array (10 , null ),
86
+ array (true , null ),
87
+ );
58
88
}
59
89
}
0 commit comments