Commit 67112f9e authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2903527 by borisson_: Clean up tests + coding standards

parent 64c56021
......@@ -17,7 +17,6 @@ No other modules required, we're supporting drupal core's search as a source for
creating facets. Though we recommend using Search API, as that integration is
better tested.
INSTALLATION
------------
* Install as you would normally install a contributed drupal module. See:
......
......@@ -22,7 +22,6 @@ function facets_update_8001() {
// This only works for the 3 default plugins that we previously shipped. So
// only views that have a page, block, or rest display. The id will get
// replaced from views_page:foo to search_api:views_page__foo.
$old_ids = ['views_page', 'views_block', 'views_rest'];
/** @var \Drupal\facets\FacetInterface[] $entities */
......@@ -79,9 +78,9 @@ function facets_update_8002() {
}
$database->update('config')
->fields(array(
->fields([
'data' => serialize($data),
))
])
->condition('name', $result->name)
->execute();
}
......
......@@ -68,9 +68,6 @@ function facets_theme($existing, $type, $theme, $path) {
/**
* Implements hook_search_api_query_alter().
*
* @param \Drupal\search_api\Query\QueryInterface $query
* Generates query for facet search.
*/
function facets_search_api_query_alter(QueryInterface &$query) {
if ($query->getIndex()->getServerInstance()->supportsFeature('search_api_facets')) {
......@@ -214,7 +211,7 @@ function facets_entity_predelete(EntityInterface $entity) {
*
* @see https://www.drupal.org/node/1842756
*/
function facets_preprocess_facets_item_list(&$variables) {
function facets_preprocess_facets_item_list(array &$variables) {
template_preprocess_item_list($variables);
}
......@@ -322,7 +319,7 @@ function facets_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInter
// Because we can't get the desired url trough a url processor method
// we iterate each result url and remove the facet params that haven't
// been used on previous crumbs
// been used on previous crumbs.
foreach ($facet_results as $res) {
$facet_url = $res->getUrl();
/** @var \Drupal\Core\Url $facet_url */
......
......@@ -17,9 +17,7 @@ abstract class CoreSearchFacetsTestBase extends BrowserTestBase {
use TestHelperTrait;
/**
* Modules to enable for this test.
*
* @var string[]
* {@inheritdoc}
*/
public static $modules = [
'field',
......
......@@ -51,7 +51,7 @@ class HooksTest extends CoreSearchFacetsTestBase {
// Verify that hook_facets_core_allowed_field_types was triggered.
$facet_add_page = 'admin/config/search/facets/add-facet';
$this->drupalGet($facet_add_page);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
// Select the node_search facet source.
$this->drupalGet($facet_add_page);
......@@ -62,7 +62,7 @@ class HooksTest extends CoreSearchFacetsTestBase {
);
// The field appears as expected.
$this->assertText('Float Field Label');
$this->assertSession()->pageTextContains('Float Field Label');
}
}
......@@ -36,8 +36,10 @@ class SliderProcessor extends ProcessorPluginBase implements PostQueryProcessorI
'count' => (int) $result->getCount(),
];
}
uasort($simple_results, function($a, $b) {
if ($a['value'] === $b['value']) { return 0; }
uasort($simple_results, function ($a, $b) {
if ($a['value'] === $b['value']) {
return 0;
}
return $a['value'] < $b['value'] ? -1 : 1;
});
......
......@@ -48,8 +48,7 @@ class SliderIntegrationTest extends FacetsTestBase {
public function testSliderWidget() {
$this->createIntegerField();
$id = 'owl';
$name = 'Owl widget.';
$this->createFacet($name, $id, 'field_integer');
$this->createFacet('Owl widget.', $id, 'field_integer');
$this->drupalGet('admin/config/search/facets/' . $id . '/edit');
......
......@@ -22,6 +22,8 @@ use Drupal\Tests\UnitTestCase;
class RangeSliderProcessorTest extends UnitTestCase {
/**
* The processor we're testing.
*
* @var \Drupal\facets_range_widget\Plugin\facets\processor\RangeSliderProcessor
*/
protected $processor;
......
......@@ -19,6 +19,8 @@ use Drupal\Tests\UnitTestCase;
class SliderProcessorTest extends UnitTestCase {
/**
* The processor we're testing.
*
* @var \Drupal\facets\Processor\ProcessorInterface
*/
protected $processor;
......@@ -46,7 +48,7 @@ class SliderProcessorTest extends UnitTestCase {
$result_higher = new Result(150, '150', 1);
$facet->setResults([$result_lower, $result_higher]);
// Process the data
// Process the data.
$startTime = microtime();
$this->processor->postQuery($facet);
$new_results = $facet->getResults();
......@@ -81,7 +83,7 @@ class SliderProcessorTest extends UnitTestCase {
$original_results[] = new Result(150000, 'Big', 5);
$facet->setResults($original_results);
// Process the data
// Process the data.
$startTime = microtime();
$this->processor->postQuery($facet);
$new_results = $facet->getResults();
......@@ -110,7 +112,7 @@ class SliderProcessorTest extends UnitTestCase {
}
$facet->setResults($original_results);
// Process the data
// Process the data.
$this->processor->postQuery($facet);
$new_results = $facet->getResults();
......@@ -139,7 +141,7 @@ class SliderProcessorTest extends UnitTestCase {
$result_higher = new Result(150, '150', 1);
$facet->setResults([$result_lower, $result_higher]);
// Process the data
// Process the data.
$this->processor->postQuery($facet);
$new_results = $facet->getResults();
......@@ -161,7 +163,7 @@ class SliderProcessorTest extends UnitTestCase {
$result_higher = new Result(15, '15', 4);
$facet->setResults([$result_lower, $result_higher]);
// Process the data
// Process the data.
$this->processor->postQuery($facet);
$new_results = $facet->getResults();
......@@ -178,7 +180,7 @@ class SliderProcessorTest extends UnitTestCase {
* Configures the container.
*
* @param array $config
* The config for the widget.
* The config for the widget.
*/
protected function configureContainer(array $config = []) {
$widget = $this->prophesize(ArrayWidget::class);
......
......@@ -80,7 +80,7 @@ class SliderWidgetTest extends WidgetTestBase {
$originalResults = [];
foreach (range(3, 20000, 2) as $rv) {
$res = new Result($rv, 'Value: ' . $rv, ceil($rv/2));
$res = new Result($rv, 'Value: ' . $rv, ceil($rv / 2));
$res->setUrl(new Url('test'));
$originalResults[] = $res;
}
......
......@@ -93,6 +93,6 @@ function facets_summary_theme_suggestions_facets_summary_facet_result(array $var
*
* @see https://www.drupal.org/node/1842756
*/
function facets_summary_preprocess_facets_summary_item_list(&$variables) {
function facets_summary_preprocess_facets_summary_item_list(array &$variables) {
template_preprocess_item_list($variables);
}
......@@ -7,12 +7,10 @@ use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\facets\FacetManager\DefaultFacetManager;
use Drupal\Core\Form\FormStateInterface;
use Drupal\facets\FacetSource\FacetSourcePluginInterface;
use Drupal\facets\FacetSource\FacetSourcePluginManager;
use Drupal\facets\FacetSource\SearchApiFacetSourceInterface;
use Drupal\facets_summary\Processor\ProcessorPluginManager;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\facets_summary\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\LanguageInterface;
use Drupal\search_api\Item\Field;
use Drupal\taxonomy\Entity\Term;
......@@ -35,7 +34,7 @@ class HierarchicalFacetIntegrationTest extends FacetsTestBase {
protected $vocabulary;
/**
* The fieldname for the referenced term.
* The field name for the referenced term.
*
* @var string
*/
......@@ -87,8 +86,8 @@ class HierarchicalFacetIntegrationTest extends FacetsTestBase {
$this->setUpExampleStructure();
// Create a taxonomy_term_reference field on the article and item.
$this->fieldName = Unicode::strtolower($this->randomMachineName());
$fieldLabel = $this->randomString();
$this->fieldName = 'hierarchy_field';
$fieldLabel = 'Hierarchy field';
$this->createEntityReferenceField('entity_test_mulrev_changed', 'article', $this->fieldName, $fieldLabel, 'taxonomy_term');
$this->createEntityReferenceField('entity_test_mulrev_changed', 'item', $this->fieldName, $fieldLabel, 'taxonomy_term');
......@@ -123,7 +122,7 @@ class HierarchicalFacetIntegrationTest extends FacetsTestBase {
// Verify that the link to the index processors settings page is available.
$this->drupalGet($this->facetEditPage);
$this->clickLink('Search api index processor configuration');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
// Enable hierarchical facets and translation of entity ids to its names for
// a better readability.
......@@ -154,12 +153,12 @@ class HierarchicalFacetIntegrationTest extends FacetsTestBase {
$this->assertFacetBlocksAppear();
$this->assertFacetLabel('Parent 1');
$this->assertFacetLabel('Parent 2');
$this->assertNoLink('Child 1');
$this->assertNoLink('Child 2');
$this->assertNoLink('Child 3');
$this->assertNoLink('Child 4');
$this->assertSession()->linkNotExists('Child 1');
$this->assertSession()->linkNotExists('Child 2');
$this->assertSession()->linkNotExists('Child 3');
$this->assertSession()->linkNotExists('Child 4');
$this->assertText($block->label());
$this->assertSession()->pageTextContains($block->label());
// Click the first parent and make sure its children are visible.
$this->clickLink('Parent 1');
......@@ -167,10 +166,10 @@ class HierarchicalFacetIntegrationTest extends FacetsTestBase {
$this->checkFacetIsActive('Parent 1');
$this->assertFacetLabel('Child 1');
$this->assertFacetLabel('Child 2');
$this->assertNoLink('Child 3');
$this->assertNoLink('Child 4');
$this->assertSession()->linkNotExists('Child 3');
$this->assertSession()->linkNotExists('Child 4');
$this->assertText($block->label());
$this->assertSession()->pageTextContains($block->label());
}
/**
......@@ -189,7 +188,7 @@ class HierarchicalFacetIntegrationTest extends FacetsTestBase {
}
// Generate 4 child terms.
for ($i = 1; $i <= 4; $i++) {
foreach (range(1, 4) as $i) {
$this->terms[$i] = Term::create([
'name' => sprintf('Child %d', $i),
'description' => '',
......@@ -220,76 +219,63 @@ class HierarchicalFacetIntegrationTest extends FacetsTestBase {
$entity_test_storage = \Drupal::entityTypeManager()
->getStorage('entity_test_mulrev_changed');
$this->entities[1] = $entity_test_storage->create(array(
$this->entities[1] = $entity_test_storage->create([
'name' => 'foo bar baz',
'body' => 'test test',
'type' => 'item',
'keywords' => array('orange'),
'keywords' => ['orange'],
'category' => 'item_category',
$this->fieldName => [$this->parents['Parent 1']->id()],
));
]);
$this->entities[1]->save();
$this->entities[2] = $entity_test_storage->create(array(
$this->entities[2] = $entity_test_storage->create([
'name' => 'foo test',
'body' => 'bar test',
'type' => 'item',
'keywords' => array('orange', 'apple', 'grape'),
'keywords' => ['orange', 'apple', 'grape'],
'category' => 'item_category',
$this->fieldName => [$this->parents['Parent 2']->id()],
));
]);
$this->entities[2]->save();
$this->entities[3] = $entity_test_storage->create(array(
$this->entities[3] = $entity_test_storage->create([
'name' => 'bar',
'body' => 'test foobar',
'type' => 'item',
$this->fieldName => [$this->terms[1]->id()],
));
]);
$this->entities[3]->save();
$this->entities[4] = $entity_test_storage->create(array(
$this->entities[4] = $entity_test_storage->create([
'name' => 'foo baz',
'body' => 'test test test',
'type' => 'article',
'keywords' => array('apple', 'strawberry', 'grape'),
'keywords' => ['apple', 'strawberry', 'grape'],
'category' => 'article_category',
$this->fieldName => [$this->terms[2]->id()],
));
]);
$this->entities[4]->save();
$this->entities[5] = $entity_test_storage->create(array(
$this->entities[5] = $entity_test_storage->create([
'name' => 'bar baz',
'body' => 'foo',
'type' => 'article',
'keywords' => array('orange', 'strawberry', 'grape', 'banana'),
'keywords' => ['orange', 'strawberry', 'grape', 'banana'],
'category' => 'article_category',
$this->fieldName => [$this->terms[3]->id()],
));
]);
$this->entities[5]->save();
$this->entities[6] = $entity_test_storage->create(array(
$this->entities[6] = $entity_test_storage->create([
'name' => 'bar baz',
'body' => 'foo',
'type' => 'article',
'keywords' => array('orange', 'strawberry', 'grape', 'banana'),
'keywords' => ['orange', 'strawberry', 'grape', 'banana'],
'category' => 'article_category',
$this->fieldName => [$this->terms[4]->id()],
));
]);
$this->entities[6]->save();
}
/**
* Convert facet name to machine name.
*
* @param string $facet_name
* The name of the facet.
*
* @return string
* The facet name changed to a machine name.
*/
protected function convertNameToMachineName($facet_name) {
return preg_replace('@[^a-zA-Z0-9_]+@', '_', strtolower($facet_name));
}
}
......@@ -30,7 +30,7 @@ class IntegrationTest extends FacetsTestBase {
$this->setUpExampleStructure();
$this->insertExampleContent();
$this->assertEqual($this->indexItems($this->indexId), 5, '5 items were indexed.');
$this->assertEquals(5, $this->indexItems($this->indexId), '5 items were indexed.');
// Make absolutely sure the ::$blocks variable doesn't pass information
// along between tests.
......@@ -42,7 +42,7 @@ class IntegrationTest extends FacetsTestBase {
*/
public function testFramework() {
$this->drupalGet('admin/config/search/facets');
$this->assertNoText('Facets Summary');
$this->assertSession()->pageTextNotContains('Facets Summary');
$values = [
'name' => 'Owl',
......@@ -53,30 +53,30 @@ class IntegrationTest extends FacetsTestBase {
$this->drupalPostForm(NULL, [], 'Save');
$this->drupalGet('admin/config/search/facets');
$this->assertText('Facets Summary');
$this->assertText('Owl');
$this->assertSession()->pageTextContains('Facets Summary');
$this->assertSession()->pageTextContains('Owl');
$this->drupalGet('admin/config/search/facets/facet-summary/owl/edit');
$this->assertText('No facets found.');
$this->assertSession()->pageTextContains('No facets found.');
$this->createFacet('Llama', 'llama');
$this->drupalGet('admin/config/search/facets');
$this->assertText('Llama');
$this->assertSession()->pageTextContains('Llama');
// Go back to the facet summary and check that the facets are not checked by
// default and that they show up in the list here.
$this->drupalGet('admin/config/search/facets/facet-summary/owl/edit');
$this->assertNoText('No facets found.');
$this->assertText('Llama');
$this->assertNoFieldChecked('edit-facets-llama-checked');
$this->assertSession()->pageTextNotContains('No facets found.');
$this->assertSession()->pageTextContains('Llama');
$this->assertSession()->checkboxNotChecked('edit-facets-llama-checked');
// Post the form and check that no facets are checked after saving the form.
$this->drupalPostForm(NULL, [], 'Save');
$this->assertNoFieldChecked('edit-facets-llama-checked');
$this->assertSession()->checkboxNotChecked('edit-facets-llama-checked');
// Enable a facet and check it's status after saving.
$this->drupalPostForm(NULL, ['facets[llama][checked]' => TRUE], 'Save');
$this->assertFieldChecked('edit-facets-llama-checked');
$this->assertSession()->checkboxChecked('edit-facets-llama-checked');
$this->configureShowCountProcessor();
$this->configureResetFacetsProcessor();
......@@ -119,8 +119,8 @@ class IntegrationTest extends FacetsTestBase {
$block = $this->drupalPlaceBlock('facets_summary_block:owl', $block);
$this->drupalGet('search-api-test-fulltext');
$this->assertText('Displaying 5 search results');
$this->assertText($block->label());
$this->assertSession()->pageTextContains('Displaying 5 search results');
$this->assertSession()->pageTextContains($block->label());
$this->assertFacetBlocksAppear();
$this->clickLink('apple');
......@@ -147,8 +147,8 @@ class IntegrationTest extends FacetsTestBase {
$this->drupalPostForm('admin/config/search/facets/facet-summary/owl/edit', $summaries, 'Save');
$this->drupalGet('search-api-test-fulltext');
$this->assertText('Displaying 5 search results');
$this->assertText($block->label());
$this->assertSession()->pageTextContains('Displaying 5 search results');
$this->assertSession()->pageTextContains($block->label());
$this->assertFacetBlocksAppear();
$this->clickLink('apple');
......@@ -274,6 +274,44 @@ class IntegrationTest extends FacetsTestBase {
$this->assertFacetLabel('apple (2)');
}
/**
* Tests for deleting a block.
*/
public function testBlockDelete() {
$name = 'Owl';
$id = 'owl';
$values = [
'name' => $name,
'id' => $id,
'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1',
];
$this->drupalPostForm('admin/config/search/facets/add-facet-summary', $values, 'Save');
$this->drupalPostForm(NULL, [], 'Save');
$block_settings = [
'region' => 'footer',
'id' => $id,
];
$block = $this->drupalPlaceBlock('facets_summary_block:' . $id, $block_settings);
$this->drupalGet('admin/structure/block');
$this->assertSession()->pageTextContains($block->label());
$this->drupalGet('admin/structure/block/library/classy');
$this->assertSession()->pageTextContains($name);
// Check for the warning message that additional config entities will be
// deleted if the facet summary is removed.
$this->drupalGet('admin/config/search/facets/facet-summary/' . $id . '/delete');
$this->assertSession()->pageTextContains('The listed configuration will be deleted.');
$this->assertSession()->pageTextContains($block->label());
$this->drupalPostForm(NULL, [], 'Delete');
$this->drupalGet('admin/structure/block/library/classy');
$this->assertSession()->pageTextNotContains($name);
}
/**
* Tests configuring show_count processor.
*/
......@@ -401,42 +439,4 @@ class IntegrationTest extends FacetsTestBase {
$this->assertSession()->pageTextNotContains(t('Reset facets'));
}
/**
* Tests for deleting a block.
*/
public function testBlockDelete() {
$name = 'Owl';
$id = 'owl';
$values = [
'name' => $name,
'id' => $id,
'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1',
];
$this->drupalPostForm('admin/config/search/facets/add-facet-summary', $values, 'Save');
$this->drupalPostForm(NULL, [], 'Save');
$block_settings = [
'region' => 'footer',
'id' => $id,
];
$block = $this->drupalPlaceBlock('facets_summary_block:' . $id, $block_settings);
$this->drupalGet('admin/structure/block');
$this->assertSession()->pageTextContains($block->label());
$this->drupalGet('admin/structure/block/library/classy');
$this->assertSession()->pageTextContains($name);
// Check for the warning message that additional config entities will be
// deleted if the facet summary is removed.
$this->drupalGet('admin/config/search/facets/facet-summary/' . $id . '/delete');
$this->assertSession()->pageTextContains('The listed configuration will be deleted.');
$this->assertSession()->pageTextContains($block->label());
$this->drupalPostForm(NULL, [], 'Delete');
$this->drupalGet('admin/structure/block/library/classy');
$this->assertSession()->pageTextNotContains($name);
}
}
......@@ -33,7 +33,7 @@ class RestIntegrationTest extends FacetsTestBase {
$this->drupalLogin($this->adminUser);
$this->setUpExampleStructure();
$this->insertExampleContent();
$this->assertEqual($this->indexItems($this->indexId), 5, '5 items were indexed.');
$this->assertEquals(5, $this->indexItems($this->indexId), '5 items were indexed.');
}
/**
......@@ -70,9 +70,9 @@ class RestIntegrationTest extends FacetsTestBase {
// Use the array widget.
$facet_edit_page = '/admin/config/search/facets/' . $id . '/edit';
$this->drupalGet($facet_edit_page);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->drupalPostForm(NULL, ['widget' => 'array'], $this->t('Configure widget'));
$this->drupalPostForm(NULL, ['widget' => 'array'], 'Configure widget');
$values['widget'] = 'array';
$values['widget_config[show_numbers]'] = TRUE;
$values['facet_sorting[count_widget_order][status]'] = TRUE;
......@@ -82,7 +82,7 @@ class RestIntegrationTest extends FacetsTestBase {
$values['facet_settings[query_operator]'] = 'or';
$values['facet_settings[only_visible_when_facet_source_is_visible]'] = TRUE;
$this->drupalPostForm(NULL, $values, $this->t('Save'));
$this->drupalPostForm(NULL, $values, 'Save');
drupal_flush_all_caches();
......@@ -94,9 +94,9 @@ class RestIntegrationTest extends FacetsTestBase {
// Use the array widget.
$facet_edit_page = '/admin/config/search/facets/' . $id . '/edit';
$this->drupalGet($facet_edit_page);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->drupalPostForm(NULL, ['widget' => 'array'], $this->t('Configure widget'));
$this->drupalPostForm(NULL, ['widget' => 'array'], 'Configure widget');
$values['widget'] = 'array';
$values['widget_config[show_numbers]'] = TRUE;
$values['facet_sorting[count_widget_order][status]'] = TRUE;
......@@ -106,13 +106,13 @@ class RestIntegrationTest extends FacetsTestBase {
$values['facet_settings[query_operator]'] = 'or';
$values['facet_settings[only_visible_when_facet_source_is_visible]'] = TRUE;
$this->drupalPostForm(NULL, $values, $this->t('Save'));
$this->drupalPostForm(NULL, $values, 'Save');
// Get the output from the rest view and decode it into an array.
$json = $this->drupalGet('facets-rest');
$json_decoded = json_decode($json);
$this->assertEqual(count($json_decoded->search_results), 5);
$this->assertEquals(5, count($json_decoded->search_results));
// Verify the facet "Type".
$results = [
......@@ -128,8 +128,8 @@ class RestIntegrationTest extends FacetsTestBase {
foreach ($json_decoded->facets[1][0]->type as $result) {
$value = $result->values->value;
$this->assertEqual($result->url, $results[$value]['url']);
$this->assertEqual($result->values->count, $results[$value]['count']);
$this->assertEquals($result->url, $results[$value]['url']);
$this->assertEquals($result->values->count, $results[$value]['count']);
}
// Verify the facet "Keywords".
......@@ -158,15 +158,15 @@ class RestIntegrationTest extends FacetsTestBase {
foreach ($json_decoded->facets[0][0]->keywords as $result) {
$value = $result->values->value;
$this->assertEqual($result->url, $results[$value]['url']);
$this->assertEqual($result->values->count, $results[$value]['count']);
$this->assertEquals($result->url, $results[$value]['url']);
$this->assertEquals($result->values->count, $results[$value]['count']);
}
// Filter and verify that the results are correct.
$json = $this->drupalGet($base_url . '/facets-rest?f%5B0%5D=type%3Aitem');
$json_decoded = json_decode($json);
$this->assertEqual(count($json_decoded->search_results), 3);
$this->assertEquals(3, count($json_decoded->search_results));
$results = [
'article' => [
......@@ -201,14 +201,14 @@ class RestIntegrationTest extends FacetsTestBase {
foreach ($json_decoded->facets[1][0]->type as $result) {
$value = $result->values->value;
$this->assertEqual($result->url, $results[$value]['url']);
$this->assertEqual($result->values->count, $results[$value]['count']);
$this->assertEquals($result->url, $results[$value]['url']);
$this->assertEquals($result->values->count, $results[$value]['count']);
}
foreach ($json_decoded->facets[0][0]->keywords as $result) {
$value = $result->values->value;
$this->assertEqual($result->url, $results[$value]['url']);
$this->assertEqual($result->values->count, $results[$value]['count']);
$this->assertEquals($result->url, $results[$value]['url']);
$this->assertEquals($result->values->count, $results[$value]['count']);
}
}
......@@ -217,22 +217,21 @@ class RestIntegrationTest extends FacetsTestBase {
* Tests that the system raises an error when selecting the wrong widget.
*/
public function testWidgetSelection() {
$name = 'Type';
$id = 'type';
// Add a new facet to filter by content type.
$this->createFacet($name, $id, 'type', 'rest_export_1', 'views_rest__search_api_rest_test_view');
$this->createFacet('Type', $id, 'type', 'rest_export_1', 'views_rest__search_api_rest_test_view');
// Use the array widget.
$facet_edit_page = '/admin/config/search/facets/' . $id . '/edit';
$this->drupalGet($facet_edit_page);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->drupalPostForm(NULL, ['widget' => 'checkbox'], $this->t('Configure widget'));
$this->assertText('The Facet source is a Rest export. Please select a raw widget.');
$this->drupalPostForm(NULL, ['widget' => 'checkbox'], 'Configure widget');
$this->assertSession()->pageTextContains('The Facet source is a Rest export. Please select a raw widget.');
$this->drupalPostForm(NULL, ['widget' => 'array'], $this->t('Configure widget'));