You are here

class HideWhenNotRenderedProcessorTest in Facets 8

Class HideWhenNotRenderedProcessorTest.

@group facets @coversDefaultClass \Drupal\facets_summary\Plugin\facets_summary\processor\HideWhenNotRenderedProcessor

Hierarchy

Expanded class hierarchy of HideWhenNotRenderedProcessorTest

File

modules/facets_summary/tests/src/Unit/Plugin/Processor/HideWhenNotRenderedProcessorTest.php, line 18

Namespace

Drupal\Tests\facets_summary\Unit\Plugin\Processor
View source
class HideWhenNotRenderedProcessorTest extends UnitTestCase {

  /**
   * The processor we're testing.
   *
   * @var \Drupal\facets_summary\Processor\ProcessorInterface|\Drupal\facets_summary\Processor\BuildProcessorInterface
   */
  protected $processor;

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

  /**
   * Tests the is hidden method.
   *
   * @covers ::isHidden
   */
  public function testIsHidden() {
    $this
      ->assertFalse($this->processor
      ->isHidden());
  }

  /**
   * Tests the is locked method.
   *
   * @covers ::isLocked
   */
  public function testIsLocked() {
    $this
      ->assertFalse($this->processor
      ->isLocked());
  }

  /**
   * Tests the build method, containing the actual work of the processor.
   *
   * @covers ::build
   */
  public function testBuild() {
    $this
      ->createContainer(TRUE);
    $summary = new FacetsSummary([], 'facets_summary');
    $summary
      ->setFacetSourceId('foo');
    $result = $this->processor
      ->build($summary, [
      'foo',
    ], []);
    $this
      ->assertEquals([
      'foo',
    ], $result);
  }

  /**
   * Tests the build method, containing the actual work of the processor.
   *
   * @covers ::build
   */
  public function testBuildWithNoCurrentRequest() {
    $this
      ->createContainer(FALSE);
    $summary = new FacetsSummary([], 'facets_summary');
    $summary
      ->setFacetSourceId('foo');
    $result = $this->processor
      ->build($summary, [
      'foo',
    ], []);
    $this
      ->assertEquals([], $result);
  }

  /**
   * Rendered in current request.
   *
   * @param bool $renderedInCurrentRequestValue
   *   The value for rendered in current request.
   */
  protected function createContainer($renderedInCurrentRequestValue) {
    $fsi = $this
      ->getMockBuilder(FacetSourcePluginInterface::class)
      ->disableOriginalConstructor()
      ->getMock();
    $fsi
      ->method('isRenderedInCurrentRequest')
      ->willReturn($renderedInCurrentRequestValue);
    $facetSourceManager = $this
      ->getMockBuilder(FacetSourcePluginManager::class)
      ->disableOriginalConstructor()
      ->getMock();
    $facetSourceManager
      ->method('createInstance')
      ->willReturn($fsi);
    $container = new ContainerBuilder();
    $container
      ->set('plugin.manager.facets.facet_source', $facetSourceManager);
    \Drupal::setContainer($container);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HideWhenNotRenderedProcessorTest::$processor protected property The processor we're testing.
HideWhenNotRenderedProcessorTest::createContainer protected function Rendered in current request.
HideWhenNotRenderedProcessorTest::setUp public function Overrides UnitTestCase::setUp
HideWhenNotRenderedProcessorTest::testBuild public function Tests the build method, containing the actual work of the processor.
HideWhenNotRenderedProcessorTest::testBuildWithNoCurrentRequest public function Tests the build method, containing the actual work of the processor.
HideWhenNotRenderedProcessorTest::testIsHidden public function Tests the is hidden method.
HideWhenNotRenderedProcessorTest::testIsLocked public function Tests the is locked method.
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.