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
!63
Issue
#3529441
by bluegeek9: Test: hook_crm_contact_delete
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3529441
by bluegeek9: Test: hook_crm_contact_delete
issue/crm-3529441:3529441-test-hookcrmcontactdelete
into
1.0.x
Overview
0
Commits
3
Pipelines
4
Changes
2
Merged
Steven Ayers
requested to merge
issue/crm-3529441:3529441-test-hookcrmcontactdelete
into
1.0.x
2 weeks ago
Overview
0
Commits
3
Pipelines
4
Changes
2
Expand
Closes
#3529441
0
0
Merge request reports
Compare
1.0.x
version 3
08eaa127
2 weeks ago
version 2
db359fc2
2 weeks ago
version 1
b999b059
2 weeks ago
1.0.x (base)
and
latest version
latest version
08eaa127
3 commits,
2 weeks ago
version 3
08eaa127
3 commits,
2 weeks ago
version 2
db359fc2
2 commits,
2 weeks ago
version 1
b999b059
1 commit,
2 weeks ago
2 files
+
237
−
19
Side-by-side
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/HookContactDeleteTest.php
0 → 100644
+
217
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\Tests\crm\Kernel
;
use
Drupal\crm\Entity\Contact
;
use
Drupal\crm\Entity\ContactDetail
;
use
Drupal\crm\Entity\Relationship
;
use
Drupal\crm\Entity\User
;
use
Drupal\KernelTests\Core\Entity\EntityKernelTestBase
;
/**
* Tests crm user contact mapping.
*
* @group crm
*/
class
HookContactDeleteTest
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_relationship'
);
$this
->
installEntitySchema
(
'crm_user'
);
$this
->
installConfig
([
'crm'
,
'name'
]);
}
/**
* Verify the mapping is deleted when a user is deleted.
*/
public
function
testContactDeleteWithUserMapping
():
void
{
$organization_email
=
ContactDetail
::
create
([
'email'
=>
'organization@example.local'
,
'bundle'
=>
'email'
,
]);
$organization_email
->
save
();
$organization_telephone
=
ContactDetail
::
create
([
'telephone'
=>
'(555) 555 - 5555'
,
'bundle'
=>
'telephone'
,
]);
$organization_telephone
->
save
();
$organization_address
=
ContactDetail
::
create
([
'address'
=>
[
'city'
=>
'New Lenox'
,
],
'bundle'
=>
'address'
,
]);
$organization_address
->
save
();
$organization
=
Contact
::
create
([
'name'
=>
'Organization'
,
'bundle'
=>
'organization'
,
'emails'
=>
[
$organization_email
],
'telephones'
=>
[
$organization_telephone
],
'addresses'
=>
[
$organization_address
],
]);
$organization
->
save
();
// Create a user.
$user_1
=
$this
->
drupalCreateUser
();
$user_1
->
save
();
$person_1_email
=
ContactDetail
::
create
([
'email'
=>
'person_1@example.local'
,
'bundle'
=>
'email'
,
]);
$person_1_email
->
save
();
$person_1_telephone
=
ContactDetail
::
create
([
'telephone'
=>
'(555) 555 - 5555'
,
'bundle'
=>
'telephone'
,
]);
$person_1_telephone
->
save
();
$person_1_address
=
ContactDetail
::
create
([
'address'
=>
[
'city'
=>
'New Lenox'
,
],
'bundle'
=>
'address'
,
]);
$person_1_address
->
save
();
$person_1
=
Contact
::
create
([
'name'
=>
'Test person'
,
'bundle'
=>
'person'
,
'full_name'
=>
[
'given_name'
=>
'Test'
,
'family_name'
=>
'User 1'
,
],
'emails'
=>
[
$person_1_email
],
'telephones'
=>
[
$person_1_telephone
],
'addresses'
=>
[
$person_1_address
],
]);
$person_1
->
save
();
$crm_user_1
=
User
::
create
([
'user'
=>
$user_1
->
id
(),
'crm_contact'
=>
$person_1
->
id
(),
]);
$crm_user_1
->
save
();
$user_2
=
$this
->
drupalCreateUser
();
$user_2
->
save
();
$person_2_email
=
ContactDetail
::
create
([
'email'
=>
'person_2@example.local'
,
'bundle'
=>
'email'
,
]);
$person_2_email
->
save
();
$person_2_telephone
=
ContactDetail
::
create
([
'telephone'
=>
'(555) 555 - 5555'
,
'bundle'
=>
'telephone'
,
]);
$person_2_telephone
->
save
();
$person_2_address
=
ContactDetail
::
create
([
'address'
=>
[
'city'
=>
'New Lenox'
,
],
'bundle'
=>
'address'
,
]);
$person_2_address
->
save
();
$person_2
=
Contact
::
create
([
'name'
=>
'Test person'
,
'bundle'
=>
'person'
,
'full_name'
=>
[
'given_name'
=>
'Test'
,
'family_name'
=>
'User 2'
,
],
'emails'
=>
[
$person_2_email
],
'telephones'
=>
[
$person_2_telephone
],
'addresses'
=>
[
$person_2_address
],
]);
$person_2
->
save
();
$crm_user_2
=
User
::
create
([
'user'
=>
$user_2
->
id
(),
'crm_contact'
=>
$person_2
->
id
(),
]);
$crm_user_2
->
save
();
$relationship_siblings
=
Relationship
::
create
([
'bundle'
=>
'siblings'
,
'contact_a'
=>
$person_1
,
'contact_b'
=>
$person_2
,
]);
$relationship_siblings
->
save
();
$relationship_employee_1
=
Relationship
::
create
([
'bundle'
=>
'employee'
,
'contact_a'
=>
$person_1
,
'contact_b'
=>
$organization
,
]);
$relationship_employee_1
->
save
();
$relationship_employee_2
=
Relationship
::
create
([
'bundle'
=>
'employee'
,
'contact_a'
=>
$person_2
,
'contact_b'
=>
$organization
,
]);
$relationship_employee_2
->
save
();
$crm_users
=
User
::
loadMultiple
();
$this
->
assertCount
(
2
,
$crm_users
,
'Two crm_user exists.'
);
$crm_contacts
=
Contact
::
loadMultiple
();
$this
->
assertCount
(
3
,
$crm_contacts
,
'Three crm_contacts exists.'
);
$crm_contact_details
=
ContactDetail
::
loadMultiple
();
$this
->
assertCount
(
9
,
$crm_contact_details
,
'Nine crm_contact_details exists.'
);
$crm_relationships
=
Relationship
::
loadMultiple
();
$this
->
assertCount
(
3
,
$crm_relationships
,
'Three crm_relationships exists.'
);
// Delete the first user.
$person_1
->
delete
();
// Reset the user cache to ensure we are working with the latest data.
$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
(
$person_2
->
id
(),
$crm_user
->
getContactId
(),
'The remaining crm_user entity is linked to the second contact.'
);
$crm_contacts
=
Contact
::
loadMultiple
();
$this
->
assertCount
(
2
,
$crm_contacts
,
'Two crm_contacts exists.'
);
$crm_contact_details
=
ContactDetail
::
loadMultiple
();
$this
->
assertCount
(
6
,
$crm_contact_details
,
'Six crm_contact_details exists.'
);
$crm_relationships
=
Relationship
::
loadMultiple
();
$this
->
assertCount
(
1
,
$crm_relationships
,
'One crm_relationships exists.'
);
}
}
Loading