class ContactTest

Same name in other branches
  1. 3.x modules/content_entity_example/tests/src/Kernel/ContactTest.php \Drupal\Tests\content_entity_example\Kernel\ContactTest
  2. 4.0.x modules/content_entity_example/tests/src/Kernel/ContactTest.php \Drupal\Tests\content_entity_example\Kernel\ContactTest

Test basic CRUD operations for our Contact entity type.

@group content_entity_example @group examples

Hierarchy

  • class \Drupal\Tests\content_entity_example\Kernel\ContactTest extends \Drupal\KernelTests\KernelTestBase

Expanded class hierarchy of ContactTest

Related topics

File

content_entity_example/tests/src/Kernel/ContactTest.php, line 16

Namespace

Drupal\Tests\content_entity_example\Kernel
View source
class ContactTest extends KernelTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'content_entity_example',
        'options',
        'user',
    ];
    
    /**
     * Basic CRUD operations on a Contact entity.
     */
    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));
    }

}

Members

Title Sort descending Modifiers Object type Summary
ContactTest::$defaultTheme protected property
ContactTest::$modules protected static property
ContactTest::testEntity public function Basic CRUD operations on a Contact entity.