protected function BlockStorageUnitTest::createTests

Tests the creation of blocks.

1 call to BlockStorageUnitTest::createTests()
BlockStorageUnitTest::testBlockCRUD in drupal/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php
Tests CRUD operations.

File

drupal/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php, line 69
Contains \Drupal\block\Tests\BlockStorageUnitTest.

Class

BlockStorageUnitTest
Tests the storage of blocks.

Namespace

Drupal\block\Tests

Code

protected function createTests() {

  // Attempt to create a block without a plugin.
  try {
    $entity = $this->controller
      ->create(array());
    $entity
      ->getPlugin();
    $this
      ->fail('A block without a plugin was created with no exception thrown.');
  } catch (PluginException $e) {
    $this
      ->assertEqual('The block \'\' did not specify a plugin.', $e
      ->getMessage(), 'An exception was thrown when a block was created without a plugin.');
  }

  // Create a block with only required values.
  $entity = $this->controller
    ->create(array(
    'id' => 'stark.test_block',
    'plugin' => 'test_html_id',
  ));
  $entity
    ->save();
  $this
    ->assertTrue($entity instanceof Block, 'The newly created entity is a Block.');

  // Verify all of the block properties.
  $actual_properties = config('block.block.stark.test_block')
    ->get();
  $this
    ->assertTrue(!empty($actual_properties['uuid']), 'The block UUID is set.');
  unset($actual_properties['uuid']);

  // Ensure that default values are filled in.
  $expected_properties = array(
    'id' => 'stark.test_block',
    'weight' => '',
    'status' => '1',
    'langcode' => language_default()->langcode,
    'region' => '-1',
    'plugin' => 'test_html_id',
    'settings' => array(
      'cache' => '1',
      'label' => '',
      'module' => 'block_test',
      'label_display' => BLOCK_LABEL_VISIBLE,
    ),
    'visibility' => '',
  );
  $this
    ->assertIdentical($actual_properties, $expected_properties, 'The block properties are exported correctly.');
  $this
    ->assertTrue($entity
    ->getPlugin() instanceof TestHtmlIdBlock, 'The entity has an instance of the correct block plugin.');
}