public function AllTermsArgumentTest::setUp in Search API 8
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ Views/ AllTermsArgumentTest.php, line 50
Class
- AllTermsArgumentTest
- Tests whether the SearchApiAllTerms argument plugin works correctly.
Namespace
Drupal\Tests\search_api\Unit\ViewsCode
public function setUp() {
parent::setUp();
$this
->setupContainer();
$this->plugin = new SearchApiAllTerms([], 'search_api_all_terms', [
'vocabulary_fields' => [
'voc_a' => [
'field_voc_a',
],
'voc_b' => [
'field_voc_b_1',
'field_voc_b_2',
],
],
]);
$this->plugin->options['break_phrase'] = TRUE;
$term_values = [
1 => [
'id' => 1,
'label' => 'Term 1',
'bundle' => 'voc_a',
],
2 => [
'id' => 2,
'label' => 'Term 2',
'bundle' => 'voc_a',
],
3 => [
'id' => 3,
'label' => 'Term 3',
'bundle' => 'voc_b',
],
4 => [
'id' => 4,
'label' => 'Term 4',
'bundle' => 'voc_c',
],
];
$terms = [];
foreach ($term_values as $tid => $values) {
$term = $this
->createMock(TermInterface::class);
foreach ($values as $field => $value) {
$term
->method($field)
->willReturn($value);
}
$terms[$tid] = $term;
}
$this->termStorage
->method('loadMultiple')
->willReturnCallback(function (array $tids) use ($terms) : array {
return array_intersect_key($terms, array_flip($tids));
});
}