Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views_ui / tests / src / FunctionalJavascript / LibraryCachingTest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6
7 /**
8  * Tests the JavaScript library caching on consecutive requests.
9  *
10  * @group views_ui
11  */
12 class LibraryCachingTest extends WebDriverTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = ['node', 'views', 'views_ui'];
18
19   /**
20    * Tests if the Views UI dialogs open on consecutive requests.
21    */
22   public function testConsecutiveDialogRequests() {
23     $admin_user = $this->drupalCreateUser([
24       'administer site configuration',
25       'administer views',
26       'administer nodes',
27       'access content overview',
28     ]);
29
30     // Disable automatic live preview to make the sequence of calls clearer.
31     \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
32     $this->drupalLogin($admin_user);
33
34     $this->drupalGet('admin/structure/views/view/content');
35     $page = $this->getSession()->getPage();
36
37     // Use the 'Add' link for fields to open a dialog. This will load the proper
38     // dialog libraries.
39     $add_link = $page->findById('views-add-field');
40     $this->assertTrue($add_link->isVisible(), 'Add fields button found.');
41     $add_link->click();
42     $this->assertJsCondition("jQuery('.ui-dialog-titlebar').length > 0");
43     // Close the dialog and open it again. No no libraries will be loaded, but a
44     // cache entry will be made for not loading any libraries.
45     $page->pressButton('Close');
46     $add_link->click();
47     $this->assertJsCondition("jQuery('.ui-dialog-titlebar').length > 0");
48     $page->pressButton('Close');
49
50     // Reload the page.
51     $this->drupalGet('admin/structure/views/view/content');
52     $page = $this->getSession()->getPage();
53
54     // Now use the 'Update preview' button to load libraries.
55     $preview = $page->findById('preview-submit');
56     // The first click will load all the libraries.
57     $preview->click();
58     $this->assertJsCondition("jQuery('.ajax-progress').length === 0");
59     // The second click will not load any new libraries.
60     $preview->click();
61     $this->assertJsCondition("jQuery('.ajax-progress').length === 0");
62     // Check to see if the dialogs still open.
63     $add_link = $page->findById('views-add-field');
64     $add_link->click();
65     $this->assertJsCondition("jQuery('.ui-dialog-titlebar').length > 0");
66     $page->pressButton('Close');
67   }
68
69 }