You are here

public function FacetsIntegrationTest::setUp in Search API Pages 8

Overrides FunctionalTestBase::setUp

File

tests/src/Functional/FacetsIntegrationTest.php, line 30

Class

FacetsIntegrationTest
Provides web tests for Search API Pages's integration with facets.

Namespace

Drupal\Tests\search_api_page\Functional

Code

public function setUp() {
  parent::setUp();
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer search_api',
    'administer search_api_page',
    'access administration pages',
    'administer nodes',
    'access content overview',
    'administer content types',
    'administer blocks',
    'view search api pages',
    'administer facets',
  ]);
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->setupSearchApi();
  $this
    ->drupalCreateContentType([
    'type' => 'page',
  ]);
  for ($i = 1; $i < 12; $i++) {
    $this
      ->drupalCreateNode([
      'title' => 'Page number' . $i,
      'type' => 'page',
      'body' => [
        [
          'value' => "Page {$i} body.",
        ],
      ],
    ]);
  }

  // Index the taxonomy and entity reference fields.
  $type_field = new Field($this->index, 'type');
  $type_field
    ->setType('string');
  $type_field
    ->setPropertyPath('type');
  $type_field
    ->setDatasourceId('entity:node');
  $type_field
    ->setLabel('Type');
  $this->index
    ->addField($type_field);
  $this->index
    ->save();
  $this
    ->indexItems($this->index
    ->id());
}