Skip to content
Snippets Groups Projects
Commit d88e5580 authored by ambient.impact's avatar ambient.impact
Browse files

Issue #3401146: Added basic drupalSettings merging test.

parent 1bdd51f6
Branches
Tags
No related merge requests found
Pipeline #390137 passed
<?php
declare(strict_types=1);
namespace Drupal\Tests\refreshless_turbo\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\refreshless_turbo\FunctionalJavascript\TurboAssertTrait;
use Drupal\Tests\refreshless_turbo\FunctionalJavascript\TurboHtmlDebugTrait;
/**
* drupalSettings updater tests.
*
* @group refreshless
*
* @group refreshless_turbo
*/
class DrupalSettingsTest extends WebDriverTestBase {
use TurboAssertTrait;
use TurboHtmlDebugTrait;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = ['block', 'refreshless_turbo', 'system'];
/**
* Assert that a drupalSettings property equals an expected value.
*
* @param string $propertyName
* The property name. Note that 'drupalSettings.' is prepended automatically
* and so should not be included.
*
* @param string $expectedValue
* The expected value of the property.
*/
protected function assertDrupalSettingsValue(
string $propertyName, string $expectedValue,
): void {
$actualValue = $this->getSession()->evaluateScript(<<<JS
return drupalSettings.{$propertyName};
JS);
$this->assertEquals(
$expectedValue, $actualValue,
"drupalSettings.$propertyName was expected to equal \"$expectedValue\" but got \"$actualValue\"!",
);
}
/**
* Test that drupalSettings updates are merged when navigating to new pages.
*/
public function testMerging(): void {
$this->drupalPlaceBlock('local_tasks_block', [
'region' => 'content', 'id' => 'local-tasks-block',
]);
$loginUrl = Url::fromRoute('user.login');
$registerUrl = Url::fromRoute('user.register');
$resetPasswordUrl = Url::fromRoute('user.pass');
$this->drupalGet($loginUrl);
$this->assertSession()->assertTurboIsPresent();
$this->assertSession()->startTurboPersist();
$this->assertDrupalSettingsValue(
'path.currentPath', $loginUrl->getInternalPath(),
);
$this->click('[data-drupal-link-system-path="' .
$registerUrl->getInternalPath() .
'"]');
$this->assertSession()->assertWaitOnTurboRequest();
$this->assertSession()->assertTurboPersisted();
$this->assertDrupalSettingsValue(
'path.currentPath', $registerUrl->getInternalPath(),
);
$this->turboHtmlOutput();
$this->click('[data-drupal-link-system-path="' .
$resetPasswordUrl->getInternalPath() .
'"]');
$this->assertSession()->assertWaitOnTurboRequest();
$this->assertSession()->assertTurboPersisted();
$this->assertDrupalSettingsValue(
'path.currentPath', $resetPasswordUrl->getInternalPath(),
);
$this->turboHtmlOutput();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment