public function CustomBlockTypeTest::testCustomBlockTypeEditing

Tests editing a block type using the UI.

File

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

Class

CustomBlockTypeTest
Tests related to custom block types.

Namespace

Drupal\custom_block\Tests

Code

public function testCustomBlockTypeEditing() {
  $this
    ->drupalLogin($this->adminUser);

  // We need two block types to prevent /block/add redirecting.
  $this
    ->createCustomBlockType('other');
  $instance = field_info_instance('custom_block', 'block_body', 'basic');
  $this
    ->assertEqual($instance['label'], 'Block body', 'Body field was found.');

  // Verify that title and body fields are displayed.
  $this
    ->drupalGet('block/add/basic');
  $this
    ->assertRaw('Block description', 'Block info field was found.');
  $this
    ->assertRaw('Block body', 'Body field was found.');

  // Change the block type name.
  $edit = array(
    'label' => 'Bar',
  );
  $this
    ->drupalPost('admin/structure/custom-blocks/manage/basic', $edit, t('Save'));
  field_info_cache_clear();
  $this
    ->drupalGet('block/add');
  $this
    ->assertRaw('Bar', 'New name was displayed.');
  $this
    ->clickLink('Bar');
  $this
    ->assertEqual(url('block/add/basic', array(
    'absolute' => TRUE,
  )), $this
    ->getUrl(), 'Original machine name was used in URL.');

  // Remove the body field.
  $this
    ->drupalPost('admin/structure/custom-blocks/manage/basic/fields/custom_block.basic.block_body/delete', array(), t('Delete'));

  // Resave the settings for this type.
  $this
    ->drupalPost('admin/structure/custom-blocks/manage/basic', array(), t('Save'));

  // Check that the body field doesn't exist.
  $this
    ->drupalGet('block/add/basic');
  $this
    ->assertNoRaw('Block body', 'Body field was not found.');
}