View source
<?php
namespace Drupal\Tests\views_ui\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class FilterCriteriaTest extends WebDriverTestBase {
protected static $modules = [
'node',
'views',
'views_ui',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
'administer views',
'administer nodes',
'access content overview',
]);
\Drupal::configFactory()
->getEditable('views.settings')
->set('ui.always_live_preview', FALSE)
->save();
$this
->drupalLogin($admin_user);
}
public function testFilterCriteriaDialog() {
$this
->drupalGet('admin/structure/views/view/who_s_online');
$page = $this
->getSession()
->getPage();
$this
->assertNotNull($page
->findLink('User: Last access (>= -15 minutes)'));
$this
->drupalGet('admin/structure/views/view/content_recent');
$assert_session = $this
->assertSession();
$session = $this
->getSession();
$page = $session
->getPage();
$this
->openFilterDialog();
$create_new_filter_group = $page
->findById('views-add-group-link');
$this
->assertTrue($create_new_filter_group
->isVisible(), 'Add group link found.');
$create_new_filter_group
->click();
$assert_session
->assertWaitOnAjaxRequest();
$remove_link = $page
->findLink('Remove group');
$this
->assertTrue($remove_link
->isVisible(), 'New group found.');
$remove_link
->click();
$assert_session
->assertWaitOnAjaxRequest();
$remove_link = $page
->findLink('Remove group');
$this
->assertEmpty($remove_link, 'Remove button not available');
$create_new_filter_group = $page
->findById('views-add-group-link');
$this
->assertTrue($create_new_filter_group
->isVisible(), 'Add group link found.');
$create_new_filter_group
->click();
$assert_session
->assertWaitOnAjaxRequest();
$status_extra_row = $page
->findById("views-row-status_extra");
$langcode_row = $page
->findById("views-row-langcode");
$status_extra_group_field = $status_extra_row
->findField('filters[status_extra][group]');
$langcode_group_field = $langcode_row
->findField('filters[langcode][group]');
$status_extra_original_value = $status_extra_group_field
->getValue();
$langcode_original_value = $langcode_group_field
->getValue();
$drag_handle = $status_extra_row
->find('css', '.tabledrag-handle');
$target = $page
->find('css', '.filter-group-operator-row');
$drag_handle
->dragTo($target);
$remove_link = $page
->findLink('Remove group');
$this
->assertFalse($remove_link
->isVisible(), 'Remove group should be invisible after drag.');
$drag_handle = $langcode_row
->find('css', '.tabledrag-handle');
$drag_handle
->dragTo($status_extra_row);
$this
->assertNotEquals($status_extra_original_value, $status_extra_group_field
->getValue(), 'Status extra group should be changed');
$this
->assertNotEquals($langcode_original_value, $langcode_group_field
->getValue(), 'Langcode group should be changed');
$this
->assertSession()
->waitForLink('Create new filter group', 20000);
$create_new_filter_group = $page
->findLink('Create new filter group');
$this
->assertTrue($create_new_filter_group
->isVisible(), 'Add group link found.');
$create_new_filter_group
->click();
$assert_session
->assertWaitOnAjaxRequest();
$dragged = $page
->find('css', ".tabledrag-handle");
$target = $page
->find('css', '.filter-group-operator-row');
$dragged
->dragTo($target);
$remove_link = $page
->findLink('Remove group');
$this
->assertFalse($remove_link
->isVisible(), 'Remove group should be invisible after drag.');
}
public function testOperatorLabels() {
$this
->drupalGet('admin/structure/views/view/frontpage');
$session = $this
->getSession();
$page = $session
->getPage();
$this
->openFilterDialog();
$row = $page
->findAll('css', '.draggable');
$row_count = count($row);
$last_row = array_pop($row);
$penultimate_row = array_pop($row);
$drag_handle = $last_row
->find('css', '.tabledrag-handle');
$drag_handle
->dragTo($penultimate_row);
$operator_label = $page
->findAll('css', '.views-operator-label');
$this
->assertEquals($row_count - 1, count($operator_label), 'There are valid number of operator labels after drag.');
$row = $page
->findAll('css', '.draggable');
$last_row = array_pop($row);
$penultimate_row = array_pop($row);
$operator_label = $penultimate_row
->find('css', '.views-operator-label');
$this
->assertTrue($operator_label
->isVisible(), 'Operator label in the penultimate row is not visible after drag.');
$operator_label = $last_row
->find('css', '.views-operator-label');
$this
->assertNull($operator_label, 'Operator label in the last row is not visible after drag.');
$remove_link = $last_row
->find('css', '.views-remove-link');
$remove_link
->click();
$operator_label = $penultimate_row
->find('css', '.views-operator-label');
$this
->assertNull($operator_label, 'The penultimate filter has no operator label after the last filter is removed.');
}
protected function openFilterDialog() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$dropbutton = $page
->find('css', '.views-ui-display-tab-bucket.filter .dropbutton-toggle button');
$dropbutton
->click();
$add_link = $page
->findById('views-rearrange-filter');
$this
->assertTrue($add_link
->isVisible(), 'And/Or Rearrange button found.');
$add_link
->click();
$assert_session
->assertWaitOnAjaxRequest();
}
}