@@ -40,10 +40,10 @@ public function test_stale_callback_url_triggers_token_re_request() {
4040 $ code = 'test-code-verifier ' ;
4141 $ created_at = 1_640_995_200 ;
4242
43- // The stored hash differs from the current callback URL hash.
44- Monkey \ Functions \expect ( ' get_option ' )
45- ->with ( 'yoast_ai_generator_callback_url_hash ' , ' ' )
46- ->once ( )
43+ // The stored per-user hash differs from the current callback URL hash.
44+ $ this -> user_helper
45+ ->shouldReceive ( 'get_meta ' )
46+ ->with ( 123 , ' _yoast_wpseo_ai_generator_callback_url_hash ' , true )
4747 ->andReturn ( $ old_callback_hash );
4848
4949 $ this ->urls
@@ -108,13 +108,11 @@ public function test_stale_callback_url_triggers_token_re_request() {
108108 ->expects ( 'handle ' )
109109 ->once ();
110110
111- // Capture the update_option call to verify the hash is stored.
112- $ stored_option = [];
113- Monkey \Functions \when ( 'update_option ' )->alias (
114- static function () use ( &$ stored_option ) {
115- $ stored_option = \func_get_args ();
116- },
117- );
111+ // The new callback URL hash should be stored per-user.
112+ $ this ->user_helper
113+ ->expects ( 'update_meta ' )
114+ ->with ( 123 , '_yoast_wpseo_ai_generator_callback_url_hash ' , \md5 ( $ new_callback_url ) )
115+ ->once ();
118116
119117 Monkey \Functions \expect ( 'wp_cache_delete ' )
120118 ->with ( 123 , 'user_meta ' )
@@ -129,8 +127,6 @@ static function () use ( &$stored_option ) {
129127 $ result = $ this ->instance ->get_or_request_access_token ( $ user );
130128
131129 $ this ->assertEquals ( $ new_access_jwt , $ result );
132- $ this ->assertEquals ( 'yoast_ai_generator_callback_url_hash ' , $ stored_option [0 ] );
133- $ this ->assertEquals ( \md5 ( $ new_callback_url ), $ stored_option [1 ] );
134130 }
135131
136132 /**
@@ -184,10 +180,10 @@ public function test_empty_stored_hash_forces_token_re_request() {
184180 $ code = 'test-code-verifier ' ;
185181 $ created_at = 1_640_995_200 ;
186182
187- // No stored hash — return empty to trigger re-request.
188- Monkey \ Functions \expect ( ' get_option ' )
189- ->with ( 'yoast_ai_generator_callback_url_hash ' , ' ' )
190- ->once ( )
183+ // No stored per-user hash — return empty to trigger re-request.
184+ $ this -> user_helper
185+ ->shouldReceive ( 'get_meta ' )
186+ ->with ( 123 , ' _yoast_wpseo_ai_generator_callback_url_hash ' , true )
191187 ->andReturn ( '' );
192188
193189 // Stale tokens should be deleted.
@@ -252,13 +248,11 @@ public function test_empty_stored_hash_forces_token_re_request() {
252248 ->expects ( 'handle ' )
253249 ->once ();
254250
255- // Capture the update_option call to verify the hash is stored.
256- $ stored_option = [];
257- Monkey \Functions \when ( 'update_option ' )->alias (
258- static function () use ( &$ stored_option ) {
259- $ stored_option = \func_get_args ();
260- },
261- );
251+ // The new callback URL hash should be stored per-user.
252+ $ this ->user_helper
253+ ->expects ( 'update_meta ' )
254+ ->with ( 123 , '_yoast_wpseo_ai_generator_callback_url_hash ' , \md5 ( $ new_callback_url ) )
255+ ->once ();
262256
263257 Monkey \Functions \expect ( 'wp_cache_delete ' )
264258 ->with ( 123 , 'user_meta ' )
@@ -273,12 +267,10 @@ static function () use ( &$stored_option ) {
273267 $ result = $ this ->instance ->get_or_request_access_token ( $ user );
274268
275269 $ this ->assertEquals ( $ new_access_jwt , $ result );
276- $ this ->assertEquals ( 'yoast_ai_generator_callback_url_hash ' , $ stored_option [0 ] );
277- $ this ->assertEquals ( \md5 ( $ new_callback_url ), $ stored_option [1 ] );
278270 }
279271
280272 /**
281- * Tests that token_request stores the callback URL hash.
273+ * Tests that token_request stores the callback URL hash per-user .
282274 *
283275 * @return void
284276 */
@@ -336,21 +328,16 @@ public function test_token_request_stores_callback_url_hash() {
336328 ->expects ( 'handle ' )
337329 ->once ();
338330
339- // Capture the update_option call to verify the hash is stored.
340- $ stored_option = [];
341- Monkey \Functions \when ( 'update_option ' )->alias (
342- static function () use ( &$ stored_option ) {
343- $ stored_option = \func_get_args ();
344- },
345- );
331+ // Verify the per-user hash is stored after successful token request.
332+ $ this ->user_helper
333+ ->expects ( 'update_meta ' )
334+ ->with ( 123 , '_yoast_wpseo_ai_generator_callback_url_hash ' , \md5 ( $ callback_url ) )
335+ ->once ();
346336
347337 Monkey \Functions \expect ( 'wp_cache_delete ' )
348338 ->with ( 123 , 'user_meta ' )
349339 ->once ();
350340
351341 $ this ->instance ->token_request ( $ user );
352-
353- $ this ->assertEquals ( 'yoast_ai_generator_callback_url_hash ' , $ stored_option [0 ] );
354- $ this ->assertEquals ( \md5 ( $ callback_url ), $ stored_option [1 ] );
355342 }
356343}
0 commit comments