File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
tests/TestCase/Controller/Component Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -240,6 +240,16 @@ public function getResult(): ?ResultInterface
240240 return $ this ->getAuthenticationService ()->getResult ();
241241 }
242242
243+ /**
244+ * Get the identifier (primary key) of the identity.
245+ *
246+ * @return array|string|int|null
247+ */
248+ public function getIdentifier (): array |string |int |null
249+ {
250+ return $ this ->getIdentity ()?->getIdentifier();
251+ }
252+
243253 /**
244254 * Returns the identity used in the authentication attempt.
245255 *
Original file line number Diff line number Diff line change @@ -143,6 +143,22 @@ public function testGetAuthenticationServiceInvalidServiceObject()
143143 $ component ->getAuthenticationService ();
144144 }
145145
146+ public function testGetId (): void
147+ {
148+ $ component = new AuthenticationComponent (new ComponentRegistry (new Controller ($ this ->request )));
149+ $ this ->assertNull ($ component ->getIdentifier ());
150+
151+ $ request = $ this ->request
152+ ->withAttribute ('identity ' , $ this ->identity )
153+ ->withAttribute ('authentication ' , $ this ->service );
154+
155+ $ controller = new Controller ($ request );
156+ $ registry = new ComponentRegistry ($ controller );
157+ $ component = new AuthenticationComponent ($ registry );
158+
159+ $ this ->assertSame ($ component ->getIdentifier (), $ this ->identity ->getIdentifier ());
160+ }
161+
146162 /**
147163 * testGetIdentity
148164 *
You can’t perform that action at this time.
0 commit comments