You are here

public function CrmCoreUserSyncRelationTest::testNoDuplicatedContactsCreated in CRM Core 8.3

Same name and namespace in other branches
  1. 8 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 200

Class

CrmCoreUserSyncRelationTest
Test description.

Namespace

Drupal\Tests\crm_core_user_sync\Kernel

Code

public function testNoDuplicatedContactsCreated() {
  $account_name = $this
    ->randomString();
  $account_authenticated = User::create([
    'name' => $account_name,
    'uid' => rand(50, 100),
  ]);
  $account_authenticated
    ->save();
  $authenticated_individual_id = $this->relationService
    ->getIndividualIdFromUserId($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');
}