You are here

class ShowOnlyDeepestLevelItemsProcessorTest in Facets 8

Class ShowOnlyDeepestLevelItemsProcessorTest.

@group facets @coversDefaultClass \Drupal\facets\Plugin\facets\processor\ShowOnlyDeepestLevelItemsProcessor

Hierarchy

Expanded class hierarchy of ShowOnlyDeepestLevelItemsProcessorTest

File

tests/src/Unit/Plugin/processor/ShowOnlyDeepestLevelItemsProcessorTest.php, line 16

Namespace

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

  /**
   * The processor under test.
   *
   * @var \Drupal\facets\Plugin\facets\processor\ShowOnlyDeepestLevelItemsProcessor
   */
  protected $processor;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->processor = new ShowOnlyDeepestLevelItemsProcessor([], 'test', []);
  }

  /**
   * Tests that only items without children survive.
   *
   * @covers ::build
   */
  public function testRemoveItemsWithoutChildren() {
    $facet = new Facet([
      'id' => 'llama',
    ], 'facets_facet');

    // Setup results.
    $results = [
      new Result($facet, 'a', 'A', 5),
      new Result($facet, 'b', 'B', 2),
      new Result($facet, 'c', 'C', 4),
    ];
    $child = new Result($facet, 'a_1', 'A 1', 3);
    $results[0]
      ->setChildren([
      $child,
    ]);

    // Execute the build method, so we can test the behavior.
    $built_results = $this->processor
      ->build($facet, $results);

    // Sort to have a 0-indexed array.
    sort($built_results);

    // Check the output.
    $this
      ->assertCount(2, $built_results);
    $this
      ->assertSame('b', $built_results[0]
      ->getRawValue());
    $this
      ->assertSame('c', $built_results[1]
      ->getRawValue());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
ShowOnlyDeepestLevelItemsProcessorTest::$processor protected property The processor under test.
ShowOnlyDeepestLevelItemsProcessorTest::setUp public function Overrides UnitTestCase::setUp
ShowOnlyDeepestLevelItemsProcessorTest::testRemoveItemsWithoutChildren public function Tests that only items without children survive.
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.