class GroupingBuildFormTest in Search API Grouping 8
Test the getSupportedFields method.
@group search_api_grouping
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\search_api_grouping\Unit\GroupingBuildFormTest uses StringTranslationTrait, ProcessorTestTrait
Expanded class hierarchy of GroupingBuildFormTest
File
- tests/
src/ Unit/ GroupingBuildFormTest.php, line 21
Namespace
Drupal\Tests\search_api_grouping\UnitView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GroupingBuildFormTest:: |
protected | property | A mock of an index. | |
GroupingBuildFormTest:: |
public | function |
Overrides UnitTestCase:: |
|
GroupingBuildFormTest:: |
public | function | Test if the form of the processor is built correctly. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
ProcessorTestTrait:: |
protected | property | The tested processor. | |
ProcessorTestTrait:: |
protected | function | Invokes a method on the processor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |