You are here

class GroupingBuildFormTest in Search API Grouping 8

Test the getSupportedFields method.

@group search_api_grouping

Hierarchy

Expanded class hierarchy of GroupingBuildFormTest

File

tests/src/Unit/GroupingBuildFormTest.php, line 21

Namespace

Drupal\Tests\search_api_grouping\Unit
View source
class GroupingBuildFormTest extends UnitTestCase {
  use ProcessorTestTrait;
  use StringTranslationTrait;

  /**
   * A mock of an index.
   *
   * @var \PHPUnit\Framework\MockObject\MockBuilder
   */
  protected $index;

  /**
   * {@inheritdoc}
   */
  public function setUp($processor = NULL) {
    parent::setUp();
    $serviceTranslation = new TranslationManager(new LanguageDefault([
      'en',
    ]));
    $container = new ContainerBuilder();
    \Drupal::setContainer($container);
    $container
      ->set('string_translation', $serviceTranslation);
    $this->processor = new Grouping([], 'grouping', []);
  }

  /**
   * Test if the form of the processor is built correctly.
   */
  public function testBuildForm() {
    $form_state = $this
      ->getMockBuilder(FormStateInterface::class)
      ->disableOriginalConstructor()
      ->getMock();
    $form = [];
    $field = $this
      ->getMockBuilder(FieldInterface::class)
      ->disableOriginalConstructor()
      ->getMock();
    $field
      ->method('getType')
      ->willReturn('string');
    $field
      ->method('getLabel')
      ->willReturn('Author');
    $fields[] = $field;
    $this->index = $this
      ->getMockBuilder(IndexInterface::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->index
      ->method('getFields')
      ->willReturn($fields);
    $this->processor
      ->setIndex($this->index);
    $form = $this->processor
      ->buildConfigurationForm($form, $form_state);
    $this
      ->assertEquals([], $form['grouping_fields']['#default_value']);
    $this
      ->assertEquals([], $form['group_sort']['#default_value']);
    $this
      ->assertEquals('asc', $form['group_sort_direction']['#default_value']);
    $this
      ->assertFalse($form['truncate']['#default_value']);
    $this
      ->assertEquals(1, $form['group_limit']['#default_value']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GroupingBuildFormTest::$index protected property A mock of an index.
GroupingBuildFormTest::setUp public function Overrides UnitTestCase::setUp
GroupingBuildFormTest::testBuildForm public function Test if the form of the processor is built correctly.
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.
ProcessorTestTrait::$processor protected property The tested processor.
ProcessorTestTrait::invokeMethod protected function Invokes a method on the processor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
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.