diff --git a/src/Tests/WidgetIntegrationTest.php b/src/Tests/WidgetIntegrationTest.php index b0a4058..802561a 100644 --- a/src/Tests/WidgetIntegrationTest.php +++ b/src/Tests/WidgetIntegrationTest.php @@ -80,6 +80,71 @@ class WidgetIntegrationTest extends FacetWebTestBase { } /** + * Tests submitting multiple items at the same time.. + */ + public function testMultipleCheckboxItems() { + $id = 'palau'; + $name = 'Palau owl'; + $facet_add_page = 'admin/config/search/facets/add-facet'; + + // Create a new facet. + $this->drupalGet($facet_add_page); + $form_values = [ + 'id' => $id, + 'status' => 1, + 'url_alias' => $id, + 'name' => $name, + 'facet_source_id' => 'search_api_views:search_api_test_view:page_1', + 'facet_source_configs[search_api_views:search_api_test_view:page_1][field_identifier]' => 'keywords', + ]; + $this->drupalPostForm(NULL, ['facet_source_id' => 'search_api_views:search_api_test_view:page_1'], $this->t('Configure facet source')); + $this->drupalPostForm(NULL, $form_values, $this->t('Save')); + $this->drupalPostForm(NULL, ['widget' => 'checkbox'], $this->t('Save')); + + // Place a block. + $block_values = [ + 'plugin_id' => 'facet_block:' . $id, + 'settings' => [ + 'region' => 'footer', + 'id' => str_replace('_', '-', $id), + ], + ]; + $this->drupalPlaceBlock($block_values['plugin_id'], $block_values['settings']); + + // Go to the view, check that all results are displayed. + $this->drupalGet('search-api-test-fulltext'); + $this->assertText('Displaying 5 search results'); + + // Filter by the grape keyword. + $edit = ['keywords[grape]' => 'grape']; + $this->drupalPostForm(NULL, $edit, $this->t('submit')); + $this->assertFieldChecked('edit-keywords-grape'); + $this->assertText('Displaying 3 search results'); + + // Add apple to the filter as well. + $edit = ['keywords[grape]' => 'grape', 'keywords[apple]' => 'apple']; + $this->drupalPostForm(NULL, $edit, $this->t('submit')); + $this->assertText('Displaying 3 search results'); + $this->assertFieldChecked('edit-keywords-apple'); + $this->assertFieldChecked('edit-keywords-grape'); + + // Reset the filters back to default and make sure that the original 5 + // results are displayed again. + $this->drupalPostForm(NULL, [], $this->t('submit')); + $this->assertText('Displaying 5 search results'); + $this->assertNoFieldChecked('edit-keywords-apple'); + $this->assertNoFieldChecked('edit-keywords-grape'); + + // Filter on both grape and apple at once and check that those are now + // checked. + $edit = ['keywords[grape]' => 'grape', 'keywords[apple]' => 'apple']; + $this->drupalPostForm(NULL, $edit, $this->t('submit')); + $this->assertText('Displaying 3 search results'); + $this->assertFieldChecked('edit-keywords-apple'); + $this->assertFieldChecked('edit-keywords-grape'); + } + + /** * Tests multiple checkbox widgets. */ public function testMultipleCheckboxWidget() {