+ public function test_return_routes_change_depending_on_entry_context()
+ {
+ $user = $this->users->admin();
+ $returnByContext = [
+ 'settings' => url("/settings/users/{$user->id}/#api_tokens"),
+ 'my-account' => url('/my-account/auth#api_tokens'),
+ ];
+
+ foreach ($returnByContext as $context => $returnUrl) {
+ $resp = $this->actingAs($user)->get("/api-tokens/{$user->id}/create?context={$context}");
+ $this->withHtml($resp)->assertLinkExists($returnUrl, 'Cancel');
+
+ $this->post("/api-tokens/{$user->id}/create", $this->testTokenData);
+ $token = $user->apiTokens()->latest()->first();
+
+ $resp = $this->get($token->getUrl());
+ $this->withHtml($resp)->assertLinkExists($returnUrl, 'Back');
+
+ $resp = $this->delete($token->getUrl());
+ $resp->assertRedirect($returnUrl);
+ }
+ }
+
+ public function test_context_assumed_for_editing_tokens_of_another_user()
+ {
+ $user = $this->users->viewer();
+
+ $resp = $this->asAdmin()->get("/api-tokens/{$user->id}/create?context=my-account");
+ $this->withHtml($resp)->assertLinkExists($user->getEditUrl('#api_tokens'), 'Cancel');
+ }
+}