/**
  * 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());
 }
示例#2
0
 /**
  * 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);
 }
示例#3
0
 /**
  * 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);
 }
示例#4
0
 /**
  * Tests XSS coming from Block Content block info.
  */
 protected function doBlockContentTest()
 {
     BlockContentType::create(['id' => 'basic', 'label' => 'basic', 'revision' => TRUE])->save();
     BlockContent::create(['type' => 'basic', 'info' => '<script>alert("block_content");</script>'])->save();
     $this->drupalGet(Url::fromRoute('block.admin_display'));
     $this->clickLink('<script>alert("block_content");</script>');
     $this->assertRaw('&lt;script&gt;alert(&quot;block_content&quot;);&lt;/script&gt;');
     $this->assertNoRaw('<script>alert("block_content");</script>');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create the "basic" block type.
     $bundle = BlockContentType::create(['id' => 'basic', 'label' => 'basic', 'revision' => FALSE]);
     $bundle->save();
     // Add the body field to it.
     block_content_add_body_field($bundle->id());
 }
 /**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     $block_content_type = BlockContentType::create(array('id' => 'basic', 'label' => 'basic', 'revision' => FALSE));
     $block_content_type->save();
     block_content_add_body_field($block_content_type->id());
     // Create a "Llama" custom block.
     $block_content = BlockContent::create(array('info' => 'Llama', 'type' => 'basic', 'body' => array('value' => 'The name "llama" was adopted by European settlers from native Peruvians.', 'format' => 'plain_text')));
     $block_content->save();
     return $block_content;
 }
 /**
  * Tests workbench moderation third party schema for block content types.
  */
 public function testWorkbenchModerationBlockContentTypeConfig()
 {
     $this->installEntitySchema('block_content');
     $this->installEntitySchema('user');
     $this->installConfig(['workbench_moderation']);
     $typed_config = \Drupal::service('config.typed');
     $moderation_states = ModerationState::loadMultiple();
     $block_content_type = BlockContentType::create(['id' => 'basic', 'label' => 'basic', 'revision' => TRUE]);
     $block_content_type->setThirdPartySetting('workbench_moderation', 'enabled', TRUE);
     $block_content_type->setThirdPartySetting('workbench_moderation', 'allowed_moderation_states', array_keys($moderation_states));
     $block_content_type->setThirdPartySetting('workbench_moderation', 'default_moderation_state', '');
     $block_content_type->save();
     $this->assertConfigSchema($typed_config, $block_content_type->getEntityType()->getConfigPrefix() . '.' . $block_content_type->id(), $block_content_type->toArray());
 }
示例#8
0
 /**
  * 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 = entity_create('block_content_type', $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;
 }
 /**
  * Tests deleting a block_content updates the discovered block plugin.
  */
 public function testDeletingBlockContentShouldClearPluginCache()
 {
     // Create a block content type.
     $block_content_type = BlockContentType::create(['id' => 'spiffy', 'label' => 'Mucho spiffy', 'description' => "Provides a block type that increases your site's spiffiness by upto 11%"]);
     $block_content_type->save();
     // And a block content entity.
     $block_content = BlockContent::create(['info' => 'Spiffy prototype', 'type' => 'spiffy']);
     $block_content->save();
     // Make sure the block content provides a derivative block plugin in the
     // block repository.
     /** @var \Drupal\Core\Block\BlockManagerInterface $block_manager */
     $block_manager = $this->container->get('plugin.manager.block');
     $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid();
     $this->assertTrue($block_manager->hasDefinition($plugin_id));
     // Now delete the block content entity.
     $block_content->delete();
     // The plugin should no longer exist.
     $this->assertFalse($block_manager->hasDefinition($plugin_id));
 }
