diff --git a/core/modules/views/tests/modules/views_test_exposed_filter/views_test_exposed_filter.info.yml b/core/modules/views/tests/modules/views_test_exposed_filter/views_test_exposed_filter.info.yml new file mode 100644 index 0000000..e0472bc --- /dev/null +++ b/core/modules/views/tests/modules/views_test_exposed_filter/views_test_exposed_filter.info.yml @@ -0,0 +1,8 @@ +name: 'Views Test Exposed Filter' +type: module +description: 'Test module for Views.' +package: Testing +version: VERSION +core: 8.x +dependencies: + - views diff --git a/core/modules/views/tests/modules/views_test_exposed_filter/views_test_exposed_filter.module b/core/modules/views/tests/modules/views_test_exposed_filter/views_test_exposed_filter.module new file mode 100644 index 0000000..35ddfc3 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_exposed_filter/views_test_exposed_filter.module @@ -0,0 +1,20 @@ +Default prefix'; + } +} + +function views_test_exposed_filter_ajax_callback(array &$form, FormStateInterface $form_state) { + return [ + '#markup' => 'Callback called.', + ]; +} \ No newline at end of file diff --git a/core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php b/core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php index 974aa2d..2b386cc 100644 --- a/core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php +++ b/core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php @@ -5,6 +5,7 @@ use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\simpletest\ContentTypeCreationTrait; use Drupal\simpletest\NodeCreationTrait; +use Drupal\views\Tests\ViewTestData; /** * Tests the basic AJAX functionality of Views exposed forms. @@ -19,7 +20,12 @@ class ExposedFilterAJAXTest extends JavascriptTestBase { /** * {@inheritdoc} */ - public static $modules = ['node', 'views']; + public static $modules = ['node', 'views', 'views_test_config']; + + /** + * {@inheritdoc} + */ + public static $testViews = ['test_content_ajax']; /** * Tests if exposed filtering via AJAX works for the "Content" View. @@ -80,4 +86,36 @@ public function testExposedFiltering() { $this->assertFalse($session->getPage()->hasButton('Reset')); } + /** + * Tests if AJAX events can be attached to the exposed filter form. + */ + public function testExposedFilterAjaxCallback() { + + ViewTestData::createTestViews(self::class, ['views_test_config']); + + // Attach an AJAX event to all 'title' fields in the exposed filter form. + \Drupal::service('module_installer')->install(['views_test_exposed_filter']); + $this->resetAll(); + $this->rebuildContainer(); + $this->container->get('module_handler')->reload(); + + // Create a user privileged enough to view content. + $user = $this->drupalCreateUser([ + 'administer site configuration', + 'access content', + 'access content overview', + ]); + $this->drupalLogin($user); + + $this->drupalGet('test-content-ajax'); + + $page = $this->getSession()->getPage(); + $this->assertSession()->pageTextContains('Default prefix'); + + $page->fillField('title', 'value'); + $this->assertSession()->assertWaitOnAjaxRequest(); + + $this->assertSession()->pageTextContains('Callback called.'); + } + }