diff --git a/core/modules/system/js/system.modules.js b/core/modules/system/js/system.modules.js index d47ca70..8534214 100644 --- a/core/modules/system/js/system.modules.js +++ b/core/modules/system/js/system.modules.js @@ -63,9 +63,10 @@ $details.attr('open', true).each(hidePackageDetails); Drupal.announce( - Drupal.t( - '!modules modules are available in the modified list.', - {'!modules': $rowsAndDetails.find('tbody tr:visible').length} + Drupal.formatPlural( + $rowsAndDetails.find('tbody tr:visible').length, + '1 module is available in the modified list.', + '@count modules are available in the modified list.' ) ); } diff --git a/core/modules/system/tests/src/FunctionalJavascript/ModuleFilterTest.php b/core/modules/system/tests/src/FunctionalJavascript/ModuleFilterTest.php new file mode 100644 index 0000000..c8b8eb4 --- /dev/null +++ b/core/modules/system/tests/src/FunctionalJavascript/ModuleFilterTest.php @@ -0,0 +1,85 @@ +drupalCreateUser([ + 'administer modules', + // @todo Remove after https://www.drupal.org/node/2702969 is fixed. + 'access toolbar', + ]); + $this->drupalLogin($admin_user); + } + + /** + * + */ + public function testModuleFilter() { + + // Find the module filter field. + $this->drupalGet('admin/modules'); + $session = $this->assertSession(); + $session->statusCodeEquals(200); + $page = $this->getSession()->getPage(); + $filter = $page->findField('edit-text'); + + // Get all module rows, for assertions later. + $module_rows = $page->findAll('css', '.package-listing tbody tr td.module'); + + // Test module filter reduces the number of visible rows. + $filter->setValue('test'); + $this->getSession()->wait(1000); + $visible_rows = $this->filterVisibleElements($module_rows); + self::assertNotEquals(count($module_rows), count($visible_rows)); + + // Test Drupal.announce() message when multiple matches are expected. + $expected_message = count($visible_rows) . ' modules are available in the modified list.'; + $this->assertSession()->elementTextContains('css', '#drupal-live-announce', $expected_message); + + // Test Drupal.announce() message only one match is expected. + // Using a very specific module name, we expect only one row. + $filter->setValue('System dependency test'); + $this->getSession()->wait(1000); + $visible_rows = $this->filterVisibleElements($module_rows); + $expected_message = '1 module is available in the modified list.'; + $this->assertSession()->elementTextContains('css', '#drupal-live-announce', $expected_message); + + // Test Drupal.announce() message when no matches are expected. + $filter->setValue('Pan-Galactic Gargle Blaster'); + $this->getSession()->wait(1000); + $visible_rows = $this->filterVisibleElements($module_rows); + $expected_message = '0 modules are available in the modified list.'; + $this->assertSession()->elementTextContains('css', '#drupal-live-announce', $expected_message); + } + + /** + * Removes any non-visible elements from the passed array. + * + * @param array $elements + * @return array + */ + protected function filterVisibleElements($elements) { + $elements = array_filter($elements, function($element) { + return $element->isVisible(); + }); + return $elements; + } + +}