Mercurial > hg > cmmr2012-drupal-site
comparison core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\FunctionalJavascriptTests\Ajax; | |
4 | |
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase; | |
6 | |
7 /** | |
8 * Tests AJAX responses. | |
9 * | |
10 * @group Ajax | |
11 */ | |
12 class AjaxTest extends JavascriptTestBase { | |
13 | |
14 /** | |
15 * {@inheritdoc} | |
16 */ | |
17 public static $modules = ['ajax_test']; | |
18 | |
19 public function testAjaxWithAdminRoute() { | |
20 \Drupal::service('theme_installer')->install(['stable', 'seven']); | |
21 $theme_config = \Drupal::configFactory()->getEditable('system.theme'); | |
22 $theme_config->set('admin', 'seven'); | |
23 $theme_config->set('default', 'stable'); | |
24 $theme_config->save(); | |
25 | |
26 $account = $this->drupalCreateUser(['view the administration theme']); | |
27 $this->drupalLogin($account); | |
28 | |
29 // First visit the site directly via the URL. This should render it in the | |
30 // admin theme. | |
31 $this->drupalGet('admin/ajax-test/theme'); | |
32 $assert = $this->assertSession(); | |
33 $assert->pageTextContains('Current theme: seven'); | |
34 | |
35 // Now click the modal, which should also use the admin theme. | |
36 $this->drupalGet('ajax-test/dialog'); | |
37 $assert->pageTextNotContains('Current theme: stable'); | |
38 $this->clickLink('Link 8 (ajax)'); | |
39 $assert->assertWaitOnAjaxRequest(); | |
40 | |
41 $assert->pageTextContains('Current theme: stable'); | |
42 $assert->pageTextNotContains('Current theme: seven'); | |
43 } | |
44 | |
45 /** | |
46 * Test that AJAX loaded libraries are not retained between requests. | |
47 * | |
48 * @see https://www.drupal.org/node/2647916 | |
49 */ | |
50 public function testDrupalSettingsCachingRegression() { | |
51 $this->drupalGet('ajax-test/dialog'); | |
52 $assert = $this->assertSession(); | |
53 $session = $this->getSession(); | |
54 | |
55 // Insert a fake library into the already loaded library settings. | |
56 $fake_library = 'fakeLibrary/fakeLibrary'; | |
57 $session->evaluateScript("drupalSettings.ajaxPageState.libraries = drupalSettings.ajaxPageState.libraries + ',$fake_library';"); | |
58 | |
59 $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries'); | |
60 // Test that the fake library is set. | |
61 $this->assertContains($fake_library, $libraries); | |
62 | |
63 // Click on the AJAX link. | |
64 $this->clickLink('Link 8 (ajax)'); | |
65 $assert->assertWaitOnAjaxRequest(); | |
66 | |
67 // Test that the fake library is still set after the AJAX call. | |
68 $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries'); | |
69 $this->assertContains($fake_library, $libraries); | |
70 | |
71 // Reload the page, this should reset the loaded libraries and remove the | |
72 // fake library. | |
73 $this->drupalGet('ajax-test/dialog'); | |
74 $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries'); | |
75 $this->assertNotContains($fake_library, $libraries); | |
76 | |
77 // Click on the AJAX link again, and the libraries should still not contain | |
78 // the fake library. | |
79 $this->clickLink('Link 8 (ajax)'); | |
80 $assert->assertWaitOnAjaxRequest(); | |
81 $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries'); | |
82 $this->assertNotContains($fake_library, $libraries); | |
83 } | |
84 | |
85 } |