You are here

public function IntegrationTest::testExcludeFacetDate in Facets 8

Tests the facet's exclude functionality for a date field.

File

tests/src/Functional/IntegrationTest.php, line 453

Class

IntegrationTest
Tests the overall functionality of the Facets admin UI.

Namespace

Drupal\Tests\facets\Functional

Code

public function testExcludeFacetDate() {
  $field_name = 'created';
  $entity_test_storage = \Drupal::entityTypeManager()
    ->getStorage('entity_test_mulrev_changed');
  $entity_test_storage
    ->create([
    'name' => 'foo new',
    'body' => 'test test',
    'type' => 'item',
    'keywords' => [
      'orange',
    ],
    'category' => 'item_category',
    $field_name => 1490000000,
  ])
    ->save();
  $entity_test_storage
    ->create([
    'name' => 'foo old',
    'body' => 'test test',
    'type' => 'item',
    'keywords' => [
      'orange',
    ],
    'category' => 'item_category',
    $field_name => 1460000000,
  ])
    ->save();
  $this
    ->indexItems($this->indexId);
  $facet_id = "created";

  // Create facet.
  $facet_edit_page = 'admin/config/search/facets/' . $facet_id . '/edit';
  $this
    ->createFacet("Created", $facet_id, $field_name);
  $form = [
    'widget' => 'links',
    'facet_settings[exclude]' => 0,
    'facet_settings[date_item][status]' => 1,
    'facet_settings[date_item][settings][date_display]' => 'actual_date',
    'facet_settings[date_item][settings][granularity]' => SearchApiDate::FACETAPI_DATE_MONTH,
  ];
  $this
    ->drupalGet($facet_edit_page);
  $this
    ->drupalPostForm(NULL, $form, 'Save');
  $this
    ->drupalGet('search-api-test-fulltext');
  $this
    ->assertSession()
    ->pageTextContains('foo old');
  $this
    ->assertSession()
    ->pageTextContains('foo new');
  $this
    ->clickLink('March 2017');
  $this
    ->checkFacetIsActive('March 2017');
  $this
    ->assertSession()
    ->pageTextContains('foo new');
  $this
    ->assertSession()
    ->pageTextNotContains('foo old');
  $this
    ->drupalGet($facet_edit_page);
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-facet-settings-exclude');
  $this
    ->drupalPostForm(NULL, [
    'facet_settings[exclude]' => 1,
  ], 'Save');
  $this
    ->assertSession()
    ->checkboxChecked('edit-facet-settings-exclude');
  $this
    ->drupalGet('search-api-test-fulltext');
  $this
    ->clickLink('March 2017');
  $this
    ->checkFacetIsActive('March 2017');
  $this
    ->assertSession()
    ->pageTextContains('foo old');
  $this
    ->assertSession()
    ->pageTextNotContains('foo new');
}