public function CrmCoreUserSyncRelationTest::testNoDuplicatedContactsCreated in CRM Core 8
Same name and namespace in other branches
- 8.3 modules/crm_core_user_sync/tests/src/Kernel/CrmCoreUserSyncRelationTest.php \Drupal\Tests\crm_core_user_sync\Kernel\CrmCoreUserSyncRelationTest::testNoDuplicatedContactsCreated()
Tests that "relate" method is idempotent.
See also
\Drupal\crm_core_user_sync\CrmCoreUserSyncRelation::relate()
File
- modules/
crm_core_user_sync/ tests/ src/ Kernel/ CrmCoreUserSyncRelationTest.php, line 191
Class
- CrmCoreUserSyncRelationTest
- Test description.
Namespace
Drupal\Tests\crm_core_user_sync\KernelCode
public function testNoDuplicatedContactsCreated() {
$account_name = $this
->randomString();
$account_authenticated = User::create([
'name' => $account_name,
]);
$account_authenticated
->save();
$authenticated_individual_id = $this->relationService
->getUserIndividualId($account_authenticated
->id());
$this
->assertNotEmpty($authenticated_individual_id, 'Related contact was created');
$this->relationService
->relate($account_authenticated);
$contacts_with_name = $this->entityManager
->getStorage('crm_core_individual')
->getQuery()
->condition('name.given', $account_name)
->count()
->execute();
$this
->assertEquals(1, $contacts_with_name, 'There is only one contact was created');
}