3 namespace Drupal\block_content\Tests;
5 use Drupal\block_content\Entity\BlockContent;
6 use Drupal\block_content\Entity\BlockContentType;
7 use Drupal\simpletest\WebTestBase;
10 * Sets up block content types.
12 * @deprecated Scheduled for removal in Drupal 9.0.0.
13 * Use \Drupal\Tests\block_content\Functional\BlockContentTestBase instead.
15 abstract class BlockContentTestBase extends WebTestBase {
22 protected $profile = 'testing';
27 * @var \Drupal\user\UserInterface
32 * Permissions to grant admin user.
36 protected $permissions = [
45 public static $modules = ['block', 'block_content'];
48 * Whether or not to auto-create the basic block type during setup.
52 protected $autoCreateBasicBlockType = TRUE;
57 protected function setUp() {
59 if ($this->autoCreateBasicBlockType) {
60 $this->createBlockContentType('basic', TRUE);
63 $this->adminUser = $this->drupalCreateUser($this->permissions);
64 $this->drupalPlaceBlock('local_actions_block');
68 * Creates a custom block.
70 * @param bool|string $title
71 * (optional) Title of block. When no value is given uses a random name.
73 * @param string $bundle
74 * (optional) Bundle name. Defaults to 'basic'.
76 * (optional) Whether to save the block. Defaults to TRUE.
78 * @return \Drupal\block_content\Entity\BlockContent
79 * Created custom block.
81 protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = TRUE) {
82 $title = $title ?: $this->randomMachineName();
83 $block_content = BlockContent::create([
88 if ($block_content && $save === TRUE) {
89 $block_content->save();
91 return $block_content;
95 * Creates a custom block type (bundle).
97 * @param string $label
98 * The block type label.
99 * @param bool $create_body
100 * Whether or not to create the body field
102 * @return \Drupal\block_content\Entity\BlockContentType
103 * Created custom block type.
105 protected function createBlockContentType($label, $create_body = FALSE) {
106 $bundle = BlockContentType::create([
113 block_content_add_body_field($bundle->id());