public function IndividualCRUDTest::testIndividualType in CRM Core 8.3
Same name and namespace in other branches
- 8 modules/crm_core_contact/tests/src/Kernel/IndividualCRUDTest.php \Drupal\Tests\crm_core_contact\Kernel\IndividualCRUDTest::testIndividualType()
- 8.2 modules/crm_core_contact/tests/src/Kernel/IndividualCRUDTest.php \Drupal\Tests\crm_core_contact\Kernel\IndividualCRUDTest::testIndividualType()
Tests CRUD of individual types.
File
- modules/
crm_core_contact/ tests/ src/ Kernel/ IndividualCRUDTest.php, line 60
Class
- IndividualCRUDTest
- Tests CRUD operations for the CRM Core Individual entity.
Namespace
Drupal\Tests\crm_core_contact\KernelCode
public function testIndividualType() {
$type = 'dog';
// Create.
$individual_type = IndividualType::create([
'type' => $type,
]);
$this
->assertTrue(isset($individual_type->type) && $individual_type->type == $type, 'New individual type exists.');
$individual_type->name = $this
->randomMachineName();
$individual_type->description = $this
->randomString();
$individual_type->primary_fields = [];
$this
->assertEquals(SAVED_NEW, $individual_type
->save(), 'Individual type saved.');
// Load.
$individual_type_load = IndividualType::load($type);
$this
->assertEquals($individual_type->type, $individual_type_load->type, 'Loaded individual type has same type.');
$this
->assertEquals($individual_type->name, $individual_type_load->name, 'Loaded individual type has same name.');
$this
->assertEquals($individual_type->description, $individual_type_load->description, 'Loaded individual type has same description.');
$uuid = $individual_type_load
->uuid();
$this
->assertNotEmpty($uuid, 'Loaded individual type has uuid.');
// Test IndividualType::getNames().
$individual_type_labels = IndividualType::getNames();
$this
->assertSame($individual_type->name, $individual_type_labels[$individual_type->type]);
// Delete.
$individual_type_load
->delete();
$individual_type_load = IndividualType::load($type);
$this
->assertNull($individual_type_load, 'Individual type deleted.');
}