Skip to content
Snippets Groups Projects
Commit 17c1f059 authored by utkarsh_33's avatar utkarsh_33 Committed by Chris Wells
Browse files

Issue #3476818: Use actual page URL instead of hardcoding the query string in unlock URL

parent 65f13c5b
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -39,12 +39,20 @@
// The popup function expects an element, so a div containing the error
// message is created here for it to display in a modal.
const div = document.createElement('div');
const currentUrl =
window.location.pathname + window.location.search + window.location.hash;
if (err.unlock_url) {
div.innerHTML += `<p>${errorMessage} <a href="${
err.unlock_url
}&destination=admin/modules/browse">${Drupal.t(
'Unlock Install Stage',
)}</a></p>`;
try {
const unlockUrl = new URL(err.unlock_url, BASE_URL);
unlockUrl.searchParams.set('destination', currentUrl);
div.innerHTML += `<p>${errorMessage} <a href="${
unlockUrl.pathname + unlockUrl.search
}" id="unlock-link">${Drupal.t('Unlock Install Stage')}</a></p>`;
} catch (urlError) {
div.innerHTML += `<p>${errorMessage}</p>`;
}
} else {
div.innerHTML += `<p>${errorMessage}</p>`;
}
......
......@@ -422,4 +422,27 @@ class ProjectBrowserInstallerUiTest extends WebDriverTestBase {
$this->assertNotEmpty($assert_session->waitForButton('Install selected projects'));
}
/**
* Tests that unlock url has correct href.
*/
public function testUnlockLinkMarkup(): void {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalGet('admin/modules/project_browser/install-begin');
$this->installState->deleteAll();
$this->drupalGet('admin/modules/browse');
$this->svelteInitHelper('text', 'Cream cheese on a bagel');
$cream_cheese_module_selector = '#project-browser .pb-layout__main ul > li:nth-child(1)';
$download_button = $assert_session->waitForElementVisible('css', "$cream_cheese_module_selector button.project__action_button");
$this->assertNotEmpty($download_button);
$this->assertSame('Select Cream cheese on a bagel', $download_button->getText());
$download_button->click();
$this->assertNotEmpty($assert_session->waitForButton('Install selected projects'));
$page->pressButton('Install selected projects');
$this->assertMatchesRegularExpression(
'/.*\/admin\/modules\/project_browser\/install\/unlock\?token=[\w\-]+&destination=.*\/admin\/modules\/browse$/',
urldecode($assert_session->waitForElementVisible('css', "#unlock-link")->getAttribute('href'))
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment