/** * Tests creating a block type programmatically and via a form. */ public function testBlockContentTypeCreation() { // Login a test user. $this->drupalLogin($this->adminUser); // Test the page with no block-types. $this->drupalGet('block/add'); $this->assertResponse(200); $this->assertText('You have not created any block types yet'); $this->clickLink('block type creation page'); // Create a block type via the user interface. $edit = array('id' => 'foo', 'label' => 'title for foo'); $this->drupalPostForm(NULL, $edit, t('Save')); $block_type = BlockContentType::load('foo'); $this->assertTrue($block_type, 'The new block type has been created.'); $field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'foo'); $this->assertTrue(isset($field_definitions['body']), 'Body field created when using the UI to create block content types.'); // Check that the block type was created in site default language. $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); $this->assertEqual($block_type->language()->getId(), $default_langcode); // Create block types programmatically. $this->createBlockContentType('basic', TRUE); $field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'basic'); $this->assertTrue(isset($field_definitions['body']), "Body field for 'basic' block type created when using the testing API to create block content types."); $this->createBlockContentType('other'); $field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other'); $this->assertFalse(isset($field_definitions['body']), "Body field for 'other' block type not created when using the testing API to create block content types."); $block_type = BlockContentType::load('other'); $this->assertTrue($block_type, 'The new block type has been created.'); $this->drupalGet('block/add/' . $block_type->id()); $this->assertResponse(200); }
/** * Tests creating a block type programmatically and via a form. */ public function testBlockContentTypeCreation() { // Login a test user. $this->drupalLogin($this->adminUser); // Test the page with no block-types. $this->drupalGet('block/add'); $this->assertResponse(200); $this->assertRaw(t('You have not created any block types yet. Go to the <a href="!url">block type creation page</a> to add a new block type.', ['!url' => Url::fromRoute('block_content.type_add')->toString()])); // Now create an initial block-type. $this->createBlockContentType('basic', TRUE); // Create a block type programmatically. $type = $this->createBlockContentType('other'); $block_type = BlockContentType::load('other'); $this->assertTrue($block_type, 'The new block type has been created.'); $this->drupalGet('block/add/' . $type->id()); $this->assertResponse(200, 'The new block type can be accessed at block/add.'); // Create a block type via the user interface. $edit = array('id' => 'foo', 'label' => 'title for foo'); $this->drupalPostForm('admin/structure/block/block-content/types/add', $edit, t('Save')); $block_type = BlockContentType::load('foo'); $this->assertTrue($block_type, 'The new block type has been created.'); $field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'foo'); $this->assertTrue(isset($field_definitions['body']), 'Body field was created when using the UI to create block content types.'); // Check that the block type was created in site default language. $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); $this->assertEqual($block_type->language()->getId(), $default_langcode); }
/** * Tests the block content type migration. */ public function testBlockContentTypeMigration() { /** @var \Drupal\block_content\BlockContentTypeInterface $entity */ $entity = BlockContentType::load('basic'); $this->assertTrue($entity instanceof BlockContentTypeInterface); $this->assertIdentical('Basic', $entity->label()); }
/** * Creates a custom block type (bundle). * * @param array $values * An array of settings to change from the defaults. * * @return \Drupal\block_content\Entity\BlockContentType * Created custom block type. */ protected function createBlockContentType(array $values = array()) { // Find a non-existent random type name. if (!isset($values['id'])) { do { $id = strtolower($this->randomMachineName(8)); } while (BlockContentType::load($id)); } else { $id = $values['id']; } $values += array('id' => $id, 'label' => $id, 'revision' => FALSE); $bundle = BlockContentType::create($values); $status = $bundle->save(); block_content_add_body_field($bundle->id()); $this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created block content type %bundle.', array('%bundle' => $bundle->id()))); return $bundle; }
/** * {@inheritdoc} */ protected function entityFormTitle(EntityInterface $entity) { $block_type = BlockContentType::load($entity->bundle()); return t('<em>Edit @type</em> @title', array('@type' => $block_type->label(), '@title' => $entity->label())); }