'Custom Block field test', 'description' => 'Test block fieldability.', 'group' => 'Custom Block', ); } /** * Checks block edit functionality. */ public function testBlockFields() { $this->drupalLogin($this->adminUser); $this->blockType = $this->createCustomBlockType('link'); // Create a field with settings to validate. $this->field = entity_create('field_config', array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'custom_block', 'type' => 'link', 'cardinality' => 2, )); $this->field->save(); $this->instance = entity_create('field_instance_config', array( 'field_name' => $this->field->getName(), 'entity_type' => 'custom_block', 'bundle' => 'link', 'settings' => array( 'title' => DRUPAL_OPTIONAL, ), )); $this->instance->save(); entity_get_form_display('custom_block', 'link', 'default') ->setComponent($this->field->getName(), array( 'type' => 'link_default', )) ->save(); entity_get_display('custom_block', 'link', 'default') ->setComponent($this->field->getName(), array( 'type' => 'link', 'label' => 'hidden', )) ->save(); // Create a block. $this->drupalGet('block/add/link'); $edit = array( 'info[0][value]' => $this->randomName(8), $this->field->getName() . '[0][url]' => 'http://example.com', $this->field->getName() . '[0][title]' => 'Example.com' ); $this->drupalPostForm(NULL, $edit, t('Save')); $block = entity_load('custom_block', 1); $url = 'admin/structure/block/add/custom_block:' . $block->uuid() . '/' . \Drupal::config('system.theme')->get('default'); // Place the block. $instance = array( 'id' => drupal_strtolower($edit['info[0][value]']), 'settings[label]' => $edit['info[0][value]'], 'region' => 'sidebar_first', ); $this->drupalPostForm($url, $instance, t('Save block')); // Navigate to home page. $this->drupalGet(''); $this->assertLinkByHref('http://example.com'); $this->assertText('Example.com'); } }