public function CustomBlockTypeTest::testCustomBlockTypeCreation

Tests creating a block type programmatically and via a form.

File

drupal/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php, line 46
Contains \Drupal\custom_block\Tests\CustomBlockTypeTest.

Class

CustomBlockTypeTest
Tests related to custom block types.

Namespace

Drupal\custom_block\Tests

Code

public function testCustomBlockTypeCreation() {

  // Create a block type programmaticaly.
  $type = $this
    ->createCustomBlockType('other');
  $block_type = entity_load('custom_block_type', 'other');
  $this
    ->assertTrue($block_type, 'The new block type has been created.');

  // Login a test user.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('block/add/' . $type
    ->id());
  $this
    ->assertResponse(200, 'The new block type can be accessed at bloack/add.');

  // Create a block type via the user interface.
  $edit = array(
    'id' => 'foo',
    'label' => 'title for foo',
  );
  $this
    ->drupalPost('admin/structure/custom-blocks/add', $edit, t('Save'));
  $block_type = entity_load('custom_block_type', 'foo');
  $this
    ->assertTrue($block_type, 'The new block type has been created.');

  // Check that the block type was created in site default language.
  $default_langcode = language_default()->langcode;
  $this
    ->assertEqual($block_type->langcode, $default_langcode);
}