public function ActivityEntityPreDeleteTest::testContactPreDelete in CRM Core 8
Same name and namespace in other branches
- 8.3 modules/crm_core_activity/tests/src/Kernel/ActivityEntityPreDeleteTest.php \Drupal\Tests\crm_core_activity\Kernel\ActivityEntityPreDeleteTest::testContactPreDelete()
- 8.2 modules/crm_core_activity/tests/src/Kernel/ActivityEntityPreDeleteTest.php \Drupal\Tests\crm_core_activity\Kernel\ActivityEntityPreDeleteTest::testContactPreDelete()
Tests activity type plugin.
File
- modules/
crm_core_activity/ tests/ src/ Kernel/ ActivityEntityPreDeleteTest.php, line 54
Class
Namespace
Drupal\Tests\crm_core_activity\KernelCode
public function testContactPreDelete() {
/** @var \Drupal\crm_core_activity\Entity\ActivityType $activity_type */
$activity_type = $this->container
->get('entity_type.manager')
->getStorage('crm_core_activity_type')
->create([
'name' => 'Test type',
'type' => 'test_type',
'description' => 'Test type description.',
'plugin_id' => 'generic',
]);
$activity_type
->save();
$individual_1 = Individual::create([
'type' => 'customer',
'name' => [
'given' => 'John',
'family' => 'Smith',
],
'email_value' => 'test1@example.com',
'email_type' => 'private',
]);
$individual_1
->save();
$individual_2 = Individual::create([
'type' => 'customer',
'name' => [
'given' => 'Mark',
'family' => 'Jones',
],
'email_value' => 'test2@example.com',
'email_type' => 'corporate',
]);
$individual_2
->save();
$activity_1 = Activity::create([
'type' => 'test_type',
'title' => 'Activity title',
'activity_participants' => [
$individual_1,
$individual_2,
],
]);
$activity_1
->save();
$activity_2 = Activity::create([
'type' => 'test_type',
'title' => 'Activity title 2',
'activity_participants' => [
$individual_2,
],
]);
$activity_2
->save();
$individual_2
->delete();
$loaded_activity = Activity::load($activity_2
->id());
$this
->assertNull($loaded_activity, 'Activity 2 was deleted.');
$loaded_activity = Activity::load($activity_1
->id());
$this
->assertTrue((bool) $loaded_activity, 'Activity 1 was loaded.');
$individual_1
->delete();
$loaded_activity = Activity::load($activity_1
->id());
$this
->assertNull($loaded_activity, 'Activity 1 was deleted.');
}