diff --git a/core_search_facets/src/Tests/HooksTest.php b/core_search_facets/src/Tests/HooksTest.php
index bc9572d..66fa934 100644
--- a/core_search_facets/src/Tests/HooksTest.php
+++ b/core_search_facets/src/Tests/HooksTest.php
@@ -29,23 +29,19 @@ class HooksTest extends WebTestBase {
parent::setUp();
// Create a field of type float.
- FieldStorageConfig::create(
- [
- 'field_name' => 'float',
- 'entity_type' => 'node',
- 'type' => 'float',
- ]
- )->save();
+ FieldStorageConfig::create([
+ 'field_name' => 'float',
+ 'entity_type' => 'node',
+ 'type' => 'float',
+ ])->save();
// Create an instance of the float field on the "page" content type.
- FieldConfig::create(
- [
- 'field_name' => 'float',
- 'entity_type' => 'node',
- 'bundle' => 'page',
- 'label' => 'Float Field Label',
- ]
- )->save();
+ FieldConfig::create([
+ 'field_name' => 'float',
+ 'entity_type' => 'node',
+ 'bundle' => 'page',
+ 'label' => 'Float Field Label',
+ ])->save();
// Log in, so we can test all the things.
$this->drupalLogin($this->adminUser);
diff --git a/core_search_facets/src/Tests/IntegrationTest.php b/core_search_facets/src/Tests/IntegrationTest.php
index 5fa869a..e0499a5 100644
--- a/core_search_facets/src/Tests/IntegrationTest.php
+++ b/core_search_facets/src/Tests/IntegrationTest.php
@@ -2,7 +2,7 @@
namespace Drupal\core_search_facets\Tests;
-use Drupal\facets\Tests\ExampleContentTrait;
+use Drupal\facets\Tests\BlockTestTrait;
use Drupal\node\Entity\Node;
/**
@@ -12,14 +12,7 @@ use Drupal\node\Entity\Node;
*/
class IntegrationTest extends WebTestBase {
- use ExampleContentTrait;
-
- /**
- * The block entities used by this test.
- *
- * @var \Drupal\block\BlockInterface[]
- */
- protected $blocks;
+ use BlockTestTrait;
/**
* {@inheritdoc}
@@ -30,7 +23,9 @@ class IntegrationTest extends WebTestBase {
$this->drupalLogin($this->adminUser);
// Index the content.
- \Drupal::service('plugin.manager.search')->createInstance('node_search')->updateIndex();
+ \Drupal::service('plugin.manager.search')
+ ->createInstance('node_search')
+ ->updateIndex();
search_update_totals();
// Make absolutely sure the ::$blocks variable doesn't pass information
@@ -42,7 +37,6 @@ class IntegrationTest extends WebTestBase {
* Tests various operations via the Facets' admin UI.
*/
public function testFramework() {
-
$facet_id = 'test_facet_name';
$facet_name = 'Test Facet Name';
@@ -50,10 +44,10 @@ class IntegrationTest extends WebTestBase {
$this->checkEmptyOverview();
// Add a new facet and edit it.
- $this->addFacet($facet_id, $facet_name, 'type');
+ $this->addFacet($facet_id, $facet_name);
// Create and place a block for "Test Facet name" facet.
- $this->createFacetBlock($facet_id);
+ $this->blocks[$facet_id] = $this->createBlock($facet_id);
// Verify that the facet results are correct.
$this->drupalGet('search/node', ['query' => ['keys' => 'test']]);
@@ -74,10 +68,10 @@ class IntegrationTest extends WebTestBase {
$this->clickLinkPartialName('page');
$this->assertRaw('(-) page (19)');
- // Do not show the block on empty behaviors.
- // Truncate the search_index table because, for the moment, we don't have
- // the possibility to clear the index from the API.
- // See https://www.drupal.org/node/326062
+ // To make sure we have an empty result, we truncate the search_index table
+ // because, for the moment, we don't have the possibility to clear the index
+ // from the API.
+ // @see https://www.drupal.org/node/326062
\Drupal::database()->truncate('search_index')->execute();
// Verify that no facet blocks appear. Empty behavior "None" is selected by
@@ -97,7 +91,6 @@ class IntegrationTest extends WebTestBase {
// Delete the facet and make sure the overview is empty again.
$this->deleteUnusedFacet($facet_id, $facet_name);
$this->checkEmptyOverview();
-
}
/**
@@ -108,7 +101,7 @@ class IntegrationTest extends WebTestBase {
$facet_id = 'tardigrade';
$this->addFacet($facet_id, $facet_name, 'created');
- $this->createFacetBlock($facet_id);
+ $this->blocks[$facet_id] = $this->createBlock($facet_id);
$this->setShowAmountOfResults($facet_id, TRUE);
// Assert date facets.
@@ -144,7 +137,7 @@ class IntegrationTest extends WebTestBase {
$facet_id = 'tardigrade';
$this->addFacet($facet_id, $facet_name, 'changed');
- $this->createFacetBlock($facet_id);
+ $this->blocks[$facet_id] = $this->createBlock($facet_id);
$this->setShowAmountOfResults($facet_id, TRUE);
// Update the changed date. The nodes were created on February/March 2016
@@ -155,7 +148,9 @@ class IntegrationTest extends WebTestBase {
$node->save();
// Index the content.
- \Drupal::service('plugin.manager.search')->createInstance('node_search')->updateIndex();
+ \Drupal::service('plugin.manager.search')
+ ->createInstance('node_search')
+ ->updateIndex();
search_update_totals();
$this->drupalGet('search/node', ['query' => ['keys' => 'test']]);
@@ -165,30 +160,22 @@ class IntegrationTest extends WebTestBase {
$this->assertRaw('December 3, 2016 (1)');
$this->clickLinkPartialName('December 3, 2016');
$this->assertResponse(200);
-
}
/**
- * Tests for CRUD operations.
+ * Tests for CRUD operations in the admin UI.
*/
public function testCrudFacet() {
$facet_name = "Test Facet name";
$facet_id = 'test_facet_name';
- // Check if the overview is empty.
$this->checkEmptyOverview();
- // Add a new facet and edit it.
$this->addFacetCheck($facet_id, $facet_name, 'type');
$this->editFacetCheck($facet_id, $facet_name);
+ $this->blocks[$facet_id] = $this->createBlock($facet_id);
- // Create and place a block.
- $this->createFacetBlock($facet_id);
-
- // Delete the block.
$this->deleteBlock($facet_id);
-
- // Delete the facet.
$this->deleteUnusedFacet($facet_id, $facet_name);
}
@@ -202,7 +189,7 @@ class IntegrationTest extends WebTestBase {
* @param string $type
* The field type.
*/
- public function addFacet($id, $name, $type) {
+ protected function addFacet($id, $name, $type = 'type') {
$this->drupalGet('admin/config/search/facets/add-facet');
$form_values = [
'id' => $id,
@@ -216,7 +203,7 @@ class IntegrationTest extends WebTestBase {
}
/**
- * Configures the possibility to show the amount of results for facet blocks.
+ * Configures the possibility to show the amount of results for facet items.
*
* @param string $facet_id
* The id of the facet.
@@ -224,14 +211,11 @@ class IntegrationTest extends WebTestBase {
* Boolean to determine if we want to show the amount of results.
*/
protected function setShowAmountOfResults($facet_id, $show = TRUE) {
-
$facet_edit_page = '/admin/config/search/facets/' . $facet_id . '/edit';
- // Go to the facet edit page and make sure "edit facet %facet" is present.
$this->drupalGet($facet_edit_page);
$this->assertResponse(200);
- // Configure the text for empty results behavior.
$edit = [
'widget_configs[show_numbers]' => $show,
];
@@ -239,48 +223,6 @@ class IntegrationTest extends WebTestBase {
}
/**
- * Deletes a facet block by id.
- *
- * @param string $id
- * The id of the block.
- */
- protected function deleteBlock($id) {
- $this->drupalGet('admin/structure/block/manage/' . $this->blocks[$id]->id(), array('query' => array('destination' => 'admin')));
- $this->clickLink(t('Delete'));
- $this->drupalPostForm(NULL, array(), t('Delete'));
- $this->assertRaw(t('The block %name has been deleted.', array('%name' => $this->blocks[$id]->label())));
- }
-
- /**
- * Asserts that a facet block does not appear.
- */
- protected function assertNoFacetBlocksAppear() {
- foreach ($this->blocks as $block) {
- $this->assertNoBlockAppears($block);
- }
- }
-
- /**
- * Asserts that a facet block appears.
- */
- protected function assertFacetBlocksAppear() {
- foreach ($this->blocks as $block) {
- $this->assertBlockAppears($block);
- }
- }
-
- /**
- * Creates a facet block by id.
- *
- * @param string $id
- * The id of the block.
- */
- protected function createFacetBlock($id) {
- $block_values = ['region' => 'footer', 'id' => str_replace('_', '-', $id)];
- $this->blocks[$id] = $this->drupalPlaceBlock('facet_block:' . $id, $block_values);
- }
-
- /**
* Configures empty behavior option to show a text on empty results.
*
* @param string $facet_name
@@ -401,7 +343,7 @@ class IntegrationTest extends WebTestBase {
* @param string $facet_name
* The name of the facet.
*/
- public function editFacetCheck($facet_id, $facet_name) {
+ protected function editFacetCheck($facet_id, $facet_name) {
$facet_edit_page = '/admin/config/search/facets/' . $facet_id . '/settings';
// Go to the facet edit page and make sure "edit facet %facet" is present.
diff --git a/core_search_facets/src/Tests/WebTestBase.php b/core_search_facets/src/Tests/WebTestBase.php
index 5b41816..eca7e03 100644
--- a/core_search_facets/src/Tests/WebTestBase.php
+++ b/core_search_facets/src/Tests/WebTestBase.php
@@ -70,7 +70,7 @@ abstract class WebTestBase extends SimpletestWebTestBase {
$field_storage->setTranslatable(TRUE);
$field_storage->save();
- // Adding 10 pages.
+ // Add 9 nodes of the type page.
for ($i = 1; $i <= 9; $i++) {
// Adding a different created time per language to avoid to have exactly
// the same value per nid and langcode.
@@ -102,7 +102,7 @@ abstract class WebTestBase extends SimpletestWebTestBase {
'langcode' => 'en',
));
- // Adding 10 articles.
+ // Add 10 nodes of the type article.
for ($i = 1; $i <= 10; $i++) {
$created_time = new \DateTime('April ' . $i . ' 2016 ' . str_pad($i, 2, STR_PAD_LEFT, 0) . 'PM');
$this->drupalCreateNode(array(
diff --git a/src/Tests/BlockTestTrait.php b/src/Tests/BlockTestTrait.php
new file mode 100644
index 0000000..0533e41
--- /dev/null
+++ b/src/Tests/BlockTestTrait.php
@@ -0,0 +1,92 @@
+drupalGet($facet_add_page);
+
+ $form_values = [
+ 'id' => $id,
+ 'status' => 1,
+ '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]' => $field,
+ ];
+ $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->blocks[$id] = $this->createBlock($id);
+ }
+
+ /**
+ * Creates a facet block by id.
+ *
+ * @param string $id
+ * The id of the block.
+ * @return \Drupal\block\Entity\Block
+ * The block entity.
+ */
+ protected function createBlock($id) {
+ $block = [
+ 'region' => 'footer',
+ 'id' => str_replace('_', '-', $id),
+ ];
+ return $this->drupalPlaceBlock('facet_block:' . $id, $block);
+ }
+
+ /**
+ * Asserts that a facet block does not appear.
+ */
+ protected function assertNoFacetBlocksAppear() {
+ foreach ($this->blocks as $block) {
+ $this->assertNoBlockAppears($block);
+ }
+ }
+
+ /**
+ * Asserts that a facet block appears.
+ */
+ protected function assertFacetBlocksAppear() {
+ foreach ($this->blocks as $block) {
+ $this->assertBlockAppears($block);
+ }
+ }
+
+ /**
+ * Deletes a facet block by id.
+ *
+ * @param string $id
+ * The id of the block.
+ */
+ protected function deleteBlock($id) {
+ $this->drupalGet('admin/structure/block/manage/' . $this->blocks[$id]->id(), array('query' => array('destination' => 'admin')));
+ $this->clickLink(t('Delete'));
+ $this->drupalPostForm(NULL, array(), t('Delete'));
+ $this->assertRaw(t('The block %name has been deleted.', array('%name' => $this->blocks[$id]->label())));
+ }
+
+}
diff --git a/src/Tests/ExampleContentTrait.php b/src/Tests/ExampleContentTrait.php
index 140ce1a..1cfd0ea 100644
--- a/src/Tests/ExampleContentTrait.php
+++ b/src/Tests/ExampleContentTrait.php
@@ -15,7 +15,7 @@ trait ExampleContentTrait {
*
* @var \Drupal\entity_test\Entity\EntityTest[]
*/
- protected $entities = array();
+ protected $entities = [];
/**
* Sets up the necessary bundles on the test entity type.
@@ -91,32 +91,6 @@ trait ExampleContentTrait {
}
/**
- * Add a facet trough the UI.
- *
- * @param string $name
- * The facet name.
- * @param string $id
- * The facet id.
- * @param string $field
- * The facet field.
- */
- protected function createFacet($name, $id, $field = 'type') {
- $facet_add_page = 'admin/config/search/facets/add-facet';
-
- $this->drupalGet($facet_add_page);
-
- $form_values = [
- 'id' => $id,
- 'status' => 1,
- '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]' => $field,
- ];
- $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'));
- }
-
- /**
* Asserts that a string is found before another string in the source.
*
* This uses the simpletest's getRawContent method to search in the source of
diff --git a/src/Tests/FacetSourceTest.php b/src/Tests/FacetSourceTest.php
index 2fd2335..51fcfc6 100644
--- a/src/Tests/FacetSourceTest.php
+++ b/src/Tests/FacetSourceTest.php
@@ -22,18 +22,25 @@ class FacetSourceTest extends WebTestBase {
];
/**
- * Tests the facet source editing.
+ * {@inheritdoc}
*/
- public function testEditFilterKey() {
+ public function setUp() {
+ parent::setUp();
+
// Make sure we're logged in with a user that has sufficient permissions.
$this->drupalLogin($this->adminUser);
- // Test the overview.
+ // Go to the overview and click the first configure link.
$this->drupalGet('admin/config/search/facets');
$this->assertLink($this->t('Configure'));
$this->clickLink($this->t('Configure'));
+ }
- // Test the edit page.
+ /**
+ * Tests the facet source editing.
+ */
+ public function testEditFilterKey() {
+ // Change the filter key.
$edit = array(
'filter_key' => 'fq',
);
@@ -52,15 +59,7 @@ class FacetSourceTest extends WebTestBase {
* Tests editing the url processor.
*/
public function testEditUrlProcessor() {
- // Make sure we're logged in with a user that has sufficient permissions.
- $this->drupalLogin($this->adminUser);
-
- // Test the overview.
- $this->drupalGet('admin/config/search/facets');
- $this->assertLink($this->t('Configure'));
- $this->clickLink($this->t('Configure'));
-
- // Test the edit page.
+ // Change the url processor.
$edit = array(
'url_processor' => 'dummy_query',
);
diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php
index 5bb0bd5..bc71790 100644
--- a/src/Tests/IntegrationTest.php
+++ b/src/Tests/IntegrationTest.php
@@ -13,13 +13,6 @@ use Drupal\facets\Entity\Facet;
class IntegrationTest extends WebTestBase {
/**
- * The block entities used by this test.
- *
- * @var \Drupal\block\BlockInterface[]
- */
- protected $blocks;
-
- /**
* {@inheritdoc}
*/
public function setUp() {
@@ -37,7 +30,7 @@ class IntegrationTest extends WebTestBase {
}
/**
- * Tests Facets' permissions.
+ * Tests permissions.
*/
public function testOverviewPermissions() {
$facet_overview = '/admin/config/search/facets';
@@ -76,7 +69,7 @@ class IntegrationTest extends WebTestBase {
$this->assertText('Displaying 5 search results', 'The search view displays the correct number of results.');
// Create and place a block for "Test Facet name" facet.
- $this->createFacetBlock($facet_id);
+ $this->blocks[$facet_id] = $this->createBlock($facet_id);
// Verify that the facet results are correct.
$this->drupalGet('search-api-test-fulltext');
@@ -152,7 +145,7 @@ class IntegrationTest extends WebTestBase {
$this->assertText('Fulltext test index', 'The search view displays the correct number of results.');
// Create and place a block for the test facet.
- $this->createFacetBlock($facet_id);
+ $this->blocks[$facet_id] = $this->createBlock($facet_id);
// Verify that the facet results are correct displayed.
$this->drupalGet('');
@@ -170,15 +163,10 @@ class IntegrationTest extends WebTestBase {
* @see https://www.drupal.org/node/2629504
*/
public function testRenameFacet() {
-
- // Set names.
$facet_id = 'ab_facet';
$new_facet_id = 'facet__ab';
$facet_name = 'ab>Facet';
- // Make sure we're logged in with a user that has sufficient permissions.
- $this->drupalLogin($this->adminUser);
-
// Add a new facet.
$this->addFacet($facet_name);
@@ -201,28 +189,8 @@ class IntegrationTest extends WebTestBase {
public function testUrlAlias() {
$facet_id = 'ab_facet';
$facet_name = 'ab>Facet';
-
- // Make sure we're logged in with a user that has sufficient permissions.
- $this->drupalLogin($this->adminUser);
-
- $facet_add_page = '/admin/config/search/facets/add-facet';
$facet_edit_page = '/admin/config/search/facets/' . $facet_id . '/edit';
-
- $this->drupalGet($facet_add_page);
- $this->assertResponse(200);
-
- $form_values = [
- 'name' => $facet_name,
- 'id' => $facet_id,
- 'status' => 1,
- '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]' => 'type',
- ];
- $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->assertRaw(t('Facet %name has been created.', ['%name' => $facet_name]));
-
- $this->createFacetBlock($facet_id);
+ $this->createFacet($facet_name, $facet_id);
$this->drupalGet('search-api-test-fulltext');
$this->assertLink('item');
@@ -250,15 +218,16 @@ class IntegrationTest extends WebTestBase {
public function testFacetDependencies() {
$facet_name = "DependableFacet";
$facet_id = 'dependablefacet';
- $this->addFacet($facet_name);
$depending_facet_name = "DependingFacet";
$depending_facet_id = "dependingfacet";
+
+ $this->addFacet($facet_name);
$this->addFacet($depending_facet_name, 'keywords');
// Create both facets as blocks and add them on the page.
- $this->createFacetBlock($facet_id);
- $this->createFacetBlock($depending_facet_id);
+ $this->blocks[$facet_id] = $this->createBlock($facet_id);
+ $this->blocks[$depending_facet_id] = $this->createBlock($depending_facet_id);
// Go the the view and test that both facets are shown. Item and article
// come from the DependableFacet, orange and grape come from DependingFacet.
@@ -334,16 +303,11 @@ class IntegrationTest extends WebTestBase {
$facet_id = 'test_facet';
$facet_edit_page = 'admin/config/search/facets/' . $facet_id . '/edit';
- $this->drupalLogin($this->adminUser);
- $this->addFacet($facet_name);
- $this->createFacetBlock('test_facet');
+ $this->createFacet($facet_name, $facet_id);
$this->drupalGet($facet_edit_page);
$this->drupalPostForm(NULL, ['facet_settings[query_operator]' => 'AND'], $this->t('Save'));
- $this->insertExampleContent();
- $this->assertEqual($this->indexItems($this->indexId), 5, '5 items were indexed.');
-
$this->drupalGet('search-api-test-fulltext');
$this->assertLink('item');
$this->assertLink('article');
@@ -364,7 +328,7 @@ class IntegrationTest extends WebTestBase {
}
/**
- * Tests that we disallow unwanted values.
+ * Tests that we disallow unwanted values when creating a facet trough the UI.
*/
public function testUnwantedValues() {
// Go to the Add facet page and make sure that returns a 200.
@@ -409,9 +373,7 @@ class IntegrationTest extends WebTestBase {
$facet_name = 'test & facet';
$facet_id = 'test_facet';
$facet_edit_page = 'admin/config/search/facets/' . $facet_id . '/edit';
-
- $this->addFacet($facet_name);
- $this->createFacetBlock($facet_id);
+ $this->createFacet($facet_name, $facet_id);
$this->drupalGet($facet_edit_page);
$this->assertNoFieldChecked('edit-facet-settings-exclude');
@@ -456,8 +418,7 @@ class IntegrationTest extends WebTestBase {
$facet_id = 'spotted_wood_owl';
$facet_edit_page = 'admin/config/search/facets/' . $facet_id;
- $this->addFacet($facet_name, 'keywords');
- $this->createFacetBlock($facet_id);
+ $this->createFacet($facet_name, $facet_id, 'keywords');
$this->drupalGet($facet_edit_page . '/edit');
$edit = ['facet_settings[show_only_one_result]' => TRUE];
@@ -485,7 +446,7 @@ class IntegrationTest extends WebTestBase {
public function testWeight() {
$facet_name = "Forest owlet";
$id = "forest_owlet";
- $this->addFacet($facet_name);
+ $this->createFacet($facet_name, $id);
/** @var \Drupal\facets\FacetInterface $facet */
$facet = Facet::load($id);
@@ -494,54 +455,6 @@ class IntegrationTest extends WebTestBase {
}
/**
- * Deletes a facet block by id.
- *
- * @param string $id
- * The id of the block.
- */
- protected function deleteBlock($id) {
- $this->drupalGet('admin/structure/block/manage/' . $this->blocks[$id]->id(), array('query' => array('destination' => 'admin')));
- $this->clickLink(t('Delete'));
- $this->drupalPostForm(NULL, array(), t('Delete'));
- $this->assertRaw(t('The block %name has been deleted.', array('%name' => $this->blocks[$id]->label())));
- }
-
- /**
- * Asserts that a facet block does not appear.
- */
- protected function assertNoFacetBlocksAppear() {
- foreach ($this->blocks as $block) {
- $this->assertNoBlockAppears($block);
- }
- }
-
- /**
- * Asserts that a facet block appears.
- */
- protected function assertFacetBlocksAppear() {
- foreach ($this->blocks as $block) {
- $this->assertBlockAppears($block);
- }
- }
-
- /**
- * Creates a facet block by id.
- *
- * @param string $id
- * The id of the block.
- */
- protected function createFacetBlock($id) {
- $block = [
- 'plugin_id' => 'facet_block:' . $id,
- 'settings' => [
- 'region' => 'footer',
- 'id' => str_replace('_', '-', $id),
- ],
- ];
- $this->blocks[$id] = $this->drupalPlaceBlock($block['plugin_id'], $block['settings']);
- }
-
- /**
* Configures empty behavior option to show a text on empty results.
*
* @param string $facet_name
diff --git a/src/Tests/ProcessorIntegrationTest.php b/src/Tests/ProcessorIntegrationTest.php
index a8ba341..02f0815 100644
--- a/src/Tests/ProcessorIntegrationTest.php
+++ b/src/Tests/ProcessorIntegrationTest.php
@@ -97,7 +97,6 @@ class ProcessorIntegrationTest extends WebTestBase {
$this->editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this->createFacet($facet_name, $facet_id, 'keywords');
- $this->createFacetBlock($facet_id);
$this->drupalGet('search-api-test-fulltext');
$this->assertText('Displaying 10 search results');
@@ -122,7 +121,6 @@ class ProcessorIntegrationTest extends WebTestBase {
$this->editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this->createFacet($facet_name, $facet_id, 'keywords');
- $this->createFacetBlock($facet_id);
$this->checkSortByActive();
$this->checkSortByCount();
@@ -133,7 +131,7 @@ class ProcessorIntegrationTest extends WebTestBase {
/**
* Tests the count limit processor.
*/
- private function checkCountLimitProcessor() {
+ protected function checkCountLimitProcessor() {
$this->drupalGet($this->editForm);
$form = [
@@ -185,7 +183,7 @@ class ProcessorIntegrationTest extends WebTestBase {
/**
* Tests the exclude items.
*/
- private function checkExcludeItems() {
+ protected function checkExcludeItems() {
$form = [
'facet_settings[exclude_specified_items][status]' => TRUE,
];
@@ -223,7 +221,7 @@ class ProcessorIntegrationTest extends WebTestBase {
/**
* Tests hiding non-narrowing results.
*/
- private function checkHideNonNarrowingProcessor() {
+ protected function checkHideNonNarrowingProcessor() {
$this->drupalGet('search-api-test-fulltext');
$this->assertText('Displaying 10 search results');
$this->assertLink('grape');
@@ -254,7 +252,7 @@ class ProcessorIntegrationTest extends WebTestBase {
/**
* Tests hiding active results.
*/
- private function checkHideActiveItems() {
+ protected function checkHideActiveItems() {
$form = [
'facet_settings[hide_active_items_processor][status]' => TRUE,
];
@@ -341,10 +339,8 @@ class ProcessorIntegrationTest extends WebTestBase {
/**
* Tests the display order.
*/
- public function checkSortByDisplay() {
- $form = [
- 'facet_sorting[display_value_widget_order][status]' => TRUE,
- ];
+ protected function checkSortByDisplay() {
+ $form = ['facet_sorting[display_value_widget_order][status]' => TRUE];
$this->drupalPostForm($this->editForm, $form, $this->t('Save'));
$this->drupalGet('search-api-test-fulltext');
@@ -361,16 +357,14 @@ class ProcessorIntegrationTest extends WebTestBase {
$this->assertStringPosition('strawberry', 'grape');
$this->assertStringPosition('banana', 'apple');
- $form = [
- 'facet_sorting[display_value_widget_order][status]' => FALSE,
- ];
+ $form = ['facet_sorting[display_value_widget_order][status]' => FALSE];
$this->drupalPostForm($this->editForm, $form, $this->t('Save'));
}
/**
* Tests the display order.
*/
- public function checkSortByRaw() {
+ protected function checkSortByRaw() {
$form = [
'facet_sorting[raw_value_widget_order][status]' => TRUE,
];
diff --git a/src/Tests/UrlIntegrationTest.php b/src/Tests/UrlIntegrationTest.php
index 4d3107f..4c73226 100644
--- a/src/Tests/UrlIntegrationTest.php
+++ b/src/Tests/UrlIntegrationTest.php
@@ -47,28 +47,7 @@ class UrlIntegrationTest extends WebTestBase {
public function testUrlIntegration() {
$id = 'facet';
$name = '&^Facet@#1';
- $facet_add_page = 'admin/config/search/facets/add-facet';
-
- $this->drupalGet($facet_add_page);
-
- $form_values = [
- 'id' => $id,
- 'status' => 1,
- '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]' => 'type',
- ];
- $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'));
-
- $block_values = [
- 'plugin_id' => 'facet_block:' . $id,
- 'settings' => [
- 'region' => 'footer',
- 'id' => str_replace('_', '-', $id),
- ],
- ];
- $this->drupalPlaceBlock($block_values['plugin_id'], $block_values['settings']);
+ $this->createFacet($name, $id);
$url = Url::fromUserInput('/search-api-test-fulltext', ['query' => ['f[0]' => 'facet:item']]);
$this->checkClickedFacetUrl($url);
@@ -135,28 +114,7 @@ class UrlIntegrationTest extends WebTestBase {
public function testColonValue() {
$id = 'water_bear';
$name = 'Water bear';
-
- $facet_add_page = 'admin/config/search/facets/add-facet';
-
- // Create the facet.
- $this->drupalGet($facet_add_page);
-
- $form_values = [
- 'id' => $id,
- 'status' => 1,
- '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'));
-
- // Create / place the block.
- $block_settings = [
- 'region' => 'footer',
- 'id' => str_replace('_', '-', $id),
- ];
- $this->drupalPlaceBlock('facet_block:' . $id, $block_settings);
+ $this->createFacet($name, $id, 'keywords');
// Add a new entity that has a colon in one of it's keywords.
$entity_test_storage = \Drupal::entityTypeManager()
diff --git a/src/Tests/WebTestBase.php b/src/Tests/WebTestBase.php
index 3ce4bfd..ed4b42f 100644
--- a/src/Tests/WebTestBase.php
+++ b/src/Tests/WebTestBase.php
@@ -14,6 +14,7 @@ abstract class WebTestBase extends SimpletestWebTestBase {
use StringTranslationTrait;
use ExampleContentTrait;
+ use BlockTestTrait;
/**
* Modules to enable for this test.
diff --git a/src/Tests/WidgetIntegrationTest.php b/src/Tests/WidgetIntegrationTest.php
index 960a66a..5a49f1a 100644
--- a/src/Tests/WidgetIntegrationTest.php
+++ b/src/Tests/WidgetIntegrationTest.php
@@ -39,35 +39,15 @@ class WidgetIntegrationTest extends WebTestBase {
}
/**
- * Tests various url integration things.
+ * Tests checkbox widget.
*/
public function testCheckboxWidget() {
$id = 't';
$name = 'Facet & checkbox~';
- $facet_add_page = 'admin/config/search/facets/add-facet';
-
- $this->drupalGet($facet_add_page);
-
- $form_values = [
- 'id' => $id,
- 'status' => 1,
- '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]' => 'type',
- ];
- $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->createFacet($name, $id);
+ $this->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this->drupalPostForm(NULL, ['widget' => 'checkbox'], $this->t('Save'));
- $block_values = [
- 'plugin_id' => 'facet_block:' . $id,
- 'settings' => [
- 'region' => 'footer',
- 'id' => str_replace('_', '-', $id),
- ],
- ];
- $this->drupalPlaceBlock($block_values['plugin_id'], $block_values['settings']);
-
$this->drupalGet('search-api-test-fulltext');
$this->assertLink('item');
$this->assertLink('article');
@@ -79,30 +59,10 @@ class WidgetIntegrationTest extends WebTestBase {
public function testLinksWidget() {
$id = 'links_widget';
$name = '>.Facet &* Links';
- $facet_add_page = 'admin/config/search/facets/add-facet';
-
- $this->drupalGet($facet_add_page);
-
- $form_values = [
- 'id' => $id,
- 'status' => 1,
- '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]' => 'type',
- ];
- $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->createFacet($name, $id);
+ $this->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this->drupalPostForm(NULL, ['widget' => 'links'], $this->t('Save'));
- $block_values = [
- 'plugin_id' => 'facet_block:' . $id,
- 'settings' => [
- 'region' => 'footer',
- 'id' => str_replace('_', '-', $id),
- ],
- ];
- $this->drupalPlaceBlock($block_values['plugin_id'], $block_values['settings']);
-
$this->drupalGet('search-api-test-fulltext');
$this->assertLink('item');
$this->assertLink('article');
@@ -117,30 +77,10 @@ class WidgetIntegrationTest extends WebTestBase {
public function testSelectWidget() {
$id = 'select_widget';
$name = 'Select';
- $facet_add_page = 'admin/config/search/facets/add-facet';
-
- $this->drupalGet($facet_add_page);
-
- $form_values = [
- 'id' => $id,
- 'status' => 1,
- '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]' => 'type',
- ];
- $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->createFacet($name, $id);
+ $this->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this->drupalPostForm(NULL, ['widget' => 'select'], $this->t('Save'));
- $block_values = [
- 'plugin_id' => 'facet_block:' . $id,
- 'settings' => [
- 'region' => 'footer',
- 'id' => str_replace('_', '-', $id),
- ],
- ];
- $this->drupalPlaceBlock($block_values['plugin_id'], $block_values['settings']);
-
$this->drupalGet('search-api-test-fulltext');
$this->assertField('edit-type', 'Dropdown is visible.');
$this->assertText('Displaying 5 search results');
@@ -159,30 +99,9 @@ class WidgetIntegrationTest extends WebTestBase {
public function testLinksShowHideCount() {
$id = 'links_widget';
$name = '>.Facet &* Links';
- $facet_add_page = 'admin/config/search/facets/add-facet';
$facet_edit_page = 'admin/config/search/facets/' . $id . '/edit';
- $this->drupalGet($facet_add_page);
-
- $form_values = [
- 'id' => $id,
- 'status' => 1,
- '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]' => 'type',
- ];
- $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' => 'links'], $this->t('Save'));
-
- $block_values = [
- 'plugin_id' => 'facet_block:' . $id,
- 'settings' => [
- 'region' => 'footer',
- 'id' => str_replace('_', '-', $id),
- ],
- ];
- $this->drupalPlaceBlock($block_values['plugin_id'], $block_values['settings']);
+ $this->createFacet($name, $id);
// Go to the view and check that the facet links are shown with their
// default settings.