f0ac6085487c076ee1d5e45ff7f08a1b5a928678
[yaffs-website] / web / core / modules / views / tests / src / FunctionalJavascript / Plugin / views / Handler / ContextualFilterTest.php
1 <?php
2
3 namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler;
4
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6 use Drupal\views\Tests\ViewTestData;
7
8 /**
9  * Tests the contextual filter handler UI.
10  *
11  * @group views
12  */
13 class ContextualFilterTest extends WebDriverTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['node', 'views', 'views_ui', 'views_test_config'];
19
20   /**
21    * Views used by this test.
22    *
23    * @var array
24    */
25   public static $testViews = ['test_field_body'];
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUp() {
31     parent::setUp();
32
33     ViewTestData::createTestViews(get_class($this), ['views_test_config']);
34
35     // Always show advanced column.
36     \Drupal::configFactory()->getEditable('views.settings')->set('ui.show.advanced_column', TRUE)->save();
37
38     // Disable automatic live preview to make the sequence of calls clearer. And
39     // prevent errors on saving the view with the preview ajax load that are
40     // cancelled.
41     \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
42
43     $account = $this->drupalCreateUser(['administer views']);
44     $this->drupalLogin($account);
45   }
46
47   /**
48    * Test adding a contextual filter handler through the UI.
49    */
50   public function testAddContextualFilterUI() {
51     $this->drupalGet('/admin/structure/views/view/test_field_body');
52
53     $web_assert = $this->assertSession();
54     $page = $this->getSession()->getPage();
55
56     $page->clickLink('views-add-argument');
57
58     $field = $web_assert->waitForField('name[node_field_data.nid]');
59     $this->assertNotEmpty($field);
60     $field->check();
61
62     $add_button = $page->find('css', '.ui-dialog-buttonset .button--primary');
63     $add_button->click();
64
65     $field_action = $web_assert->waitForField('options[default_action]');
66     $this->assertNotEmpty($field_action);
67     $field_action->setValue('default');
68
69     $page->selectFieldOption('options[default_argument_type]', 'node');
70     $add_button = $page->find('css', '.ui-dialog-buttonset .button--primary');
71     $add_button->click();
72
73     // Wait for the dialog to close.
74     $page->waitFor(10, function () use ($page) {
75       $field = $page->find('css', '.ui-dialog-buttonset .button--primary');
76       return empty($field);
77     });
78
79     $page->pressButton('edit-actions-submit');
80
81     $page->clickLink('Content: ID');
82     // Check that the dialog opens.
83     $field_action = $web_assert->waitForField('options[default_action]');
84     $this->assertNotEmpty($field_action);
85   }
86
87 }