public function CustomBlockSaveTest::testDeterminingChanges

Tests determing changes in hook_block_presave().

Verifies the static block load cache is cleared upon save.

File

drupal/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php, line 75
Contains \Drupal\custom_block\Tests\CustomBlockSaveTest.

Class

CustomBlockSaveTest
Tests block save related functionality.

Namespace

Drupal\custom_block\Tests

Code

public function testDeterminingChanges() {

  // Initial creation.
  $block = $this
    ->createCustomBlock('test_changes');

  // Update the block without applying changes.
  $block
    ->save();
  $this
    ->assertEqual($block
    ->label(), 'test_changes', 'No changes have been determined.');

  // Apply changes.
  $block->info->value = 'updated';
  $block
    ->save();

  // The hook implementations custom_block_test_custom_block_presave() and
  // custom_block_test_custom_block_update() determine changes and change the
  // title.
  $this
    ->assertEqual($block
    ->label(), 'updated_presave_update', 'Changes have been determined.');

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