View source
<?php
namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler;
use Drupal\field\Entity\FieldConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\ViewTestData;
class GroupedExposedFilterTest extends WebDriverTestBase {
protected static $modules = [
'node',
'views',
'views_ui',
'user',
'views_test_config',
];
protected $defaultTheme = 'stark';
public static $testViews = [
'test_exposed_admin_ui',
];
protected $account;
protected function setUp() : void {
parent::setUp();
ViewTestData::createTestViews(static::class, [
'views_test_config',
]);
\Drupal::configFactory()
->getEditable('views.settings')
->set('ui.always_live_preview', FALSE)
->save();
$this->account = $this
->drupalCreateUser([
'administer views',
]);
$this
->drupalLogin($this->account);
NodeType::create([
'type' => 'page',
])
->save();
FieldConfig::create([
'entity_type' => 'node',
'field_name' => 'body',
'bundle' => 'page',
])
->save();
}
public function testGroupedFilterValuesUI() {
$web_assert = $this
->assertSession();
$this
->drupalGet('/admin/structure/views/view/test_exposed_admin_ui');
$page = $this
->getSession()
->getPage();
$page
->clickLink('Content: Authored on (grouped)');
$web_assert
->assertWaitOnAjaxRequest();
$between_from = $page
->findField('options[group_info][group_items][1][value][min]');
$this
->assertNotEmpty($between_from
->isVisible());
$this
->assertEquals('2015-01-01', $between_from
->getValue());
$between_to = $page
->findField('options[group_info][group_items][1][value][max]');
$this
->assertNotEmpty($between_to
->isVisible());
$this
->assertEquals('2016-01-01', $between_to
->getValue());
$weight = $page
->findField('options[group_info][group_items][1][weight]');
$this
->assertNull($weight
->find('named', [
'option',
-4,
]));
foreach (range(-3, 3) as $value) {
$this
->assertNotEmpty($weight
->find('named', [
'option',
$value,
]));
}
$this
->assertEmpty($weight
->find('named', [
'option',
4,
]));
$page
->pressButton("Add another item");
$web_assert
->waitForField('options[group_info][group_items][4][title]');
$this
->assertEmpty($weight
->find('named', [
'option',
-5,
]));
foreach (range(-4, 4) as $value) {
$this
->assertNotEmpty($weight
->find('named', [
'option',
$value,
]));
}
$this
->assertEmpty($weight
->find('named', [
'option',
5,
]));
}
}