You are here

public function RestIntegrationTest::testSamePath in Facets 8

Tests urls on the same path.

File

modules/facets_rest/tests/src/Functional/RestIntegrationTest.php, line 327

Class

RestIntegrationTest
Tests the integration of REST-views and facets.

Namespace

Drupal\Tests\facets_rest\Functional

Code

public function testSamePath() {
  $get_options = [
    'query' => [
      '_format' => 'json',
    ],
  ];
  $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');
  $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, $get_options);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->responseHeaderEquals('content-type', 'application/json');
  $json_decoded = json_decode($result);
  $this
    ->assertEquals(3, count($json_decoded->search_results));
}