View source
<?php
namespace Drupal\Tests\views_exposed_groups\Functional;
class ViewsExposedGroupsUiTest extends ViewsExposedGroupsTestBase {
public function testViewsUi() {
$view_path = $this->defaultView
->getDisplay('page_1')
->getOption('path');
$views_ui_path = '/admin/structure/views/view/' . $this->defaultView
->id();
$this
->drupalLogin($this->privilegedUser);
$this
->drupalGet($view_path);
$fieldset_links = $this
->xpath('//fieldset/legend/span');
$this
->assertEqual(0, count($fieldset_links), 'Found no grouped exposed filters.');
$this
->drupalGet($views_ui_path . '/edit');
$this
->clickLink('Basic');
$this
->drupalPostForm(NULL, [
'exposed_form[type]' => 'views_exposed_groups',
], 'Apply');
$edit_form = [
'exposed_form_options[views_exposed_groups][format_groups]' => 'fieldsets',
'exposed_form_options[views_exposed_groups][groups]' => "First\nSecond",
];
$this
->drupalPostForm(NULL, $edit_form, 'Apply');
$this
->assertLink('Grouped filters');
$edit_form = [
'exposed_form_options[views_exposed_groups][group-nid][group]' => '0',
'exposed_form_options[views_exposed_groups][group-title][group]' => '1',
'exposed_form_options[views_exposed_groups][group-uid][group]' => 'no-group',
];
$exposed_options_path = 'admin/structure/views/nojs/display/' . $this->defaultView->name . '/default/exposed_form_options';
$this
->drupalPostForm($exposed_options_path, $edit_form, 'Apply');
$this
->drupalGet($exposed_options_path);
$rows = $this
->xpath('//table[@id="reorder-group-filters"]/tbody/tr');
$this
->assertEqual(6, count($rows), 'Found six rows in filter group table.');
$this
->assertFieldByName('exposed_form_options[views_exposed_groups][group-nid][group]', '0');
$this
->assertFieldByName('exposed_form_options[views_exposed_groups][group-title][group]', '1');
$this
->assertFieldByName('exposed_form_options[views_exposed_groups][group-uid][group]', 'no-group');
$this
->drupalPostForm($views_ui_path . '/edit', [], 'Save');
$this
->drupalGet($view_path);
$fieldset_links = $this
->xpath('//fieldset/legend/span/text()');
$this
->assertEqual(2, count($fieldset_links), 'Found the two fieldset links for grouped filters.');
$this
->assertEqual('First', (string) $fieldset_links[0]);
$this
->assertEqual('Second', (string) $fieldset_links[1]);
$options = [
'query' => [
'uid' => '',
'nid' => '1',
'title' => '',
],
];
$this
->drupalGet($view_path, $options);
$this
->assertViewsTableResultCount(1);
$options['query']['title'] = substr($this->testNodes[3]->title, 0, 3);
$this
->drupalGet($view_path, $options);
$this
->assertViewsTableResultCount(1);
$this
->assertText('There are no results for your search.');
$options['query']['nid'] = '';
$this
->drupalGet($view_path, $options);
$this
->assertViewsTableResultCount(1);
$edit_form = [
'exposed_form_options[views_exposed_groups][format_groups]' => 'fieldsets',
'exposed_form_options[views_exposed_groups][groups]' => "",
];
$this
->drupalPostForm($exposed_options_path, $edit_form, 'Apply');
$this
->drupalGet($exposed_options_path);
$this
->assertFieldByName('exposed_form_options[views_exposed_groups][group-nid][group]', 'no-group');
$this
->assertFieldByName('exposed_form_options[views_exposed_groups][group-title][group]', 'no-group');
$this
->assertFieldByName('exposed_form_options[views_exposed_groups][group-uid][group]', 'no-group');
}
}