View source
<?php
namespace Drupal\Tests\facets\Functional;
class WidgetIntegrationTest extends FacetsTestBase {
public static $modules = [
'views',
'node',
'search_api',
'facets',
'block',
'facets_search_api_dependency',
'facets_query_processor',
'facets_custom_widget',
];
public function setUp() {
parent::setUp();
$this
->drupalLogin($this->adminUser);
$this
->setUpExampleStructure();
$this
->insertExampleContent();
$this
->assertEquals($this
->indexItems($this->indexId), 5, '5 items were indexed.');
}
public function testCheckboxWidget() {
$id = 't';
$this
->createFacet('Facet & checkbox~', $id);
$this
->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this
->drupalPostForm(NULL, [
'widget' => 'checkbox',
], 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('item');
$this
->assertFacetLabel('article');
}
public function testLinksWidget() {
$id = 'links_widget';
$this
->createFacet('>.Facet &* Links', $id);
$this
->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this
->drupalPostForm(NULL, [
'widget' => 'links',
], 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('item');
$this
->assertFacetLabel('article');
$this
->clickLink('item');
$this
->checkFacetIsActive('item');
}
public function testDropdownWidget() {
$id = 'select_widget';
$this
->createFacet('Select', $id);
$this
->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this
->drupalPostForm(NULL, [
'widget' => 'dropdown',
], 'Configure widget');
$this
->drupalPostForm(NULL, [
'widget' => 'dropdown',
'facet_settings[show_only_one_result]' => TRUE,
], 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 5 search results');
$this
->assertFacetLabel('item');
$this
->assertFacetLabel('article');
}
public function testLinksShowHideCount() {
$id = 'links_widget';
$facet_edit_page = 'admin/config/search/facets/' . $id . '/edit';
$this
->createFacet('>.Facet &* Links', $id);
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('item');
$this
->assertFacetLabel('article');
$this
->drupalGet($facet_edit_page);
$this
->drupalPostForm(NULL, [
'widget' => 'links',
'widget_config[show_numbers]' => TRUE,
], 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('item (3)');
$this
->assertFacetLabel('article (2)');
$edit = [
'widget' => 'links',
'widget_config[show_numbers]' => TRUE,
'facet_settings[query_operator]' => 'or',
];
$this
->drupalPostForm($facet_edit_page, $edit, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('item (3)');
$this
->assertFacetLabel('article (2)');
$this
->clickPartialLink('item');
$this
->assertFacetLabel('item (3)');
$this
->assertFacetLabel('article (2)');
$this
->drupalGet($facet_edit_page);
$this
->drupalPostForm(NULL, [
'widget' => 'links',
'widget_config[show_numbers]' => FALSE,
], 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('item');
$this
->assertFacetLabel('article');
}
public function testCustomWidget() {
$id = 'custom_widget';
$this
->createFacet('Custom widget.', $id);
$this
->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this
->assertSession()
->checkboxNotChecked('edit-facet-settings-hide-non-narrowing-result-processor-status');
$this
->assertSession()
->checkboxNotChecked('edit-facet-settings-show-only-one-result');
$this
->drupalPostForm(NULL, [
'widget' => 'custom_widget',
], 'Configure widget');
$this
->drupalPostForm(NULL, [
'widget' => 'custom_widget',
], 'Save');
$this
->assertSession()
->checkboxChecked('edit-facet-settings-hide-non-narrowing-result-processor-status');
$this
->assertSession()
->checkboxChecked('edit-facet-settings-show-only-one-result');
}
public function testSupportsFacet() {
$id = 'masked_owl';
$this
->createFacet('Australian masked owl', $id);
$this
->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this
->assertSession()
->pageTextContains('Custom widget');
\Drupal::state()
->set('facets_test_supports_facet', FALSE);
$this
->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this
->assertSession()
->pageTextNotContains('Custom widget');
}
public function testAllLink() {
$id = 'kepler_16b';
$this
->createFacet('Kepler 16b', $id);
$editUrl = 'admin/config/search/facets/' . $id . '/edit';
$this
->drupalPostForm($editUrl, [
'widget' => 'links',
], 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('item');
$this
->assertFacetLabel('article');
$this
->clickLink('item');
$this
->checkFacetIsActive('item');
$this
->drupalPostForm($editUrl, [
'widget_config[show_reset_link]' => TRUE,
], 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('item');
$this
->assertFacetLabel('article');
$this
->findFacetLink('Show all');
$edit = [
'widget_config[show_reset_link]' => TRUE,
'widget_config[reset_text]' => 'Planets',
];
$this
->drupalPostForm($editUrl, $edit, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('item');
$this
->assertFacetLabel('article');
$this
->findFacetLink('Planets (5)');
$this
->checkFacetIsNotActive('item');
$this
->checkFacetIsNotActive('article');
$this
->clickLink('item');
$this
->checkFacetIsActive('item');
$this
->clickLink('Planets');
$this
->checkFacetIsNotActive('item');
$this
->checkFacetIsNotActive('article');
}
}