You are here

public function BlockContentSaveTest::testImport in Zircon Profile 8

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

Checks whether custom block IDs are saved properly during an import.

File

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

Class

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

Namespace

Drupal\block_content\Tests

Code

public function testImport() {

  // Custom block ID must be a number that is not in the database.
  $max_id = db_query('SELECT MAX(id) FROM {block_content}')
    ->fetchField();
  $test_id = $max_id + mt_rand(1000, 1000000);
  $info = $this
    ->randomMachineName(8);
  $block_array = array(
    'info' => $info,
    'body' => array(
      'value' => $this
        ->randomMachineName(32),
    ),
    'type' => 'basic',
    'id' => $test_id,
  );
  $block = entity_create('block_content', $block_array);
  $block
    ->enforceIsNew(TRUE);
  $block
    ->save();

  // Verify that block_submit did not wipe the provided id.
  $this
    ->assertEqual($block
    ->id(), $test_id, 'Block imported using provide id');

  // Test the import saved.
  $block_by_id = BlockContent::load($test_id);
  $this
    ->assertTrue($block_by_id, 'Custom block load by block ID.');
  $this
    ->assertIdentical($block_by_id->body->value, $block_array['body']['value']);
}