diff --git a/src/Tests/UrlIntegrationTest.php b/src/Tests/UrlIntegrationTest.php index 62b3c45..e08008f 100644 --- a/src/Tests/UrlIntegrationTest.php +++ b/src/Tests/UrlIntegrationTest.php @@ -96,4 +96,132 @@ class UrlIntegrationTest extends FacetWebTestBase { $this->assertUrl('search-api-test-fulltext?y[0]=facet||item'); } + /** + * Test colons. + */ + public function testColonKey() { + $id = 'facet'; + $url_alias = 'facet:colon'; + $name = '&^Facet:@#1'; + $facet_add_page = 'admin/config/search/facets/add-facet'; + + // Create the facet. + $this->drupalGet($facet_add_page); + $form_values = [ + 'id' => $id, + 'status' => 1, + 'url_alias' => $url_alias, + 'name' => $name, + 'facet_source_id' => 'search_api_views:search_api_test_views_fulltext:page_1', + 'facet_source_configs[search_api_views:search_api_test_views_fulltext:page_1][field_identifier]' => 'entity:entity_test/type', + ]; + $this->drupalPostForm(NULL, ['facet_source_id' => 'search_api_views:search_api_test_views_fulltext:page_1'], $this->t('Configure facet source')); + $this->drupalPostForm(NULL, $form_values, $this->t('Save')); + + // Create / place block. + $block_values = [ + 'plugin_id' => 'facet_block:' . $id, + 'settings' => [ + 'region' => 'footer', + 'id' => str_replace('_', '-', $id), + ] + ]; + $this->drupalPlaceBlock($block_values['plugin_id'], $block_values['settings']); + + // Create an entity type with a colon in the name. + entity_test_create_bundle('test'); + $entity_test_storage = \Drupal::entityTypeManager()->getStorage('entity_test'); + $entity_test_storage->create([ + 'name' => 'Test:1', + 'body' => 'test test', + 'type' => 'test' + ])->save(); + $this->indexItems($this->indexId); + + // Assert that colons work. + $this->drupalGet('search-api-test-fulltext'); + $this->assertResponse(200); + $this->assertLink('item'); + $this->assertLink('article'); + $this->assertLink('test'); + + $this->clickLink('test'); + $this->assertResponse(200); + + // Assert that filtering really worked. + $this->assertLink('(-) test'); + $this->assertNoLink('article'); + $this->assertNoLink('item'); + $this->assertText('Test:1'); + $this->assertNoText('bar baz'); + $this->assertNoText('foo baz'); + $this->assertNoText('bar'); + $this->assertNoText('foo test'); + $this->assertNoText('foo bar baz'); + } + + /** + * Test colons. + */ + public function testColonValue() { + $id = 'facet'; + $url_alias = 'colon'; + $name = '&^Facet:@#1'; + $facet_add_page = 'admin/config/search/facets/add-facet'; + + // Create the facet. + $this->drupalGet($facet_add_page); + $form_values = [ + 'id' => $id, + 'status' => 1, + 'url_alias' => $url_alias, + 'name' => $name, + 'facet_source_id' => 'search_api_views:search_api_test_views_fulltext:page_1', + 'facet_source_configs[search_api_views:search_api_test_views_fulltext:page_1][field_identifier]' => 'entity:entity_test/type', + ]; + $this->drupalPostForm(NULL, ['facet_source_id' => 'search_api_views:search_api_test_views_fulltext:page_1'], $this->t('Configure facet source')); + $this->drupalPostForm(NULL, $form_values, $this->t('Save')); + + // Create / place block. + $block_values = [ + 'plugin_id' => 'facet_block:' . $id, + 'settings' => [ + 'region' => 'footer', + 'id' => str_replace('_', '-', $id), + ] + ]; + $this->drupalPlaceBlock($block_values['plugin_id'], $block_values['settings']); + + // Create an entity type with a colon in the name. + entity_test_create_bundle('test:colon'); + $entity_test_storage = \Drupal::entityTypeManager()->getStorage('entity_test'); + $entity_test_storage->create([ + 'name' => 'Test:1', + 'body' => 'test test', + 'type' => 'test:colon' + ])->save(); + $this->indexItems($this->indexId); + + // Assert that colons work. + $this->drupalGet('search-api-test-fulltext'); + $this->assertResponse(200); + $this->assertLink('item'); + $this->assertLink('article'); + $this->assertLink('test:colon'); + + $this->clickLink('test:colon'); + $this->assertResponse(200); + + // Assert that filtering really worked. + $this->assertLink('(-) test:colon'); + $this->assertNoLink('article'); + $this->assertNoLink('item'); + $this->assertText('Test:1'); + $this->assertNoText('bar baz'); + $this->assertNoText('foo baz'); + $this->assertNoText('bar'); + $this->assertNoText('foo test'); + $this->assertNoText('foo bar baz'); + } + }