3 namespace Drupal\Tests\block_content\Functional;
5 use Drupal\block_content\Entity\BlockContent;
6 use Drupal\block_content\Entity\BlockContentType;
7 use Drupal\Tests\BrowserTestBase;
10 * Sets up block content types.
12 abstract class BlockContentTestBase extends BrowserTestBase {
19 protected $profile = 'testing';
24 * @var \Drupal\user\UserInterface
29 * Permissions to grant admin user.
33 protected $permissions = [
42 public static $modules = ['block', 'block_content'];
45 * Whether or not to auto-create the basic block type during setup.
49 protected $autoCreateBasicBlockType = TRUE;
54 protected function setUp() {
56 if ($this->autoCreateBasicBlockType) {
57 $this->createBlockContentType('basic', TRUE);
60 $this->adminUser = $this->drupalCreateUser($this->permissions);
61 $this->drupalPlaceBlock('local_actions_block');
65 * Creates a custom block.
67 * @param bool|string $title
68 * (optional) Title of block. When no value is given uses a random name.
70 * @param string $bundle
71 * (optional) Bundle name. Defaults to 'basic'.
73 * (optional) Whether to save the block. Defaults to TRUE.
75 * @return \Drupal\block_content\Entity\BlockContent
76 * Created custom block.
78 protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = TRUE) {
79 $title = $title ?: $this->randomMachineName();
80 $block_content = BlockContent::create([
85 if ($block_content && $save === TRUE) {
86 $block_content->save();
88 return $block_content;
92 * Creates a custom block type (bundle).
94 * @param string $label
95 * The block type label.
96 * @param bool $create_body
97 * Whether or not to create the body field
99 * @return \Drupal\block_content\Entity\BlockContentType
100 * Created custom block type.
102 protected function createBlockContentType($label, $create_body = FALSE) {
103 $bundle = BlockContentType::create([
110 block_content_add_body_field($bundle->id());