15
15
use Symfony \Cmf \Bundle \CoreBundle \PublishWorkflow \PublishTimePeriodReadInterface ;
16
16
use Symfony \Cmf \Bundle \CoreBundle \PublishWorkflow \PublishWorkflowChecker ;
17
17
use Symfony \Cmf \Component \Testing \Functional \BaseTestCase ;
18
+ use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
18
19
use Symfony \Component \Security \Core \Authentication \Token \UsernamePasswordToken ;
19
20
use Symfony \Component \Security \Core \Authorization \AuthorizationCheckerInterface ;
20
21
@@ -25,9 +26,15 @@ class PublishWorkflowTest extends BaseTestCase
25
26
*/
26
27
private $ publishWorkflowChecker ;
27
28
29
+ /**
30
+ * @var TokenStorageInterface
31
+ */
32
+ private $ tokenStorage ;
33
+
28
34
public function setUp (): void
29
35
{
30
36
$ this ->publishWorkflowChecker = $ this ->getContainer ()->get ('cmf_core.publish_workflow.checker ' );
37
+ $ this ->tokenStorage = $ this ->getContainer ()->get ('test.service_container ' )->get ('security.token_storage ' );
31
38
}
32
39
33
40
public function testPublishable ()
@@ -69,8 +76,7 @@ public function testIgnoreRoleHas()
69
76
'ROLE_CAN_VIEW_NON_PUBLISHED ' ,
70
77
];
71
78
$ token = new UsernamePasswordToken ('test ' , 'pass ' , 'testprovider ' , $ roles );
72
- $ tokenStorage = $ this ->getContainer ()->get ('security.token_storage ' );
73
- $ tokenStorage ->setToken ($ token );
79
+ $ this ->tokenStorage ->setToken ($ token );
74
80
75
81
$ this ->assertTrue ($ this ->publishWorkflowChecker ->isGranted (PublishWorkflowChecker::VIEW_ATTRIBUTE , $ doc ));
76
82
$ this ->assertFalse ($ this ->publishWorkflowChecker ->isGranted (PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE , $ doc ));
@@ -87,8 +93,7 @@ public function testIgnoreRoleNotHas()
87
93
'OTHER_ROLE ' ,
88
94
];
89
95
$ token = new UsernamePasswordToken ('test ' , 'pass ' , 'testprovider ' , $ roles );
90
- $ tokenStorage = $ this ->getContainer ()->get ('security.token_storage ' );
91
- $ tokenStorage ->setToken ($ token );
96
+ $ this ->tokenStorage ->setToken ($ token );
92
97
93
98
$ this ->assertFalse ($ this ->publishWorkflowChecker ->isGranted (PublishWorkflowChecker::VIEW_ATTRIBUTE , $ doc ));
94
99
$ this ->assertFalse ($ this ->publishWorkflowChecker ->isGranted (PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE , $ doc ));
0 commit comments