function BlockContentSaveTest::testDeterminingChanges

Same name and namespace in other branches
  1. 9 core/modules/block_content/tests/src/Functional/BlockContentSaveTest.php \Drupal\Tests\block_content\Functional\BlockContentSaveTest::testDeterminingChanges()
  2. 8.9.x core/modules/block_content/tests/src/Functional/BlockContentSaveTest.php \Drupal\Tests\block_content\Functional\BlockContentSaveTest::testDeterminingChanges()
  3. 10 core/modules/block_content/tests/src/Functional/BlockContentSaveTest.php \Drupal\Tests\block_content\Functional\BlockContentSaveTest::testDeterminingChanges()

Tests determining changes in hook_block_presave().

Verifies the static block load cache is cleared upon save.

File

core/modules/block_content/tests/src/Functional/BlockContentSaveTest.php, line 72

Class

BlockContentSaveTest
Tests $block_content->save() for saving content.

Namespace

Drupal\Tests\block_content\Functional

Code

public function testDeterminingChanges() : void {
    // Initial creation.
    $block = $this->createBlockContent('test_changes');
    // Creating a block should set the changed date to the current time
    // which is always greater than the time set by hooks we're testing.
    $this->assertGreaterThan(979534800, $block->getChangedTime(), 'Creating a block sets default "changed" timestamp.');
    // Update the block without applying changes.
    $block->save();
    $this->assertEquals('test_changes', $block->label(), 'No changes have been determined.');
    // Apply changes.
    $block->setInfo('updated');
    $block->save();
    // The hook implementations block_content_test_block_content_presave() and
    // block_content_test_block_content_update() determine changes and change
    // the title as well as programmatically set the 'changed' timestamp.
    $this->assertEquals('updated_presave_update', $block->label(), 'Changes have been determined.');
    $this->assertEquals(979534800, $block->getChangedTime(), 'Saving a content block uses "changed" timestamp set in presave hook.');
    // Test the static block load cache to be cleared.
    $block = BlockContent::load($block->id());
    $this->assertEquals('updated_presave', $block->label(), 'Static cache has been cleared.');
}

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