You are here

public function FacetTest::testResults in Facets 8

Tests results behavior.

@covers ::setResults @covers ::getResults @covers ::isActiveValue @covers ::getActiveItems @covers ::setActiveItems @covers ::setActiveItem @covers ::isActiveValue

File

tests/src/Kernel/Entity/FacetTest.php, line 258

Class

FacetTest
Class FacetTest.

Namespace

Drupal\Tests\facets\Kernel\Entity

Code

public function testResults() {
  $entity = new Facet([], 'facets_facet');

  /** @var \Drupal\facets\Result\ResultInterface[] $results */
  $results = [
    new Result($entity, 'llama', 'llama', 10),
    new Result($entity, 'badger', 'badger', 15),
    new Result($entity, 'owl', 'owl', 5),
  ];
  $this
    ->assertEmpty($entity
    ->getResults());
  $entity
    ->setResults($results);
  $this
    ->assertEquals($results, $entity
    ->getResults());
  $this
    ->assertEmpty($entity
    ->getActiveItems());
  $this
    ->assertFalse($entity
    ->isActiveValue('llama'));
  $entity
    ->setActiveItem('llama');
  $this
    ->assertEquals([
    'llama',
  ], $entity
    ->getActiveItems());
  $this
    ->assertTrue($entity
    ->isActiveValue('llama'));
  $this
    ->assertFalse($entity
    ->isActiveValue('owl'));
  $this
    ->assertFalse($entity
    ->getResults()[0]
    ->isActive());
  $entity
    ->setResults($results);
  $this
    ->assertTrue($entity
    ->getResults()[0]
    ->isActive());
  $this
    ->assertTrue($entity
    ->isActiveValue('llama'));
  $this
    ->assertFalse($entity
    ->isActiveValue('badger'));
  $this
    ->assertFalse($entity
    ->isActiveValue('owl'));
  $entity
    ->setActiveItems([
    'badger',
    'owl',
  ]);
  $this
    ->assertFalse($entity
    ->isActiveValue('llama'));
  $this
    ->assertTrue($entity
    ->isActiveValue('badger'));
  $this
    ->assertTrue($entity
    ->isActiveValue('owl'));
}