3 namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\views\Tests\ViewTestData;
11 * Tests the grouped exposed filter admin UI.
15 class GroupedExposedFilterTest extends WebDriverTestBase {
20 public static $modules = ['node', 'views', 'views_ui', 'user', 'views_test_config'];
23 * Views used by this test.
27 public static $testViews = ['test_exposed_admin_ui'];
32 * @var \Drupal\user\UserInterface
39 protected function setUp() {
42 ViewTestData::createTestViews(get_class($this), ['views_test_config']);
44 // Disable automatic live preview to make the sequence of calls clearer.
45 \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
47 $this->account = $this->drupalCreateUser(['administer views']);
48 $this->drupalLogin($this->account);
50 // Setup a node type that has the right fields for the test view.
56 'entity_type' => 'node',
57 'field_name' => 'body',
63 * Test if the right fields are shown and the right values set.
65 public function testGroupedFilterValuesUI() {
66 $web_assert = $this->assertSession();
68 $this->drupalGet('/admin/structure/views/view/test_exposed_admin_ui');
69 $page = $this->getSession()->getPage();
71 // Open the dialog for the grouped filter.
72 $page->clickLink('Content: Authored on (grouped)');
73 $web_assert->assertWaitOnAjaxRequest();
75 // Test that the 'min' field is shown and that it contains the right value.
76 $between_from = $page->findField('options[group_info][group_items][1][value][min]');
77 $this->assertNotEmpty($between_from->isVisible());
78 $this->assertEquals('2015-01-01', $between_from->getValue());
80 // Test that the 'max' field is shown and that it contains the right value.
81 $between_to = $page->findField('options[group_info][group_items][1][value][max]');
82 $this->assertNotEmpty($between_to->isVisible());
83 $this->assertEquals('2016-01-01', $between_to->getValue());
85 $weight = $page->findField('options[group_info][group_items][1][weight]');
87 // If there are 3 items, values from -3 to 3 should be available.
88 $this->assertFalse($weight->find('named', ['option', -4]));
89 foreach (range(-3, 3) as $value) {
90 $this->assertTrue($weight->find('named', ['option', $value]));
92 $this->assertFalse($weight->find('named', ['option', 4]));
94 $page->pressButton("Add another item");
95 $web_assert->waitForField('options[group_info][group_items][4][title]');
97 // A new items was added, weight options should now be -4 to 4.
98 $this->assertFalse($weight->find('named', ['option', -5]));
99 foreach (range(-4, 4) as $value) {
100 $this->assertTrue($weight->find('named', ['option', $value]));
102 $this->assertFalse($weight->find('named', ['option', 5]));