/**
  * {@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());
 }
Ejemplo n.º 2
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>');
 }
Ejemplo n.º 3
0
 /**
  * {@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;
 }
Ejemplo n.º 4
0
 /**
  * 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());
 }
Ejemplo n.º 5
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 = 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;
 }
 /**
  * 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));
 }
Ejemplo n.º 7
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");
 }
Ejemplo n.º 8
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;
 }
 /**
  * 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');
 }
Ejemplo n.º 12
0
  /**
   * 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)),
    ]));

  }
Ejemplo n.º 13
0
 protected function setUp()
 {
     parent::setUp();
     BlockContentType::create(array('id' => 'basic', 'label' => 'basic', 'revision' => TRUE));
     ViewTestData::createTestViews(get_class($this), array('block_content_test_views'));
 }
Ejemplo n.º 14
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>');
 }