Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0
This commit is contained in:
parent
2f563ab520
commit
f1c8716f57
1732 changed files with 52334 additions and 11780 deletions
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_test\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
|
||||
/**
|
||||
* Provides a block with multiple forms.
|
||||
*
|
||||
* @Block(
|
||||
* id = "test_multiple_forms_block",
|
||||
* forms = {
|
||||
* "secondary" = "\Drupal\block_test\PluginForm\EmptyBlockForm"
|
||||
* },
|
||||
* admin_label = @Translation("Multiple forms test block")
|
||||
* )
|
||||
*/
|
||||
class TestMultipleFormsBlock extends BlockBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_test\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Provides a test settings validation block.
|
||||
*
|
||||
* @Block(
|
||||
* id = "test_settings_validation",
|
||||
* admin_label = @Translation("Test settings validation block"),
|
||||
* )
|
||||
*/
|
||||
class TestSettingsValidationBlock extends BlockBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockForm($form, FormStateInterface $form_state) {
|
||||
return ['digits' => ['#type' => 'textfield']] + $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockValidate($form, FormStateInterface $form_state) {
|
||||
if (!ctype_digit($form_state->getValue('digits'))) {
|
||||
$form_state->setErrorByName('digits', $this->t('Only digits are allowed'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
return ['#markup' => 'foo'];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_test\PluginForm;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\PluginFormBase;
|
||||
|
||||
/**
|
||||
* Provides a form for a block that is empty.
|
||||
*/
|
||||
class EmptyBlockForm extends PluginFormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
// Intentionally empty.
|
||||
}
|
||||
|
||||
}
|
|
@ -49,6 +49,7 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
|
|||
'd6_user_role',
|
||||
'd6_block',
|
||||
]);
|
||||
block_rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,18 +69,21 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
|
|||
* The block label.
|
||||
* @param string $label_display
|
||||
* The block label display setting.
|
||||
* @param bool $status
|
||||
* (optional) Whether the block is expected to be enabled.
|
||||
*/
|
||||
public function assertEntity($id, $visibility, $region, $theme, $weight, $label, $label_display) {
|
||||
public function assertEntity($id, $visibility, $region, $theme, $weight, $label, $label_display, $status = TRUE) {
|
||||
$block = Block::load($id);
|
||||
$this->assertTrue($block instanceof Block);
|
||||
$this->assertIdentical($visibility, $block->getVisibility());
|
||||
$this->assertIdentical($region, $block->getRegion());
|
||||
$this->assertIdentical($theme, $block->getTheme());
|
||||
$this->assertIdentical($weight, $block->getWeight());
|
||||
$this->assertSame($visibility, $block->getVisibility());
|
||||
$this->assertSame($region, $block->getRegion());
|
||||
$this->assertSame($theme, $block->getTheme());
|
||||
$this->assertSame($weight, $block->getWeight());
|
||||
$this->assertSame($status, $block->status());
|
||||
|
||||
$config = $this->config('block.block.' . $id);
|
||||
$this->assertIdentical($label, $config->get('settings.label'));
|
||||
$this->assertIdentical($label_display, $config->get('settings.label_display'));
|
||||
$this->assertSame($label, $config->get('settings.label'));
|
||||
$this->assertSame($label_display, $config->get('settings.label_display'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,7 +126,7 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
|
|||
$visibility['request_path']['id'] = 'request_path';
|
||||
$visibility['request_path']['negate'] = TRUE;
|
||||
$visibility['request_path']['pages'] = '/node/1';
|
||||
$this->assertEntity('system', $visibility, 'footer', 'bartik', -5, '', '0');
|
||||
$this->assertEntity('system', $visibility, 'footer_fifth', 'bartik', -5, '', '0');
|
||||
|
||||
// Check menu blocks
|
||||
$visibility = [];
|
||||
|
@ -137,7 +141,10 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
|
|||
$visibility['request_path']['id'] = 'request_path';
|
||||
$visibility['request_path']['negate'] = FALSE;
|
||||
$visibility['request_path']['pages'] = '/node';
|
||||
$this->assertEntity('block_1', $visibility, 'sidebar_second', 'bluemarine', -4, 'Another Static Block', 'visible');
|
||||
// bluemarine does not exist in Drupal 8 and the d6_block migration defines
|
||||
// no mapping for its regions, so this block should have been defaulted
|
||||
// to the 'content' region.
|
||||
$this->assertEntity('block_1', $visibility, 'content', 'bluemarine', -4, 'Another Static Block', 'visible');
|
||||
|
||||
$visibility = [];
|
||||
$this->assertEntity('block_2', $visibility, 'right', 'test_theme', -7, '', '0');
|
||||
|
|
|
@ -13,7 +13,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
|||
*/
|
||||
class MigrateBlockTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
|
@ -53,6 +53,7 @@ class MigrateBlockTest extends MigrateDrupal7TestBase {
|
|||
'd7_custom_block',
|
||||
'd7_block',
|
||||
]);
|
||||
block_rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,29 +77,32 @@ class MigrateBlockTest extends MigrateDrupal7TestBase {
|
|||
* The block label.
|
||||
* @param string $label_display
|
||||
* The block label display setting.
|
||||
* @param bool $status
|
||||
* (optional) Whether the block is expected to be enabled.
|
||||
*/
|
||||
public function assertEntity($id, $plugin_id, array $roles, $pages, $region, $theme, $weight, $label, $label_display) {
|
||||
public function assertEntity($id, $plugin_id, array $roles, $pages, $region, $theme, $weight, $label, $label_display, $status = TRUE) {
|
||||
$block = Block::load($id);
|
||||
$this->assertTrue($block instanceof Block);
|
||||
/** @var \Drupal\block\BlockInterface $block */
|
||||
$this->assertIdentical($plugin_id, $block->getPluginId());
|
||||
$this->assertSame($plugin_id, $block->getPluginId());
|
||||
|
||||
$visibility = $block->getVisibility();
|
||||
if ($roles) {
|
||||
$this->assertIdentical($roles, array_values($visibility['user_role']['roles']));
|
||||
$this->assertIdentical('@user.current_user_context:current_user', $visibility['user_role']['context_mapping']['user']);
|
||||
$this->assertSame($roles, array_values($visibility['user_role']['roles']));
|
||||
$this->assertSame('@user.current_user_context:current_user', $visibility['user_role']['context_mapping']['user']);
|
||||
}
|
||||
if ($pages) {
|
||||
$this->assertIdentical($pages, $visibility['request_path']['pages']);
|
||||
$this->assertSame($pages, $visibility['request_path']['pages']);
|
||||
}
|
||||
|
||||
$this->assertIdentical($region, $block->getRegion());
|
||||
$this->assertIdentical($theme, $block->getTheme());
|
||||
$this->assertIdentical($weight, $block->getWeight());
|
||||
$this->assertSame($region, $block->getRegion());
|
||||
$this->assertSame($theme, $block->getTheme());
|
||||
$this->assertSame($weight, $block->getWeight());
|
||||
$this->assertSame($status, $block->status());
|
||||
|
||||
$config = $this->config('block.block.' . $id);
|
||||
$this->assertIdentical($label, $config->get('settings.label'));
|
||||
$this->assertIdentical($label_display, $config->get('settings.label_display'));
|
||||
$this->assertSame($label, $config->get('settings.label'));
|
||||
$this->assertSame($label_display, $config->get('settings.label_display'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,7 +112,7 @@ class MigrateBlockTest extends MigrateDrupal7TestBase {
|
|||
$this->assertEntity('bartik_system_main', 'system_main_block', [], '', 'content', 'bartik', 0, '', '0');
|
||||
$this->assertEntity('bartik_search_form', 'search_form_block', [], '', 'sidebar_first', 'bartik', -1, '', '0');
|
||||
$this->assertEntity('bartik_user_login', 'user_login_block', [], '', 'sidebar_first', 'bartik', 0, '', '0');
|
||||
$this->assertEntity('bartik_system_powered_by', 'system_powered_by_block', [], '', 'footer', 'bartik', 10, '', '0');
|
||||
$this->assertEntity('bartik_system_powered_by', 'system_powered_by_block', [], '', 'footer_fifth', 'bartik', 10, '', '0');
|
||||
$this->assertEntity('seven_system_main', 'system_main_block', [], '', 'content', 'seven', 0, '', '0');
|
||||
$this->assertEntity('seven_user_login', 'user_login_block', [], '', 'content', 'seven', 10, '', '0');
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\block\Unit;
|
||||
|
||||
use Drupal\block\BlockForm;
|
||||
use Drupal\Core\Plugin\PluginFormFactoryInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
|
@ -54,6 +55,13 @@ class BlockFormTest extends UnitTestCase {
|
|||
*/
|
||||
protected $contextRepository;
|
||||
|
||||
/**
|
||||
* The plugin form manager.
|
||||
*
|
||||
* @var \Drupal\Core\Plugin\PluginFormFactoryInterface|\Prophecy\Prophecy\ProphecyInterface
|
||||
*/
|
||||
protected $pluginFormFactory;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -71,6 +79,7 @@ class BlockFormTest extends UnitTestCase {
|
|||
->method('getStorage')
|
||||
->will($this->returnValue($this->storage));
|
||||
|
||||
$this->pluginFormFactory = $this->prophesize(PluginFormFactoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,7 +108,7 @@ class BlockFormTest extends UnitTestCase {
|
|||
->method('getQuery')
|
||||
->will($this->returnValue($query));
|
||||
|
||||
$block_form_controller = new BlockForm($this->entityManager, $this->conditionManager, $this->contextRepository, $this->language, $this->themeHandler);
|
||||
$block_form_controller = new BlockForm($this->entityManager, $this->conditionManager, $this->contextRepository, $this->language, $this->themeHandler, $this->pluginFormFactory->reveal());
|
||||
|
||||
// Ensure that the block with just one other instance gets the next available
|
||||
// name suggestion.
|
||||
|
|
|
@ -18,7 +18,7 @@ class BlockRegionTest extends UnitTestCase {
|
|||
*
|
||||
* @param array $value
|
||||
* The value to transform.
|
||||
* @param \Drupal\migrate\Row|NULL $row
|
||||
* @param \Drupal\migrate\Row|null $row
|
||||
* (optional) The mocked row.
|
||||
*
|
||||
* @return array|string
|
||||
|
@ -30,14 +30,20 @@ class BlockRegionTest extends UnitTestCase {
|
|||
$row = $this->prophesize(Row::class)->reveal();
|
||||
}
|
||||
|
||||
$regions = array(
|
||||
'bartik' => array(
|
||||
'triptych_first' => 'Triptych first',
|
||||
'triptych_second' => 'Triptych second',
|
||||
'triptych_third' => 'Triptych third',
|
||||
),
|
||||
);
|
||||
$plugin = new BlockRegion(['region_map' => []], 'block_region', [], $regions);
|
||||
$configuration = [
|
||||
'map' => [
|
||||
'bartik' => [
|
||||
'bartik' => [
|
||||
'triptych_first' => 'triptych_first',
|
||||
'triptych_middle' => 'triptych_second',
|
||||
'triptych_last' => 'triptych_third',
|
||||
],
|
||||
],
|
||||
],
|
||||
'default_value' => 'content',
|
||||
];
|
||||
|
||||
$plugin = new BlockRegion($configuration, 'block_region', [], $configuration['map']['bartik']['bartik']);
|
||||
return $plugin->transform($value, $executable, $row, 'foo');
|
||||
}
|
||||
|
||||
|
@ -48,7 +54,7 @@ class BlockRegionTest extends UnitTestCase {
|
|||
* @covers ::transform
|
||||
*/
|
||||
public function testTransformSameThemeRegionExists() {
|
||||
$this->assertSame('triptych_second', $this->transform(['triptych_second', 'bartik', 'bartik']));
|
||||
$this->assertSame('triptych_second', $this->transform(['bartik', 'bartik', 'triptych_middle']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,7 +64,7 @@ class BlockRegionTest extends UnitTestCase {
|
|||
* @covers ::transform
|
||||
*/
|
||||
public function testTransformSameThemeRegionNotExists() {
|
||||
$this->assertSame('content', $this->transform(['footer', 'bartik', 'bartik']));
|
||||
$this->assertSame('content', $this->transform(['bartik', 'bartik', 'footer']));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue