Chris@0: install(['stable', 'seven']);
Chris@0: $theme_config = \Drupal::configFactory()->getEditable('system.theme');
Chris@0: $theme_config->set('admin', 'seven');
Chris@0: $theme_config->set('default', 'stable');
Chris@0: $theme_config->save();
Chris@0:
Chris@0: $account = $this->drupalCreateUser(['view the administration theme']);
Chris@0: $this->drupalLogin($account);
Chris@0:
Chris@0: // First visit the site directly via the URL. This should render it in the
Chris@0: // admin theme.
Chris@0: $this->drupalGet('admin/ajax-test/theme');
Chris@0: $assert = $this->assertSession();
Chris@0: $assert->pageTextContains('Current theme: seven');
Chris@0:
Chris@0: // Now click the modal, which should also use the admin theme.
Chris@0: $this->drupalGet('ajax-test/dialog');
Chris@0: $assert->pageTextNotContains('Current theme: stable');
Chris@0: $this->clickLink('Link 8 (ajax)');
Chris@0: $assert->assertWaitOnAjaxRequest();
Chris@0:
Chris@0: $assert->pageTextContains('Current theme: stable');
Chris@0: $assert->pageTextNotContains('Current theme: seven');
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Test that AJAX loaded libraries are not retained between requests.
Chris@0: *
Chris@0: * @see https://www.drupal.org/node/2647916
Chris@0: */
Chris@0: public function testDrupalSettingsCachingRegression() {
Chris@0: $this->drupalGet('ajax-test/dialog');
Chris@0: $assert = $this->assertSession();
Chris@0: $session = $this->getSession();
Chris@0:
Chris@0: // Insert a fake library into the already loaded library settings.
Chris@0: $fake_library = 'fakeLibrary/fakeLibrary';
Chris@0: $session->evaluateScript("drupalSettings.ajaxPageState.libraries = drupalSettings.ajaxPageState.libraries + ',$fake_library';");
Chris@0:
Chris@0: $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries');
Chris@0: // Test that the fake library is set.
Chris@0: $this->assertContains($fake_library, $libraries);
Chris@0:
Chris@0: // Click on the AJAX link.
Chris@0: $this->clickLink('Link 8 (ajax)');
Chris@0: $assert->assertWaitOnAjaxRequest();
Chris@0:
Chris@0: // Test that the fake library is still set after the AJAX call.
Chris@0: $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries');
Chris@0: $this->assertContains($fake_library, $libraries);
Chris@0:
Chris@0: // Reload the page, this should reset the loaded libraries and remove the
Chris@0: // fake library.
Chris@0: $this->drupalGet('ajax-test/dialog');
Chris@0: $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries');
Chris@0: $this->assertNotContains($fake_library, $libraries);
Chris@0:
Chris@0: // Click on the AJAX link again, and the libraries should still not contain
Chris@0: // the fake library.
Chris@0: $this->clickLink('Link 8 (ajax)');
Chris@0: $assert->assertWaitOnAjaxRequest();
Chris@0: $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries');
Chris@0: $this->assertNotContains($fake_library, $libraries);
Chris@0: }
Chris@0:
Chris@17: /**
Chris@17: * Tests that various AJAX responses with DOM elements are correctly inserted.
Chris@17: *
Chris@17: * After inserting DOM elements, Drupal JavaScript behaviors should be
Chris@17: * reattached and all top-level elements of type Node.ELEMENT_NODE need to be
Chris@17: * part of the context.
Chris@17: */
Chris@17: public function testInsertAjaxResponse() {
Chris@17: $render_single_root = [
Chris@17: 'pre-wrapped-div' => '