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 {
17 protected $profile = 'testing';
22 * @var \Drupal\user\UserInterface
27 * Permissions to grant admin user.
31 protected $permissions = [
40 public static $modules = ['block', 'block_content'];
43 * Whether or not to auto-create the basic block type during setup.
47 protected $autoCreateBasicBlockType = TRUE;
52 protected function setUp() {
54 if ($this->autoCreateBasicBlockType) {
55 $this->createBlockContentType('basic', TRUE);
58 $this->adminUser = $this->drupalCreateUser($this->permissions);
59 $this->drupalPlaceBlock('local_actions_block');
63 * Creates a custom block.
65 * @param bool|string $title
66 * (optional) Title of block. When no value is given uses a random name.
68 * @param string $bundle
69 * (optional) Bundle name. Defaults to 'basic'.
71 * (optional) Whether to save the block. Defaults to TRUE.
73 * @return \Drupal\block_content\Entity\BlockContent
74 * Created custom block.
76 protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = TRUE) {
77 $title = $title ?: $this->randomMachineName();
78 $block_content = BlockContent::create([
83 if ($block_content && $save === TRUE) {
84 $block_content->save();
86 return $block_content;
90 * Creates a custom block type (bundle).
92 * @param string $label
93 * The block type label.
94 * @param bool $create_body
95 * Whether or not to create the body field
97 * @return \Drupal\block_content\Entity\BlockContentType
98 * Created custom block type.
100 protected function createBlockContentType($label, $create_body = FALSE) {
101 $bundle = BlockContentType::create([
108 block_content_add_body_field($bundle->id());