public function OrganizationCRUDTest::testOrganization in CRM Core 8.2
Same name and namespace in other branches
- 8.3 modules/crm_core_contact/tests/src/Kernel/OrganizationCRUDTest.php \Drupal\Tests\crm_core_contact\Kernel\OrganizationCRUDTest::testOrganization()
- 8 modules/crm_core_contact/tests/src/Kernel/OrganizationCRUDTest.php \Drupal\Tests\crm_core_contact\Kernel\OrganizationCRUDTest::testOrganization()
Tests CRUD of organizations.
File
- modules/
crm_core_contact/ tests/ src/ Kernel/ OrganizationCRUDTest.php, line 86
Class
- OrganizationCRUDTest
- Tests CRUD operations for the CRM Core Organization entity.
Namespace
Drupal\Tests\crm_core_contact\KernelCode
public function testOrganization() {
$this
->installEntitySchema('user');
$type = OrganizationType::create(array(
'id' => 'test',
'primary_fields' => [],
));
$type
->save();
// Create.
$organization = Organization::create(array(
'type' => $type
->id(),
));
$this
->assertEquals(SAVED_NEW, $organization
->save(), 'Organization saved.');
// Create second organization.
$organization_one = Organization::create(array(
'type' => $type
->id(),
));
$this
->assertEquals(SAVED_NEW, $organization_one
->save(), 'Organization saved.');
// Load.
$organization_load = Organization::load($organization
->id());
$uuid = $organization_load
->uuid();
$this
->assertTrue(!empty($uuid), 'Loaded organization has uuid.');
$activity_type = ActivityType::create(array(
'type' => 'activity_test',
));
$activity_type
->save();
// Create activity and add participants organization.
$activity = Activity::create(array(
'type' => $activity_type->type,
));
$activity
->get('activity_participants')
->appendItem($organization);
$activity
->get('activity_participants')
->appendItem($organization_one);
$this
->assertEquals(SAVED_NEW, $activity
->save(), 'Activity saved.');
// Load activity.
$activity_load = Activity::load($activity
->id());
$this
->assertTrue(!empty($activity_load
->uuid()), 'Loaded activity has uuid.');
// Delete first organization, activity should'n be deleted because it's
// related to second organization.
$organization
->delete();
$organization_load = Organization::load($organization
->id());
$this
->assertNull($organization_load, 'Organization deleted.');
$activity_load = Activity::load($activity
->id());
$this
->assertNotNull($activity_load, 'Activity not deleted.');
// Delete second organization and now activity should be deleted too.
$organization_one
->delete();
$organization_load = Organization::load($organization_one
->id());
$this
->assertNull($organization_load, 'Organization deleted.');
$activity_load = Activity::load($activity
->id());
$this
->assertNull($activity_load, 'Activity deleted.');
}