示例#10
0
 public function testBlockTitleTokens()
 {
     $label = 'tokenblock';
     $bundle = BlockContentType::create(array('id' => $label, 'label' => $label, 'revision' => FALSE));
     $bundle->save();
     $block_content = BlockContent::create(array('type' => $label, 'label' => '[current-page:title] block title', 'info' => 'Test token title block', 'body[value]' => 'This is the test token title block.'));
     $block_content->save();
     $block = $this->drupalPlaceBlock('block_content:' . $block_content->uuid(), array('label' => '[user:name]'));
     $this->drupalGet($block->getSystemPath());
     $this->drupalPostForm(NULL, array(), t('Save block'));
     // Ensure token validation is working on the block.
     $this->assertText('The Title is using the following invalid tokens: [user:name].');
     // Create the block for real now with a valid title.
     $settings = $block->get('settings');
     $settings['label'] = '[current-page:title] block title';
     $block->set('settings', $settings);
     $block->save();
     // Ensure that tokens are not double-escaped when output as a block title.
     $this->drupalCreateContentType(array('type' => 'page'));
     $node = $this->drupalCreateNode(array('title' => "Site's first node"));
     $this->drupalGet('node/' . $node->id());
     // The apostraphe should only be escaped once.
     $this->assertRaw("Site&#039;s first node block title");
 }
 /**
  * {@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()));
 }
示例#12
0
 /**
  * Creates a custom block type (bundle).
  *
  * @param string $label
  *   The block type label.
  * @param bool $create_body
  *   Whether or not to create the body field
  *
  * @return \Drupal\block_content\Entity\BlockContentType
  *   Created custom block type.
  */
 protected function createBlockContentType($label, $create_body = FALSE)
 {
     $bundle = BlockContentType::create(array('id' => $label, 'label' => $label, 'revision' => FALSE));
     $bundle->save();
     if ($create_body) {
         block_content_add_body_field($bundle->id());
     }
     return $bundle;
 }
