You are here

public function ConfigEntityStatusTest::testCRUD in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStatusTest.php \Drupal\KernelTests\Core\Config\ConfigEntityStatusTest::testCRUD()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStatusTest.php \Drupal\KernelTests\Core\Config\ConfigEntityStatusTest::testCRUD()

Tests the enabling/disabling of entities.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStatusTest.php, line 24

Class

ConfigEntityStatusTest
Tests configuration entity status functionality.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testCRUD() {
  $entity = \Drupal::entityTypeManager()
    ->getStorage('config_test')
    ->create([
    'id' => strtolower($this
      ->randomMachineName()),
  ]);
  $this
    ->assertTrue($entity
    ->status(), 'Default status is enabled.');
  $entity
    ->save();
  $this
    ->assertTrue($entity
    ->status(), 'Status is enabled after saving.');
  $entity
    ->disable()
    ->save();
  $this
    ->assertFalse($entity
    ->status(), 'Entity is disabled after disabling.');
  $entity
    ->enable()
    ->save();
  $this
    ->assertTrue($entity
    ->status(), 'Entity is enabled after enabling.');
  $entity = \Drupal::entityTypeManager()
    ->getStorage('config_test')
    ->load($entity
    ->id());
  $this
    ->assertTrue($entity
    ->status(), 'Status is enabled after reload.');
}