Commit cb9f66dc authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2859254 by borisson_: Improve rest coverage for rest routes that are on...

Issue #2859254 by borisson_: Improve rest coverage for rest routes that are on the same route as a html view
parent 976126cc
......@@ -320,6 +320,13 @@ display:
type: facets_serializer
row:
type: data_field
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
path: facets-page
label: 'Search API Test Fulltext REST search view'
module: views
id: search_api_rest_test_view
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\facets_rest\Functional;
use Drupal\Tests\facets\Functional\FacetsTestBase;
use Drupal\views\Entity\View;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -241,4 +242,39 @@ class RestIntegrationTest extends FacetsTestBase {
$this->assertSession()->pageTextNotContains('The Facet source is a Rest export. Please select a raw widget.');
}
/**
* Tests urls on the same path.
*/
public function testSamePath() {
$getOptions = ['query' => ['_format' => 'json']];
$this->drupalGet('admin/config/search/facets/add-facet');
$id = 'type';
$this->createFacet('Type', $id . '_rest', 'type', 'rest_export_1', 'views_rest__search_api_rest_test_view', FALSE);
$this->createFacet('Type', $id, 'type', 'page_1', 'views_page__search_api_rest_test_view');
$this->assertSession()->statusCodeEquals(200);
$this->drupalGet('/admin/config/search/facets/type/edit');
$values['widget'] = 'array';
$values['widget_config[show_numbers]'] = TRUE;
$values['facet_settings[url_alias]'] = 'type';
$values['facet_settings[only_visible_when_facet_source_is_visible]'] = TRUE;
$this->drupalPostForm('/admin/config/search/facets/type_rest/edit', ['widget' => 'array'], 'Configure widget');
$this->drupalPostForm(NULL, $values, 'Save');
$this->drupalGet('facets-page');
$this->clickLink('item');
$this->assertSession()->pageTextContains('Displaying 3 search results');
$pageUrl = $this->getSession()->getCurrentUrl();
$restUrl = str_replace('facets-page', 'facets-rest', $pageUrl);
$result = $this->drupalGet($restUrl, $getOptions);
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->responseHeaderEquals('content-type', 'application/json');
$json_decoded = json_decode($result);
$this->assertEquals(3, count($json_decoded->search_results));
}
}
......@@ -29,8 +29,10 @@ trait BlockTestTrait {
* The display id.
* @param string $source
* Facet source.
* @param bool $allowBlockCreation
* Automatically create a block.
*/
protected function createFacet($name, $id, $field = 'type', $display_id = 'page_1', $source = 'views_page__search_api_test_view') {
protected function createFacet($name, $id, $field = 'type', $display_id = 'page_1', $source = 'views_page__search_api_test_view', $allowBlockCreation = TRUE) {
$facet_source = "search_api:{$source}__{$display_id}";
/** @var \Drupal\facets\FacetInterface $facet */
......@@ -52,7 +54,9 @@ trait BlockTestTrait {
$facet->setOnlyVisibleWhenFacetSourceIsVisible(TRUE);
$facet->save();
$this->blocks[$id] = $this->createBlock($id);
if ($allowBlockCreation) {
$this->blocks[$id] = $this->createBlock($id);
}
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment