diff --git a/core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml b/core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml index 34f7844..e8d06c0 100644 --- a/core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml +++ b/core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml @@ -35,6 +35,13 @@ ajax_test.render: requirements: _access: 'TRUE' +ajax_test.admin.theme: + path: '/admin/ajax-test/theme' + defaults: + _controller: '\Drupal\ajax_test\Controller\AjaxTestController::theme' + requirements: + _access: 'TRUE' + ajax_test.order: path: '/ajax-test/order' defaults: diff --git a/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php b/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php index fbbb2b5..9f10db4 100644 --- a/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php +++ b/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php @@ -6,6 +6,7 @@ use Drupal\Core\Ajax\AlertCommand; use Drupal\Core\Ajax\CloseDialogCommand; use Drupal\Core\Ajax\HtmlCommand; +use Drupal\Core\EventSubscriber\MainContentViewSubscriber; use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Request; @@ -62,6 +63,15 @@ public function render() { } /** + * Returns the used theme. + */ + public function theme() { + return [ + '#markup' => 'Current theme: ' . \Drupal::theme()->getActiveTheme()->getName(), + ]; + } + + /** * Returns an AjaxResponse; settings command set last. * * Helps verifying AjaxResponse reorders commands to ensure correct execution. @@ -184,6 +194,17 @@ public function dialog() { )) ), ), + 'link8' => [ + 'title' => 'Link 8 (ajax)', + 'url' => Url::fromRoute('ajax_test.admin.theme'), + 'attributes' => [ + 'class' => ['use-ajax'], + 'data-dialog-type' => 'modal', + 'data-dialog-options' => json_encode([ + 'width' => 400, + ]) + ], + ] ), ); diff --git a/core/tests/Drupal/FunctionalJavascriptTests/AjaxThemeTest.php b/core/tests/Drupal/FunctionalJavascriptTests/AjaxThemeTest.php new file mode 100644 index 0000000..0eb6d19 --- /dev/null +++ b/core/tests/Drupal/FunctionalJavascriptTests/AjaxThemeTest.php @@ -0,0 +1,43 @@ +install(['seven']); + $theme_config = \Drupal::configFactory()->getEditable('system.theme'); + $theme_config->set('admin', 'seven'); + $theme_config->save(); + + $account = $this->drupalCreateUser(['view the administration theme']); + $this->drupalLogin($account); + + // First visit the site directly via the URL. This should render it in the + // admin theme. + $this->drupalGet('/admin/ajax-test/theme'); + $assert = $this->assertSession(); + $assert->pageTextContains('Current theme: seven'); + + // Now + $this->drupalGet('/ajax-test/dialog'); + $assert->pageTextNotContains('Current theme: stable'); + $this->clickLink('Link 8 (ajax)'); + + $assert->pageTextContains('Current theme: stable'); + $assert->pageTextNotContains('Current theme: seven'); + $this->clickLink('Link 8 (ajax)'); + } + + +}