public function FieldMatcherTest::testName 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::testName()
- 8 modules/crm_core_match/tests/src/Kernel/FieldMatcherTest.php \Drupal\Tests\crm_core_match\Kernel\FieldMatcherTest::testName()
Test the text field.
File
- modules/
crm_core_match/ tests/ src/ Kernel/ FieldMatcherTest.php, line 90
Class
- FieldMatcherTest
- Tests the field matchers of the default matching engine.
Namespace
Drupal\Tests\crm_core_match\KernelCode
public function testName() {
$config = [
'title' => [
'score' => 1,
],
'given' => [
'score' => 10,
],
'middle' => [
'score' => 1,
],
'family' => [
'score' => 20,
],
'generational' => [
'score' => 1,
],
'credentials' => [
'score' => 1,
],
];
/** @var Individual $individual_needle */
$individual_needle = Individual::create([
'type' => 'customer',
]);
$individual_needle
->set('name', [
'title' => 'Mr.',
'given' => 'Gimeno',
'family' => 'Boomer',
])
->save();
/** @var Individual $individual_match */
$individual_match = Individual::create([
'type' => 'customer',
]);
$individual_match
->set('name', [
'title' => 'Mr.',
'given' => 'Gimeno',
'family' => 'Boomer',
])
->save();
/** @var Individual $individual_match2 */
$individual_match2 = Individual::create([
'type' => 'customer',
]);
$individual_match2
->set('name', [
'title' => 'Mr.',
'given' => 'Rodrigo',
'family' => 'Boomer',
])
->save();
$config['field'] = $individual_needle
->getFieldDefinition('name');
/* @var \Drupal\crm_core_match\Plugin\crm_core_match\field\FieldHandlerInterface $text */
$text = $this->pluginManager
->createInstance('name', $config);
$ids = $text
->match($individual_needle);
$this
->assertTrue(array_key_exists($individual_match
->id(), $ids), 'Text match returns expected match.');
$this
->assertTrue(array_key_exists($individual_match2
->id(), $ids), 'Text match returns expected match.');
$this
->assertEquals(20, $ids[$individual_match
->id()]['name.family'], 'Got expected match score.');
$this
->assertEquals(20, $ids[$individual_match2
->id()]['name.family'], 'Got expected match score.');
$ids = $text
->match($individual_needle, 'given');
$this
->assertTrue(array_key_exists($individual_match
->id(), $ids), 'Text match returns expected match.');
$this
->assertFalse(array_key_exists($individual_match2
->id(), $ids), 'Text match does not return wrong match.');
$this
->assertEquals(10, $ids[$individual_match
->id()]['name.given'], 'Got expected match score.');
}