function ModuleUninstallFilterTest::testModuleUninstallFilter

Same name and namespace in other branches
  1. 10 core/modules/system/tests/src/FunctionalJavascript/ModuleUninstallFilterTest.php \Drupal\Tests\system\FunctionalJavascript\ModuleUninstallFilterTest::testModuleUninstallFilter()

Tests that correct module count is returned when list filtered.

File

core/modules/system/tests/src/FunctionalJavascript/ModuleUninstallFilterTest.php, line 41

Class

ModuleUninstallFilterTest
Tests the JavaScript functionality of the module uninstall filter.

Namespace

Drupal\Tests\system\FunctionalJavascript

Code

public function testModuleUninstallFilter() : void {
    // Find the module filter field.
    $this->drupalGet('admin/modules/uninstall');
    $assertSession = $this->assertSession();
    $session = $this->getSession();
    $page = $session->getPage();
    $filter = $page->findField('edit-text');
    // Get all module rows, for assertions later.
    $module_rows = $page->findAll('css', '.module-name');
    // Test module filter reduces the number of visible rows.
    $filter->setValue('dynamic');
    $session->wait(1000, 'jQuery("#edit-uninstall-page-cache:visible").length == 0');
    $visible_rows = $this->filterVisibleElements($module_rows);
    $this->assertNotEquals(count($module_rows), count($visible_rows));
    // Test Drupal.announce() message when multiple matches are expected.
    $filter->setValue('cache');
    $session->wait(1000, 'jQuery("#drupal-live-announce").html().indexOf("modules are available") > -1');
    $visible_rows = $this->filterVisibleElements($module_rows);
    $expected_message = count($visible_rows) . ' modules are available in the modified list.';
    $assertSession->elementTextContains('css', '#drupal-live-announce', $expected_message);
    // Test Drupal.announce() message when only one match is expected.
    // Using a very specific module name, we expect only one row.
    $filter->setValue('dynamic page cache');
    $session->wait(1000, 'jQuery("#drupal-live-announce").html().indexOf("module is available") > -1');
    $visible_rows = $this->filterVisibleElements($module_rows);
    $this->assertEquals(1, count($visible_rows));
    $expected_message = '1 module is available in the modified list.';
    $assertSession->elementTextContains('css', '#drupal-live-announce', $expected_message);
    // Test Drupal.announce() message when no matches are expected.
    $filter->setValue('Pan-Galactic Gargle Blaster');
    $session->wait(1000, 'jQuery("#drupal-live-announce").html().indexOf("0 modules are available") > -1');
    $visible_rows = $this->filterVisibleElements($module_rows);
    $this->assertEquals(0, count($visible_rows));
    $expected_message = '0 modules are available in the modified list.';
    $assertSession->elementTextContains('css', '#drupal-live-announce', $expected_message);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.