Skip to content

Commit

Permalink
Add test for mergeConfig Field method.
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed Sep 4, 2018
1 parent 8a8e37d commit 33994f7
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions src/module-elasticsuite-core/Test/Unit/Index/Mapping/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,124 @@ public function getIsUsedInSpellcheckFieldConfigDataProvider()
],
];
}

/**
* @dataProvider getMergeConfigFieldConfigDataProvider
*
* @param array $fieldConfig Field configuration from data provider
* @param array $config Field configuration to merge, from data provider
* @param bool $isSearchable Expected result for is_searchable property
* @param bool $isFilterable Expected result for is_filterable property
* @param bool $isUsedForSortBy Expected result for is_used_for_sort_by property
* @param bool $isUsedInSpellcheck Expected result for is_used_in_spellcheck property
* @param int $searchWeight Expected result for search_weight property
* @param string $defaultAnalyzer Expected result for default_search_analyzer property
*/
public function testMergeConfig(
$fieldConfig,
$config,
$isSearchable,
$isFilterable,
$isUsedForSortBy,
$isUsedInSpellcheck,
$searchWeight,
$defaultAnalyzer
) {
$fieldType = FieldInterface::FIELD_TYPE_TEXT;
$field = new Field('field', $fieldType, null, $fieldConfig);

$field = $field->mergeConfig($config);

$this->assertEquals($isSearchable, $field->isSearchable());
$this->assertEquals($isFilterable, $field->isFilterable());
$this->assertEquals($isUsedForSortBy, $field->isUsedForSortBy());
$this->assertEquals($isUsedInSpellcheck, $field->isUsedInSpellcheck());
$this->assertEquals($searchWeight, $field->getSearchWeight());
$this->assertEquals($defaultAnalyzer, $field->getDefaultSearchAnalyzer());
}

/**
* Data provider to test proper merging of existing field config with new config.
* @return array
*/
public function getMergeConfigFieldConfigDataProvider()
{
return [
[
[
'is_searchable' => true,
'is_filterable' => true,
'is_used_for_sort_by' => false,
'is_used_in_spellcheck' => false,
'search_weight' => 1,
'default_search_analyzer' => 'standard',
],
[
'is_searchable' => true,
'is_filterable' => true,
'is_used_for_sort_by' => true,
'is_used_in_spellcheck' => true,
'search_weight' => 6,
'default_search_analyzer' => 'reference',
],
true,
true,
true,
true,
6,
'reference',
],
[
['is_searchable' => true, 'is_used_in_spellcheck' => false],
['is_searchable' => true, 'is_used_in_spellcheck' => true, 'search_weight' => 6, 'default_search_analyzer' => 'reference' ],
true,
true,
false,
true,
6,
'reference',
],
[
['is_searchable' => true, 'is_used_in_spellcheck' => false],
['is_searchable' => true, 'is_used_in_spellcheck' => true ],
true,
true,
false,
true,
1,
'standard',
],
[
['is_searchable' => true, 'is_used_in_spellcheck' => false],
[],
true,
true,
false,
false,
1,
'standard',
],
[
[],
['search_weight' => 6, 'default_search_analyzer' => 'reference'],
false,
true,
false,
false,
6,
'reference',
],
[
[],
[],
false,
true,
false,
false,
1,
'standard',
],
];
}
}

0 comments on commit 33994f7

Please sign in to comment.