public function FieldMatcherTest::testText in CRM Core 8.2
Same name and namespace in other branches
- 8.3 modules/crm_core_match/tests/src/Kernel/FieldMatcherTest.php \Drupal\Tests\crm_core_match\Kernel\FieldMatcherTest::testText()
- 8 modules/crm_core_match/tests/src/Kernel/FieldMatcherTest.php \Drupal\Tests\crm_core_match\Kernel\FieldMatcherTest::testText()
Test the text field.
File
- modules/
crm_core_match/ tests/ src/ Kernel/ FieldMatcherTest.php, line 152
Class
- FieldMatcherTest
- Tests the field matchers of the default matching engine.
Namespace
Drupal\Tests\crm_core_match\KernelCode
public function testText() {
FieldStorageConfig::create([
'entity_type' => 'crm_core_individual',
'type' => 'string',
'field_name' => 'individual_text',
])
->save();
FieldConfig::create([
'field_name' => 'individual_text',
'entity_type' => 'crm_core_individual',
'bundle' => 'customer',
'label' => t('Text'),
'required' => FALSE,
])
->save();
$config = array(
'value' => array(
'operator' => '=',
'score' => 42,
),
);
/** @var Individual $individual_needle */
$individual_needle = Individual::create([
'type' => 'customer',
]);
$individual_needle
->set('individual_text', 'Boomer');
$individual_needle
->save();
/** @var Individual $individual_match */
$individual_match = Individual::create([
'type' => 'customer',
]);
$individual_match
->set('individual_text', 'Boomer');
$individual_match
->save();
$config['field'] = $individual_needle
->getFieldDefinition('individual_text');
/* @var \Drupal\crm_core_match\Plugin\crm_core_match\field\FieldHandlerInterface $text */
$text = $this->pluginManager
->createInstance('text', $config);
$ids = $text
->match($individual_needle);
$this
->assertTrue(array_key_exists($individual_match
->id(), $ids), 'Text match returns expected match');
$this
->assertEqual(42, $ids[$individual_match
->id()]['individual_text.value'], 'Got expected match score');
}