function ContactTest::testEntity
Same name in other branches
- 3.x modules/content_entity_example/tests/src/Kernel/ContactTest.php \Drupal\Tests\content_entity_example\Kernel\ContactTest::testEntity()
Basic CRUD operations on a Contact entity.
File
-
modules/
content_entity_example/ tests/ src/ Kernel/ ContactTest.php, line 31
Class
- ContactTest
- Test basic CRUD operations for our Contact entity type.
Namespace
Drupal\Tests\content_entity_example\KernelCode
public function testEntity() {
$this->installEntitySchema('content_entity_example_contact');
$entity = Contact::create([
'name' => 'Name',
'first_name' => 'Firstname',
'user_id' => 0,
'role' => 'user',
]);
$this->assertNotNull($entity);
$this->assertEquals(SAVED_NEW, $entity->save());
$this->assertEquals(SAVED_UPDATED, $entity->set('role', 'administrator')
->save());
$entity_id = $entity->id();
$this->assertNotEmpty($entity_id);
$entity->delete();
$this->assertNull(Contact::load($entity_id));
}