You are here

class DisplayValueWidgetOrderProcessorTest in Facets 8

Unit test for processor.

@group facets

Hierarchy

Expanded class hierarchy of DisplayValueWidgetOrderProcessorTest

File

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

Namespace

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

  /**
   * The processor to be tested.
   *
   * @var \Drupal\facets\Processor\SortProcessorInterface
   */
  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, 'thetans', 'thetans', 10),
      new Result($facet, 'xenu', 'xenu', 5),
      new Result($facet, 'Tom', 'Tom', 15),
      new Result($facet, 'Hubbard', 'Hubbard', 666),
      new Result($facet, 'FALSE', 'FALSE', 1),
      new Result($facet, '1977', '1977', 20),
      new Result($facet, '2', '2', 22),
    ];
    $transliteration = $this
      ->getMockBuilder(TransliterationInterface::class)
      ->disableOriginalConstructor()
      ->getMock();
    $transliteration
      ->expects($this
      ->any())
      ->method('removeDiacritics')
      ->will($this
      ->returnArgument(0));
    $this->processor = new DisplayValueWidgetOrderProcessor([], 'display_value_widget_order', [], $transliteration);
  }

  /**
   * Tests sorting.
   */
  public function testSorting() {
    $result_count = $this->processor
      ->sortResults($this->originalResults[0], $this->originalResults[1]);
    $this
      ->assertEquals(-1, $result_count);
    $result_count = $this->processor
      ->sortResults($this->originalResults[1], $this->originalResults[2]);
    $this
      ->assertEquals(1, $result_count);
    $result_count = $this->processor
      ->sortResults($this->originalResults[2], $this->originalResults[3]);
    $this
      ->assertEquals(1, $result_count);
    $result_count = $this->processor
      ->sortResults($this->originalResults[3], $this->originalResults[4]);
    $this
      ->assertEquals(1, $result_count);
    $result_count = $this->processor
      ->sortResults($this->originalResults[4], $this->originalResults[5]);
    $this
      ->assertEquals(1, $result_count);
    $result_count = $this->processor
      ->sortResults($this->originalResults[5], $this->originalResults[6]);
    $this
      ->assertEquals(1, $result_count);
    $result_count = $this->processor
      ->sortResults($this->originalResults[6], $this->originalResults[5]);
    $this
      ->assertEquals(-1, $result_count);
    $result_count = $this->processor
      ->sortResults($this->originalResults[3], $this->originalResults[3]);
    $this
      ->assertEquals(0, $result_count);
  }

  /**
   * Tests that sorting uses the display value.
   */
  public function testUseActualDisplayValue() {
    $facet = new Facet([], 'facets_facet');
    $original = [
      new Result($facet, 'bb_test', 'Test AA', 10),
      new Result($facet, 'aa_test', 'Test BB', 10),
    ];
    $sorted_results = $this->processor
      ->sortResults($original[0], $original[1]);
    $this
      ->assertEquals(-1, $sorted_results);
    $sorted_results = $this->processor
      ->sortResults($original[1], $original[0]);
    $this
      ->assertEquals(1, $sorted_results);
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
DisplayValueWidgetOrderProcessorTest::$originalResults protected property An array containing the results before the processor has ran.
DisplayValueWidgetOrderProcessorTest::$processor protected property The processor to be tested.
DisplayValueWidgetOrderProcessorTest::setUp protected function Creates a new processor object for use in the tests. Overrides UnitTestCase::setUp
DisplayValueWidgetOrderProcessorTest::testDefaultConfiguration public function Tests configuration.
DisplayValueWidgetOrderProcessorTest::testSorting public function Tests sorting.
DisplayValueWidgetOrderProcessorTest::testUseActualDisplayValue public function Tests that sorting uses the display value.
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.