View source
<?php
namespace Drupal\Tests\views_ui\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class ViewsListingTest 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',
]);
$this
->drupalLogin($admin_user);
}
public function testFilterViewsListing() {
$enabled_views_count = 6;
$disabled_views_count = 2;
$content_views_count = 3;
$this
->drupalGet('admin/structure/views');
$session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$enabled_rows = $page
->findAll('css', 'tr.views-ui-list-enabled');
$enabled_rows = $this
->filterVisibleElements($enabled_rows);
$disabled_rows = $page
->findAll('css', 'tr.views-ui-list-disabled');
$disabled_rows = $this
->filterVisibleElements($disabled_rows);
$this
->assertCount($enabled_views_count, $enabled_rows);
$this
->assertCount($disabled_views_count, $disabled_rows);
$search_input = $page
->find('css', '.views-filter-text.form-search');
$search_input
->setValue('people');
$enabled_rows = $page
->findAll('css', 'tr.views-ui-list-enabled');
$enabled_rows = $this
->filterVisibleElements($enabled_rows);
$disabled_rows = $page
->findAll('css', 'tr.views-ui-list-disabled');
$disabled_rows = $this
->filterVisibleElements($disabled_rows);
$this
->assertCount(1, $enabled_rows);
$this
->assertCount(0, $disabled_rows);
$search_input
->setValue('content');
$enabled_rows = $page
->findAll('css', 'tr.views-ui-list-enabled');
$enabled_rows = $this
->filterVisibleElements($enabled_rows);
$disabled_rows = $page
->findAll('css', 'tr.views-ui-list-disabled');
$disabled_rows = $this
->filterVisibleElements($disabled_rows);
$this
->assertCount($content_views_count, $enabled_rows);
$this
->assertCount($disabled_views_count, $disabled_rows);
$search_input
->setValue('');
$search_input
->keyUp(8);
$enabled_rows = $page
->findAll('css', 'tr.views-ui-list-enabled');
$enabled_rows = $this
->filterVisibleElements($enabled_rows);
$disabled_rows = $page
->findAll('css', 'tr.views-ui-list-disabled');
$disabled_rows = $this
->filterVisibleElements($disabled_rows);
$this
->assertCount($enabled_views_count, $enabled_rows);
$this
->assertCount($disabled_views_count, $disabled_rows);
$enabled_view = $page
->find('css', 'tr.views-ui-list-enabled');
$view_description = $enabled_view
->find('css', '.views-ui-view-name strong')
->getText();
$enabled_view
->find('css', 'li.dropbutton-toggle button')
->click();
$disable_button = $enabled_view
->findLink('Disable');
$this
->assertTrue($disable_button
->isVisible());
$disable_button
->click();
$session
->assertWaitOnAjaxRequest();
$enabled_rows = $page
->findAll('css', 'tr.views-ui-list-enabled');
$enabled_rows = $this
->filterVisibleElements($enabled_rows);
$disabled_rows = $page
->findAll('css', 'tr.views-ui-list-disabled');
$disabled_rows = $this
->filterVisibleElements($disabled_rows);
$this
->assertCount($enabled_views_count - 1, $enabled_rows);
$this
->assertCount($disabled_views_count + 1, $disabled_rows);
$this
->assertTrue($this
->getSession()
->evaluateScript("jQuery(document.activeElement).text() === 'Enable'"));
$this
->assertEquals($view_description, $this
->getSession()
->evaluateScript("jQuery(document.activeElement).parents('tr').find('.views-ui-view-name strong').text()"));
$this
->getSession()
->evaluateScript('jQuery(document.activeElement).click()');
$session
->assertWaitOnAjaxRequest();
$this
->assertTrue($this
->getSession()
->evaluateScript("jQuery(document.activeElement).text() === 'Edit'"));
$this
->assertEquals($view_description, $this
->getSession()
->evaluateScript("jQuery(document.activeElement).parents('tr').find('.views-ui-view-name strong').text()"));
}
protected function filterVisibleElements($elements) {
$elements = array_filter($elements, function ($element) {
return $element
->isVisible();
});
return $elements;
}
}