public function CommandsTest::testAttachedSettings in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Ajax/CommandsTest.php \Drupal\system\Tests\Ajax\CommandsTest::testAttachedSettings()
Regression test: Settings command exists regardless of JS aggregation.
File
- core/
modules/ system/ src/ Tests/ Ajax/ CommandsTest.php, line 131 - Contains \Drupal\system\Tests\Ajax\CommandsTest.
Class
- CommandsTest
- Performs tests on AJAX framework commands.
Namespace
Drupal\system\Tests\AjaxCode
public function testAttachedSettings() {
$assert = function ($message) {
$response = new AjaxResponse();
$response
->setAttachments([
'library' => [
'core/drupalSettings',
],
'drupalSettings' => [
'foo' => 'bar',
],
]);
$ajax_response_attachments_processor = \Drupal::service('ajax_response.attachments_processor');
$subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor);
$event = new FilterResponseEvent(\Drupal::service('http_kernel'), new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$subscriber
->onResponse($event);
$expected = [
'command' => 'settings',
];
$this
->assertCommand($response
->getCommands(), $expected, $message);
};
$config = $this
->config('system.performance');
$config
->set('js.preprocess', FALSE)
->save();
$assert('Settings command exists when JS aggregation is disabled.');
$config
->set('js.preprocess', TRUE)
->save();
$assert('Settings command exists when JS aggregation is enabled.');
}