@@ -911,7 +911,7 @@ public function amOnAction($action, $params = [])
911911 $ controller = basename ($ route ->getDefault ('_controller ' ));
912912 if ($ controller === $ action ) {
913913 $ resource = $ router ->match ($ route ->getPath ());
914- $ url = $ router ->generate (
914+ $ url = $ router ->generate (
915915 $ resource ['_route ' ],
916916 $ params ,
917917 UrlGeneratorInterface::ABSOLUTE_PATH
@@ -921,4 +921,43 @@ public function amOnAction($action, $params = [])
921921 }
922922 }
923923 }
924+
925+ /**
926+ * Checks that a user is authenticated.
927+ * You can check users logged in with the option 'remember me' passing true as parameter.
928+ *
929+ * ```php
930+ * <?php
931+ * $I->seeAuthentication();
932+ * $I->seeAuthentication(true);
933+ * ```
934+ *
935+ * @param bool $remembered
936+ */
937+ public function seeAuthentication ($ remembered = false )
938+ {
939+ $ container = $ this ->_getContainer ();
940+
941+ if (!$ container ->has ('security.helper ' )) {
942+ $ this ->fail ("Symfony container doesn't have 'security.helper' service " );
943+ return ;
944+ }
945+
946+ $ security = $ this ->grabService ('security.helper ' );
947+
948+ $ user = $ security ->getUser ();
949+
950+ if (!$ user ) {
951+ $ this ->fail ('There is no user in session ' );
952+ return ;
953+ }
954+
955+ if ($ remembered ) {
956+ $ role = 'IS_AUTHENTICATED_REMEMBERED ' ;
957+ } else {
958+ $ role = 'IS_AUTHENTICATED_FULLY ' ;
959+ }
960+
961+ $ this ->assertTrue ($ security ->isGranted ($ role ), 'There is no authenticated user ' );
962+ }
924963}
0 commit comments