示例#13
0
 /**
  * Tests XSS coming from Block Content block info.
  */
 protected function doBlockContentTest()
 {
     BlockContentType::create(['id' => 'basic', 'label' => 'basic', 'revision' => TRUE])->save();
     BlockContent::create(['type' => 'basic', 'info' => '<script>alert("block_content");</script>'])->save();
     $this->drupalGet(Url::fromRoute('block.admin_display'));
     $this->clickLinkPartialName('Place block');
     $this->assertEscaped('<script>alert("block_content");</script>');
     $this->assertNoRaw('<script>alert("block_content");</script>');
 }
 /**
  * Tests the field listing for the translate operation.
  */
 public function doFieldListTest()
 {
     // Create a base content type.
     $content_type = $this->drupalCreateContentType(array('type' => Unicode::strtolower($this->randomMachineName(16)), 'name' => $this->randomMachineName()));
     // Create a block content type.
     $block_content_type = BlockContentType::create(array('id' => 'basic', 'label' => 'Basic', 'revision' => FALSE));
     $block_content_type->save();
     $field = FieldConfig::create(['field_storage' => FieldStorageConfig::loadByName('block_content', 'body'), 'bundle' => $block_content_type->id(), 'label' => 'Body', 'settings' => array('display_summary' => FALSE)]);
     $field->save();
     // Look at a few fields on a few entity types.
     $pages = array(array('list' => 'admin/structure/types/manage/' . $content_type->id() . '/fields', 'field' => 'node.' . $content_type->id() . '.body'), array('list' => 'admin/structure/block/block-content/manage/basic/fields', 'field' => 'block_content.basic.body'));
     foreach ($pages as $values) {
         // Get fields listing.
         $this->drupalGet($values['list']);
         $translate_link = $values['list'] . '/' . $values['field'] . '/translate';
         // Test if the link to translate the field is on the page.
         $this->assertLinkByHref($translate_link);
         // Test if the link to translate actually goes to the translate page.
         $this->drupalGet($translate_link);
         $this->assertRaw('<th>' . t('Language') . '</th>');
     }
 }
 /**
  * Test that no metadata is stored for a disabled bundle.
  */
 public function testDisabledBundle()
 {
     // Create a bundle that does not have translation enabled.
     $disabled_bundle = $this->randomMachineName();
     $bundle = BlockContentType::create(array('id' => $disabled_bundle, 'label' => $disabled_bundle, 'revision' => FALSE));
     $bundle->save();
     // Create a block content for each bundle.
     $enabled_block_content = $this->createBlockContent();
     $disabled_block_content = $this->createBlockContent(FALSE, $bundle->id());
     // Make sure that only a single row was inserted into the block table.
     $rows = db_query('SELECT * FROM {block_content_field_data} WHERE id = :id', array(':id' => $enabled_block_content->id()))->fetchAll();
     $this->assertEqual(1, count($rows));
 }
 /**
  * Tests creation of block content stubs when there is a block_content_type.
  */
 public function testStubSuccess()
 {
     BlockContentType::create(['id' => 'test_block_content_type', 'label' => 'Test block content type'])->save();
     $this->performStubTest('block_content');
 }
  /**
   * Tests that the "add to shortcut" and "remove from shortcut" links work.
   */
  public function testShortcutQuickLink() {
    \Drupal::service('theme_handler')->install(array('seven'));
    $this->config('system.theme')->set('admin', 'seven')->save();
    $this->config('node.settings')->set('use_admin_theme', '1')->save();
    $this->container->get('router.builder')->rebuild();

    $this->drupalLogin($this->rootUser);
    $this->drupalGet('admin/config/system/cron');

    // Test the "Add to shortcuts" link.
    $this->clickLink('Add to Default shortcuts');
    $this->assertText('Added a shortcut for Cron.');
    $this->assertLink('Cron', 0, 'Shortcut link found on page');

    $this->drupalGet('admin/structure');
    $this->assertLink('Cron', 0, 'Shortcut link found on different page');

    // Test the "Remove from shortcuts" link.
    $this->clickLink('Cron');
    $this->clickLink('Remove from Default shortcuts');
    $this->assertText('The shortcut Cron has been deleted.');
    $this->assertNoLink('Cron', 'Shortcut link removed from page');

    $this->drupalGet('admin/structure');
    $this->assertNoLink('Cron', 'Shortcut link removed from different page');

    $this->drupalGet('admin/people');

    // Test the "Add to shortcuts" link for a page generated by views.
    $this->clickLink('Add to Default shortcuts');
    $this->assertText('Added a shortcut for People.');
    $this->assertShortcutQuickLink('Remove from Default shortcuts');

    // Test the "Remove from  shortcuts" link for a page generated by views.
    $this->clickLink('Remove from Default shortcuts');
    $this->assertText('The shortcut People has been deleted.');
    $this->assertShortcutQuickLink('Add to Default shortcuts');

    // Test two pages which use same route name but different route parameters.
    $this->drupalGet('node/add/page');
    // Add Shortcut for Basic Page.
    $this->clickLink('Add to Default shortcuts');
    $this->assertText('Added a shortcut for Create Basic page.');
    // Assure that Article does not have its shortcut indicated as set.
    $this->drupalGet('node/add/article');
    $link = $this->xpath('//a[normalize-space()=:label]', array(':label' => 'Remove from Default shortcuts'));
    $this->assertTrue(empty($link), 'Link Remove to Default shortcuts not found for Create Article page.');
    // Add Shortcut for Article.
    $this->clickLink('Add to Default shortcuts');
    $this->assertText('Added a shortcut for Create Article.');

    $this->config('system.theme')->set('default', 'seven')->save();
    $this->drupalGet('node/' . $this->node->id());
    $title = $this->node->getTitle();

    // Test the "Add to shortcuts" link for node view route.
    $this->clickLink('Add to Default shortcuts');
    $this->assertText(new FormattableMarkup('Added a shortcut for @title.', ['@title' => $title]));
    $this->assertShortcutQuickLink('Remove from Default shortcuts');

    // Test the "Remove from shortcuts" link for node view route.
    $this->clickLink('Remove from Default shortcuts');
    $this->assertText(new FormattableMarkup('The shortcut @title has been deleted.', ['@title' => $title]));
    $this->assertShortcutQuickLink('Add to Default shortcuts');

    \Drupal::service('module_installer')->install(['block_content']);
    BlockContentType::create(array(
      'id' => 'basic',
      'label' => 'Basic block',
      'revision' => FALSE,
    ))->save();
    // Test page with HTML tags in title.
    $this->drupalGet('admin/structure/block/block-content/manage/basic');
    $page_title = new FormattableMarkup('Edit %label custom block type', ['%label' => 'Basic block']);
    $this->assertRaw($page_title);
    // Add shortcut to this page.
    $this->clickLink('Add to Default shortcuts');
    $this->assertRaw(new FormattableMarkup('Added a shortcut for %title.', [
      '%title' => trim(strip_tags($page_title)),
    ]));

  }
 protected function setUp()
 {
     parent::setUp();
     BlockContentType::create(array('id' => 'basic', 'label' => 'basic', 'revision' => TRUE));
     ViewTestData::createTestViews(get_class($this), array('block_content_test_views'));
 }