Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -0,0 +1,37 @@
<?php
/**
* @file
* Contains \Drupal\block_test\Plugin\Condition\BaloneySpam.
*/
namespace Drupal\block_test\Plugin\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
/**
* Provides a 'baloney.spam' condition.
*
* @Condition(
* id = "baloney.spam",
* label = @Translation("Baloney spam"),
* )
*
*/
class BaloneySpam extends ConditionPluginBase {
/**
* {@inheritdoc}
*/
public function evaluate() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function summary() {
return 'Summary';
}
}

View file

@ -30,13 +30,6 @@ class BlockFormTest extends UnitTestCase {
*/
protected $storage;
/**
* The event dispatcher service.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $dispatcher;
/**
* The language manager service.
*
@ -59,6 +52,13 @@ class BlockFormTest extends UnitTestCase {
*/
protected $entityManager;
/**
* The mocked context repository.
*
* @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $contextRepository;
/**
* {@inheritdoc}
*/
@ -67,7 +67,7 @@ class BlockFormTest extends UnitTestCase {
$this->conditionManager = $this->getMock('Drupal\Core\Executable\ExecutableManagerInterface');
$this->language = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->contextRepository = $this->getMock('Drupal\Core\Plugin\Context\ContextRepositoryInterface');
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$this->storage = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityStorageInterface');
@ -104,7 +104,7 @@ class BlockFormTest extends UnitTestCase {
->method('getQuery')
->will($this->returnValue($query));
$block_form_controller = new BlockForm($this->entityManager, $this->conditionManager, $this->dispatcher, $this->language, $this->themeHandler);
$block_form_controller = new BlockForm($this->entityManager, $this->conditionManager, $this->contextRepository, $this->language, $this->themeHandler);
// Ensure that the block with just one other instance gets the next available
// name suggestion.

View file

@ -8,6 +8,7 @@
namespace Drupal\Tests\block\Unit;
use Drupal\block\BlockRepository;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Plugin\ContextAwarePluginInterface;
use Drupal\Tests\UnitTestCase;
@ -59,7 +60,7 @@ class BlockRepositoryTest extends UnitTestCase {
]);
$theme_manager = $this->getMock('Drupal\Core\Theme\ThemeManagerInterface');
$theme_manager->expects($this->once())
$theme_manager->expects($this->atLeastOnce())
->method('getActiveTheme')
->will($this->returnValue($active_theme));
@ -84,15 +85,18 @@ class BlockRepositoryTest extends UnitTestCase {
$blocks = [];
foreach ($blocks_config as $block_id => $block_config) {
$block = $this->getMock('Drupal\block\BlockInterface');
$block->expects($this->once())
->method('setContexts')
->willReturnSelf();
$block->expects($this->once())
->method('access')
->will($this->returnValue($block_config[0]));
$block->expects($block_config[0] ? $this->atLeastOnce() : $this->never())
->method('getRegion')
->willReturn($block_config[1]);
$block->expects($this->any())
->method('label')
->willReturn($block_id);
$block->expects($this->any())
->method('getWeight')
->willReturn($block_config[2]);
$blocks[$block_id] = $block;
}
@ -101,30 +105,34 @@ class BlockRepositoryTest extends UnitTestCase {
->with(['theme' => $this->theme])
->willReturn($blocks);
$result = [];
foreach ($this->blockRepository->getVisibleBlocksPerRegion([]) as $region => $resulting_blocks) {
$cacheable_metadata = [];
foreach ($this->blockRepository->getVisibleBlocksPerRegion($cacheable_metadata) as $region => $resulting_blocks) {
$result[$region] = [];
foreach ($resulting_blocks as $plugin_id => $block) {
$result[$region][] = $plugin_id;
}
}
$this->assertSame($result, $expected_blocks);
$this->assertEquals($expected_blocks, $result);
}
public function providerBlocksConfig() {
$blocks_config = array(
'block1' => array(
TRUE, 'top', 0
AccessResult::allowed(), 'top', 0
),
// Test a block without access.
'block2' => array(
FALSE, 'bottom', 0
),
// Test two blocks in the same region with specific weight.
'block3' => array(
TRUE, 'bottom', 5
AccessResult::forbidden(), 'bottom', 0
),
// Test some blocks in the same region with specific weight.
'block4' => array(
TRUE, 'bottom', -5
AccessResult::allowed(), 'bottom', 5
),
'block3' => array(
AccessResult::allowed(), 'bottom', 5
),
'block5' => array(
AccessResult::allowed(), 'bottom', -5
),
);
@ -133,7 +141,7 @@ class BlockRepositoryTest extends UnitTestCase {
[
'top' => ['block1'],
'center' => [],
'bottom' => ['block4', 'block3'],
'bottom' => ['block5', 'block3', 'block4'],
]
];
return $test_cases;
@ -146,24 +154,21 @@ class BlockRepositoryTest extends UnitTestCase {
*/
public function testGetVisibleBlocksPerRegionWithContext() {
$block = $this->getMock('Drupal\block\BlockInterface');
$block->expects($this->once())
->method('setContexts')
->willReturnSelf();
$block->expects($this->once())
->method('access')
->willReturn(TRUE);
->willReturn(AccessResult::allowed()->addCacheTags(['config:block.block.block_id']));
$block->expects($this->once())
->method('getRegion')
->willReturn('top');
$blocks['block_id'] = $block;
$contexts = [];
$this->blockStorage->expects($this->once())
->method('loadByProperties')
->with(['theme' => $this->theme])
->willReturn($blocks);
$result = [];
foreach ($this->blockRepository->getVisibleBlocksPerRegion($contexts) as $region => $resulting_blocks) {
$cacheable_metadata = [];
foreach ($this->blockRepository->getVisibleBlocksPerRegion($cacheable_metadata) as $region => $resulting_blocks) {
$result[$region] = [];
foreach ($resulting_blocks as $plugin_id => $block) {
$result[$region][] = $plugin_id;
@ -177,6 +182,10 @@ class BlockRepositoryTest extends UnitTestCase {
'bottom' => [],
];
$this->assertSame($expected, $result);
// Assert that the cacheable metadata from the block access results was
// collected.
$this->assertEquals(['config:block.block.block_id'], $cacheable_metadata['top']->getCacheTags());
}
}

View file

@ -7,6 +7,8 @@
namespace Drupal\Tests\block\Unit\Plugin\DisplayVariant;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\DependencyInjection\Container;
use Drupal\Tests\UnitTestCase;
/**
@ -29,13 +31,6 @@ class BlockPageVariantTest extends UnitTestCase {
*/
protected $blockViewBuilder;
/**
* The event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $dispatcher;
/**
* The plugin context handler.
*
@ -55,14 +50,23 @@ class BlockPageVariantTest extends UnitTestCase {
* A mocked display variant plugin.
*/
public function setUpDisplayVariant($configuration = array(), $definition = array()) {
$container = new Container();
$cache_context_manager = $this->getMockBuilder('Drupal\Core\Cache\CacheContextsManager')
->disableOriginalConstructor()
->getMock();
$container->set('cache_contexts_manager', $cache_context_manager);
$cache_context_manager->expects($this->any())
->method('validateTokens')
->with([])
->willReturn([]);
\Drupal::setContainer($container);
$this->blockRepository = $this->getMock('Drupal\block\BlockRepositoryInterface');
$this->blockViewBuilder = $this->getMock('Drupal\Core\Entity\EntityViewBuilderInterface');
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->dispatcher->expects($this->any())
->method('dispatch')
->willReturnArgument(1);
return $this->getMockBuilder('Drupal\block\Plugin\DisplayVariant\BlockPageVariant')
->setConstructorArgs(array($configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, $this->dispatcher, ['config:block_list']))
->setConstructorArgs(array($configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, ['config:block_list']))
->setMethods(array('getRegionNames'))
->getMock();
}
@ -96,7 +100,10 @@ class BlockPageVariantTest extends UnitTestCase {
'#cache' => [
'tags' => [
'config:block_list',
'route',
],
'contexts' => [],
'max-age' => -1,
],
'top' => [
'block1' => [],
@ -121,7 +128,10 @@ class BlockPageVariantTest extends UnitTestCase {
'#cache' => [
'tags' => [
'config:block_list',
'route',
],
'contexts' => [],
'max-age' => -1,
],
'top' => [
'block1' => [],
@ -152,7 +162,10 @@ class BlockPageVariantTest extends UnitTestCase {
'#cache' => [
'tags' => [
'config:block_list',
'route',
],
'contexts' => [],
'max-age' => -1,
],
'top' => [
'block1' => [],
@ -194,20 +207,26 @@ class BlockPageVariantTest extends UnitTestCase {
$messages_block_plugin = $this->getMock('Drupal\Core\Block\MessagesBlockPluginInterface');
foreach ($blocks_config as $block_id => $block_config) {
$block = $this->getMock('Drupal\block\BlockInterface');
$block->expects($this->any())
->method('getContexts')
->willReturn([]);
$block->expects($this->atLeastOnce())
->method('getPlugin')
->willReturn($block_config[1] ? $main_content_block_plugin : ($block_config[2] ? $messages_block_plugin : $block_plugin));
$blocks[$block_config[0]][$block_id] = $block;
}
$this->blockViewBuilder->expects($this->exactly($visible_block_count))
->method('view')
->will($this->returnValue(array()));
$this->blockRepository->expects($this->once())
->method('getVisibleBlocksPerRegion')
->will($this->returnValue($blocks));
->willReturnCallback(function (&$cacheable_metadata) use ($blocks) {
$cacheable_metadata['top'] = (new CacheableMetadata())->addCacheTags(['route']);
return $blocks;
});
$this->assertSame($expected_render_array, $display_variant->build());
$value = $display_variant->build();
$this->assertSame($expected_render_array, $value);
}
/**
@ -226,6 +245,8 @@ class BlockPageVariantTest extends UnitTestCase {
'tags' => [
'config:block_list',
],
'contexts' => [],
'max-age' => -1,
],
'content' => [
'system_main' => [],

View file

@ -0,0 +1,86 @@
<?php
/**
* @file
* Contains \Drupal\Tests\block\Unit\Plugin\migrate\source\d6\BlockTest.
*/
namespace Drupal\Tests\block\Unit\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D6 block source plugin.
*
* @coversDefaultClass \Drupal\block\Plugin\migrate\source\d6\Block
* @group block
*/
class BlockTest extends MigrateSqlSourceTestCase {
// The plugin system is not working during unit testing so the source plugin
// class needs to be manually specified.
const PLUGIN_CLASS = 'Drupal\block\Plugin\migrate\source\d6\Block';
// The fake Migration configuration entity.
protected $migrationConfiguration = array(
// The ID of the entity, can be any string.
'id' => 'test',
'idlist' => array(),
'source' => array(
'plugin' => 'd6_block',
),
);
/**
* Sample block instance query results from the source.
*/
protected $expectedResults = array(
array(
'bid' => 1,
'module' => 'block',
'delta' => '1',
'theme' => 'garland',
'status' => 1,
'weight' => 0,
'region' => 'left',
'visibility' => 0,
'pages' => '',
'title' => 'Test Title 01',
'cache' => -1,
),
array(
'bid' => 2,
'module' => 'block',
'delta' => '2',
'theme' => 'garland',
'status' => 1,
'weight' => 5,
'region' => 'right',
'visibility' => 0,
'pages' => '<front>',
'title' => 'Test Title 02',
'cache' => -1,
),
);
/**
* Sample block roles table.
*/
protected $expectedBlocksRoles = array(
array(
'module' => 'block',
'delta' => 1,
'rid' => 2,
),
);
/**
* Prepopulate database contents.
*/
protected function setUp() {
$this->databaseContents['blocks'] = $this->expectedResults;
$this->databaseContents['blocks_roles'] = $this->expectedBlocksRoles;
parent::setUp();
}
}