You are here

class HideActiveItemsProcessorTest in Facets 8

Unit test for processor.

@group facets

Hierarchy

Expanded class hierarchy of HideActiveItemsProcessorTest

File

tests/src/Unit/Plugin/processor/HideActiveItemsProcessorTest.php, line 15

Namespace

Drupal\Tests\facets\Unit\Plugin\processor
View source
class HideActiveItemsProcessorTest extends UnitTestCase {

  /**
   * The processor to be tested.
   *
   * @var \Drupal\facets\processor\BuildProcessorInterface
   */
  protected $processor;

  /**
   * An array containing the results before the processor has ran.
   *
   * @var \Drupal\facets\Result\Result[]
   */
  protected $originalResults;

  /**
   * Creates a new processor object for use in the tests.
   */
  protected function setUp() {
    parent::setUp();
    $facet = new Facet([], 'facets_facet');
    $this->originalResults = [
      new Result($facet, 'llama', 'llama', 10),
      new Result($facet, 'badger', 'badger', 15),
      new Result($facet, 'duck', 'duck', 15),
    ];
    $this->processor = new HideActiveItemsProcessor([], 'hide_non_narrowing_result_processor', []);
  }

  /**
   * Tests filtering of results.
   */
  public function testNoFilterResults() {
    $facet = new Facet([], 'facets_facet');
    $facet
      ->setResults($this->originalResults);
    $filtered_results = $this->processor
      ->build($facet, $this->originalResults);
    $this
      ->assertCount(3, $filtered_results);
    $this
      ->assertEquals(10, $filtered_results[0]
      ->getCount());
    $this
      ->assertEquals('llama', $filtered_results[0]
      ->getDisplayValue());
    $this
      ->assertEquals(15, $filtered_results[1]
      ->getCount());
    $this
      ->assertEquals('badger', $filtered_results[1]
      ->getDisplayValue());
    $this
      ->assertEquals(15, $filtered_results[2]
      ->getCount());
    $this
      ->assertEquals('duck', $filtered_results[2]
      ->getDisplayValue());
  }

  /**
   * Tests filtering of results.
   */
  public function testFilterResults() {
    $results = $this->originalResults;
    $results[2]
      ->setActiveState(TRUE);
    $facet = new Facet([], 'facets_facet');
    $facet
      ->setResults($results);
    $filtered_results = $this->processor
      ->build($facet, $results);
    $this
      ->assertCount(2, $filtered_results);
    $this
      ->assertEquals(10, $filtered_results[0]
      ->getCount());
    $this
      ->assertEquals('llama', $filtered_results[0]
      ->getDisplayValue());
    $this
      ->assertEquals(15, $filtered_results[1]
      ->getCount());
    $this
      ->assertEquals('badger', $filtered_results[1]
      ->getDisplayValue());
  }

  /**
   * Tests configuration.
   */
  public function testConfiguration() {
    $config = $this->processor
      ->defaultConfiguration();
    $this
      ->assertEquals([], $config);
  }

  /**
   * Tests testDescription().
   */
  public function testDescription() {
    $this
      ->assertEquals('', $this->processor
      ->getDescription());
  }

  /**
   * Tests isHidden().
   */
  public function testIsHidden() {
    $this
      ->assertEquals(FALSE, $this->processor
      ->isHidden());
  }

  /**
   * Tests isLocked().
   */
  public function testIsLocked() {
    $this
      ->assertEquals(FALSE, $this->processor
      ->isLocked());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HideActiveItemsProcessorTest::$originalResults protected property An array containing the results before the processor has ran.
HideActiveItemsProcessorTest::$processor protected property The processor to be tested.
HideActiveItemsProcessorTest::setUp protected function Creates a new processor object for use in the tests. Overrides UnitTestCase::setUp
HideActiveItemsProcessorTest::testConfiguration public function Tests configuration.
HideActiveItemsProcessorTest::testDescription public function Tests testDescription().
HideActiveItemsProcessorTest::testFilterResults public function Tests filtering of results.
HideActiveItemsProcessorTest::testIsHidden public function Tests isHidden().
HideActiveItemsProcessorTest::testIsLocked public function Tests isLocked().
HideActiveItemsProcessorTest::testNoFilterResults public function Tests filtering of results.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.