HideOnlyOneItemProcessorTest.php 2.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
<?php

namespace Drupal\Tests\facets\Unit\Plugin\processor;

use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\HideOnlyOneItemProcessor;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;

/**
 * Class HideOnlyOneItemProcessorTest.
 *
 * @coversDefaultClass Drupal\facets\Plugin\facets\processor\HideOnlyOneItemProcessor
 * @group facets
 */
class HideOnlyOneItemProcessorTest extends UnitTestCase {

  /**
   * Tests with one result.
   *
   * @covers ::build
   */
  public function testWithOneResult() {
    $processor = new HideOnlyOneItemProcessor([], 'hide_only_one_item', []);
    $facet = new Facet([], 'facets_facet');
    $results = [
      new Result($facet, '1', 1, 1),
    ];
    $facet = $this->getMockBuilder(Facet::class)
      ->disableOriginalConstructor()
      ->getMock();
    $processed_results = $processor->build($facet, $results);
    $this->assertCount(0, $processed_results);
  }

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  /**
   * Tests with one result that is already active.
   *
   * @covers ::build
   */
  public function testWithOneActiveResult() {
    $processor = new HideOnlyOneItemProcessor([], 'hide_only_one_item', []);
    $facet = new Facet([], 'facets_facet');
    $results = [
      new Result($facet, '1', 1, 1),
    ];
    $results[0]->setActiveState(TRUE);
    $facet = $this->getMockBuilder(Facet::class)
      ->disableOriginalConstructor()
      ->getMock();
    $processed_results = $processor->build($facet, $results);
    $this->assertCount(1, $processed_results);
  }

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  /**
   * Tests with one result.
   *
   * @covers ::build
   */
  public function testWithMoreResults() {
    $processor = new HideOnlyOneItemProcessor([], 'hide_only_one_item', []);
    $facet = new Facet([], 'facets_facet');
    $results = [
      new Result($facet, '1', 1, 1),
      new Result($facet, '2', 2, 2),
    ];
    $facet = $this->getMockBuilder(Facet::class)
      ->disableOriginalConstructor()
      ->getMock();
    $processed_results = $processor->build($facet, $results);
    $this->assertCount(2, $processed_results);
  }

}