function UpdateApiEntityDefinitionUpdateTest::testStatusReport

Tests that entity updates are correctly reported in the status report page.

File

core/modules/system/tests/src/Functional/Entity/Update/UpdateApiEntityDefinitionUpdateTest.php, line 125

Class

UpdateApiEntityDefinitionUpdateTest
Tests performing entity updates through the Update API.

Namespace

Drupal\Tests\system\Functional\Entity\Update

Code

public function testStatusReport() {
    // Create a test entity.
    $entity = EntityTest::create([
        'name' => $this->randomString(),
        'user_id' => mt_rand(),
    ]);
    $entity->save();
    // Check that the status report initially displays no error.
    $this->drupalGet('admin/reports/status');
    $this->assertNoRaw('Out of date');
    $this->assertNoRaw('Mismatched entity and/or field definitions');
    // Enable an entity update and check that we have a dedicated status report
    // item.
    $this->container
        ->get('state')
        ->set('entity_test.remove_name_field', TRUE);
    $this->drupalGet('admin/reports/status');
    $this->assertNoRaw('Out of date');
    $this->assertRaw('Mismatched entity and/or field definitions');
    // Enable a db update and check that now the entity update status report
    // item is no longer displayed. We assume an update function will fix the
    // mismatch.
    $this->enableUpdates('entity_test', 'status_report', 8001);
    $this->drupalGet('admin/reports/status');
    $this->assertRaw('Out of date');
    $this->assertRaw('Mismatched entity and/or field definitions');
    // Apply db updates and check that entity updates were not applied.
    $this->applyUpdates();
    $this->drupalGet('admin/reports/status');
    $this->assertNoRaw('Out of date');
    $this->assertRaw('Mismatched entity and/or field definitions');
    // Apply the entity updates and check that the entity update status report
    // item is no longer displayed.
    $this->applyEntityUpdates();
    $this->drupalGet('admin/reports/status');
    $this->assertNoRaw('Out of date');
    $this->assertNoRaw('Mismatched entity and/or field definitions');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.