You are here

public function BlockContentSaveTest::testDeterminingChanges in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/block_content/src/Tests/BlockContentSaveTest.php \Drupal\block_content\Tests\BlockContentSaveTest::testDeterminingChanges()

Tests determining changes in hook_block_presave().

Verifies the static block load cache is cleared upon save.

File

core/modules/block_content/src/Tests/BlockContentSaveTest.php, line 67
Contains \Drupal\block_content\Tests\BlockContentSaveTest.

Class

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

Namespace

Drupal\block_content\Tests

Code

public function testDeterminingChanges() {

  // Initial creation.
  $block = $this
    ->createBlockContent('test_changes');
  $this
    ->assertEqual($block
    ->getChangedTime(), REQUEST_TIME, 'Creating a block sets default "changed" timestamp.');

  // Update the block without applying changes.
  $block
    ->save();
  $this
    ->assertEqual($block
    ->label(), 'test_changes', '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
    ->assertEqual($block
    ->label(), 'updated_presave_update', 'Changes have been determined.');
  $this
    ->assertEqual($block
    ->getChangedTime(), 979534800, 'Saving a custom block uses "changed" timestamp set in presave hook.');

  // Test the static block load cache to be cleared.
  $block = BlockContent::load($block
    ->id());
  $this
    ->assertEqual($block
    ->label(), 'updated_presave', 'Static cache has been cleared.');
}