You are here

public function RestIntegrationTest::testHideFacets in Facets 8

Tests hiding of facets from rest views.

File

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

Class

RestIntegrationTest
Tests the integration of REST-views and facets.

Namespace

Drupal\Tests\facets_rest\Functional

Code

public function testHideFacets() {
  $get_options = [
    'query' => [
      '_format' => 'json',
    ],
  ];
  $id = 'type_rest';
  $this
    ->createFacet('Type', $id, 'type', 'rest_export_1', 'views_rest__search_api_rest_test_view', FALSE);
  $facet = Facet::load($id);
  $facet
    ->setWidget('array', [
    'show_numbers' => TRUE,
  ]);
  $facet
    ->save();
  $result = $this
    ->drupalGet('facets-rest', $get_options);
  $this
    ->assertSession()
    ->responseHeaderEquals('content-type', 'application/json');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $json_decoded = json_decode($result, TRUE);
  $this
    ->assertArrayHasKey('facets', $json_decoded);
  $this
    ->assertArrayHasKey('search_results', $json_decoded);
  $this
    ->drupalGet('admin/structure/views/nojs/display/search_api_rest_test_view/rest_export_1/style_options');
  $this
    ->drupalPostForm(NULL, [
    'style_options[show_facets]' => FALSE,
  ], 'Apply');
  $this
    ->drupalPostForm(NULL, [], 'Save');
  $result = $this
    ->drupalGet('facets-rest', $get_options);
  $this
    ->assertSession()
    ->responseHeaderEquals('content-type', 'application/json');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $json_decoded = json_decode($result, TRUE);
  $this
    ->assertArrayNotHasKey('facets', $json_decoded);
  $this
    ->assertArrayNotHasKey('search_results', $json_decoded);
}