Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
crm
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
crm
Merge requests
!57
Resolve
#3529218
"Test hookuserdelete"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve
#3529218
"Test hookuserdelete"
issue/crm-3529218:3529218-test-hookuserdelete
into
1.0.x
Overview
0
Commits
2
Pipelines
2
Changes
2
Merged
Steven Ayers
requested to merge
issue/crm-3529218:3529218-test-hookuserdelete
into
1.0.x
2 weeks ago
Overview
0
Commits
2
Pipelines
2
Changes
2
Expand
Closes
#3529218
0
0
Merge request reports
Compare
1.0.x
version 1
3cd840bc
2 weeks ago
1.0.x (base)
and
latest version
latest version
3cd840bc
2 commits,
2 weeks ago
version 1
3cd840bc
2 commits,
2 weeks ago
2 files
+
108
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
tests/src/Kernel/HookUserDeleteTest.php
0 → 100644
+
107
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\Tests\crm\Kernel
;
use
Drupal\KernelTests\Core\Entity\EntityKernelTestBase
;
use
Drupal\crm\Entity\Contact
;
use
Drupal\crm\Entity\User
;
/**
* Tests crm user contact mapping.
*
* @group crm
*/
class
HookUserDeleteTest
extends
EntityKernelTestBase
{
/**
* {@inheritdoc}
*/
protected
static
$modules
=
[
'address'
,
'comment'
,
'crm_field'
,
'crm'
,
'datetime'
,
'name'
,
'telephone'
,
];
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
installEntitySchema
(
'user'
);
$this
->
installSchema
(
'user'
,
[
'users_data'
]);
$this
->
installEntitySchema
(
'comment'
);
$this
->
installSchema
(
'comment'
,
[
'comment_entity_statistics'
]);
$this
->
installEntitySchema
(
'crm_contact'
);
$this
->
installEntitySchema
(
'crm_contact_detail'
);
$this
->
installEntitySchema
(
'crm_user'
);
$this
->
installConfig
([
'crm'
,
'name'
]);
}
/**
* Verify the mapping is deleted when a user is deleted.
*/
public
function
testUserDeleteWithContactMapping
():
void
{
// Create a user.
$user_1
=
$this
->
drupalCreateUser
();
$user_1
->
save
();
$contact_1
=
Contact
::
create
([
'name'
=>
'Test Contact'
,
'bundle'
=>
'person'
,
'full_name'
=>
[
'given_name'
=>
'Test'
,
'family_name'
=>
'User 1'
,
],
]);
$contact_1
->
save
();
$crm_user_1
=
User
::
create
([
'user'
=>
$user_1
->
id
(),
'crm_contact'
=>
$contact_1
->
id
(),
]);
$crm_user_1
->
save
();
$user_2
=
$this
->
drupalCreateUser
();
$user_2
->
save
();
$contact_2
=
Contact
::
create
([
'name'
=>
'Test Contact 2'
,
'bundle'
=>
'person'
,
'full_name'
=>
[
'given_name'
=>
'Test'
,
'family_name'
=>
'User 2'
,
],
]);
$contact_2
->
save
();
$crm_user_2
=
User
::
create
([
'user'
=>
$user_2
->
id
(),
'crm_contact'
=>
$contact_2
->
id
(),
]);
$crm_user_2
->
save
();
$crm_users
=
User
::
loadMultiple
();
$this
->
assertCount
(
2
,
$crm_users
,
'Two crm_user exists.'
);
// Delete the first user.
$user_1
->
delete
();
// Reset the user cache to ensure we are working with the latest data.
// \Drupal::entityTypeManager()->getStorage('crm_user')->resetCache();
$crm_users
=
User
::
loadMultiple
();
$this
->
assertCount
(
1
,
$crm_users
,
'One crm_user entity remains after deleting the user.'
);
$crm_user
=
reset
(
$crm_users
);
$this
->
assertEquals
(
$user_2
->
id
(),
$crm_user
->
getUserId
(),
'The remaining crm_user entity is linked to the second user.'
);
$this
->
assertEquals
(
$contact_2
->
id
(),
$crm_user
->
getContactId
(),
'The remaining crm_user entity is linked to the second contact.'
);
}
}
Loading