Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -0,0 +1,6 @@
services:
block_test.multiple_static_context:
class: Drupal\block_test\ContextProvider\MultipleStaticContext
arguments: ['@current_user', '@entity.manager']
tags:
- { name: 'context_provider' }

View file

@ -0,0 +1,78 @@
<?php
/**
* @file
* Contains \Drupal\block_test\ContextProvider\MultipleStaticContext.
*/
namespace Drupal\block_test\ContextProvider;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\ContextProviderInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Sets multiple contexts for a static value.
*/
class MultipleStaticContext implements ContextProviderInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* The user storage.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/**
* Constructs a new MultipleStaticContext.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(AccountInterface $account, EntityManagerInterface $entity_manager) {
$this->account = $account;
$this->userStorage = $entity_manager->getStorage('user');
}
/**
* {@inheritdoc}
*/
public function getRuntimeContexts(array $unqualified_context_ids) {
$current_user = $this->userStorage->load($this->account->id());
$context1 = new Context(new ContextDefinition('entity:user', 'User 1'), $current_user);
$context2 = new Context(new ContextDefinition('entity:user', 'User 2'), $current_user);
$cacheability = new CacheableMetadata();
$cacheability->setCacheContexts(['user']);
$context1->addCacheableDependency($cacheability);
$context2->addCacheableDependency($cacheability);
return [
'user1' => $context1,
'user2' => $context2,
];
}
/**
* {@inheritdoc}
*/
public function getAvailableContexts() {
return $this->getRuntimeContexts([]);
}
}

View file

@ -63,7 +63,7 @@ class TestAccessBlock extends BlockBase implements ContainerFactoryPluginInterfa
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
return $this->state->get('test_block_access', FALSE) ? AccessResult::allowed() : AccessResult::forbidden();
return $this->state->get('test_block_access', FALSE) ? AccessResult::allowed()->setCacheMaxAge(0) : AccessResult::forbidden()->setCacheMaxAge(0);
}
/**

View file

@ -8,6 +8,7 @@
namespace Drupal\block_test\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
/**
* Provides a block to test caching.
@ -39,4 +40,11 @@ class TestCacheBlock extends BlockBase {
return \Drupal::state()->get('block_test.cache_contexts', []);
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return \Drupal::state()->get('block_test.cache_max_age', parent::getCacheMaxAge());
}
}

View file

@ -29,6 +29,8 @@ class TestContextAwareBlock extends BlockBase {
/** @var $user \Drupal\user\UserInterface */
$user = $this->getContextValue('user');
return array(
'#prefix' => '<div id="' . $this->getPluginId() . '--username">',
'#suffix' => '</div>',
'#markup' => $user->getUsername(),
);
}

View file

@ -0,0 +1,34 @@
<?php
/**
* @file
* Contains \Drupal\block_test\Plugin\Block\TestContextAwareBlock.
*/
namespace Drupal\block_test\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a context-aware block.
*
* @Block(
* id = "test_context_aware_unsatisfied",
* admin_label = @Translation("Test context-aware unsatisfied block"),
* context = {
* "user" = @ContextDefinition("entity:foobar")
* }
* )
*/
class TestContextAwareUnsatisfiedBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
return [
'#markup' => 'test',
];
}
}

View file

@ -100,7 +100,7 @@ class BlockConfigEntityUnitTest extends UnitTestCase {
->method('getPluginCollections')
->will($this->returnValue(array($plugin_collection)));
$dependencies = $entity->calculateDependencies();
$dependencies = $entity->calculateDependencies()->getDependencies();
$this->assertContains('test', $dependencies['module']);
$this->assertContains('stark', $dependencies['theme']);
}

View file

@ -7,8 +7,8 @@
namespace Drupal\Tests\block\Unit;
use Drupal\Component\Utility\Html;
use Drupal\block\Controller\CategoryAutocompleteController;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
@ -48,7 +48,7 @@ class CategoryAutocompleteTest extends UnitTestCase {
*/
public function testAutocompleteSuggestions($string, $suggestions) {
$suggestions = array_map(function ($suggestion) {
return array('value' => $suggestion, 'label' => SafeMarkup::checkPlain($suggestion));
return array('value' => $suggestion, 'label' => Html::escape($suggestion));
}, $suggestions);
$result = $this->autocompleteController->autocomplete(new Request(array('q' => $string)));
$this->assertSame($suggestions, json_decode($result->getContent(), TRUE));

View file

@ -57,9 +57,8 @@ class BlockPageVariantTest extends UnitTestCase {
->getMock();
$container->set('cache_contexts_manager', $cache_context_manager);
$cache_context_manager->expects($this->any())
->method('validateTokens')
->with([])
->willReturn([]);
->method('assertValidTokens')
->willReturn(TRUE);
\Drupal::setContainer($container);
$this->blockRepository = $this->getMock('Drupal\block\BlockRepositoryInterface');
@ -74,28 +73,32 @@ class BlockPageVariantTest extends UnitTestCase {
public function providerBuild() {
$blocks_config = array(
'block1' => array(
// region, is main content block, is messages block
'top', FALSE, FALSE,
// region, is main content block, is messages block, is title block
'top', FALSE, FALSE, FALSE,
),
// Test multiple blocks in the same region.
'block2' => array(
'bottom', FALSE, FALSE,
'bottom', FALSE, FALSE, FALSE,
),
'block3' => array(
'bottom', FALSE, FALSE,
'bottom', FALSE, FALSE, FALSE,
),
// Test a block implementing MainContentBlockPluginInterface.
'block4' => array(
'center', TRUE, FALSE,
'center', TRUE, FALSE, FALSE,
),
// Test a block implementing MessagesBlockPluginInterface.
'block5' => array(
'center', FALSE, TRUE,
'center', FALSE, TRUE, FALSE,
),
// Test a block implementing TitleBlockPluginInterface.
'block6' => array(
'center', FALSE, FALSE, TRUE,
),
);
$test_cases = [];
$test_cases[] = [$blocks_config, 5,
$test_cases[] = [$blocks_config, 6,
[
'#cache' => [
'tags' => [
@ -113,6 +116,7 @@ class BlockPageVariantTest extends UnitTestCase {
'center' => [
'block4' => [],
'block5' => [],
'block6' => [],
'#sorted' => TRUE,
],
'bottom' => [
@ -123,7 +127,7 @@ class BlockPageVariantTest extends UnitTestCase {
],
];
unset($blocks_config['block5']);
$test_cases[] = [$blocks_config, 4,
$test_cases[] = [$blocks_config, 5,
[
'#cache' => [
'tags' => [
@ -139,6 +143,7 @@ class BlockPageVariantTest extends UnitTestCase {
],
'center' => [
'block4' => [],
'block6' => [],
'#sorted' => TRUE,
],
'bottom' => [
@ -157,6 +162,7 @@ class BlockPageVariantTest extends UnitTestCase {
],
];
unset($blocks_config['block4']);
unset($blocks_config['block6']);
$test_cases[] = [$blocks_config, 3,
[
'#cache' => [
@ -205,6 +211,7 @@ class BlockPageVariantTest extends UnitTestCase {
$block_plugin = $this->getMock('Drupal\Core\Block\BlockPluginInterface');
$main_content_block_plugin = $this->getMock('Drupal\Core\Block\MainContentBlockPluginInterface');
$messages_block_plugin = $this->getMock('Drupal\Core\Block\MessagesBlockPluginInterface');
$title_block_plugin = $this->getMock('Drupal\Core\Block\TitleBlockPluginInterface');
foreach ($blocks_config as $block_id => $block_config) {
$block = $this->getMock('Drupal\block\BlockInterface');
$block->expects($this->any())
@ -212,7 +219,7 @@ class BlockPageVariantTest extends UnitTestCase {
->willReturn([]);
$block->expects($this->atLeastOnce())
->method('getPlugin')
->willReturn($block_config[1] ? $main_content_block_plugin : ($block_config[2] ? $messages_block_plugin : $block_plugin));
->willReturn($block_config[1] ? $main_content_block_plugin : ($block_config[2] ? $messages_block_plugin : ($block_config[3] ? $title_block_plugin : $block_plugin)));
$blocks[$block_config[0]][$block_id] = $block;
}
$this->blockViewBuilder->expects($this->exactly($visible_block_count))

View file

@ -0,0 +1,69 @@
<?php
/**
* @file
* Contains \Drupal\Tests\block\Unit\Plugin\migrate\process\BlockRegionTest.
*/
namespace Drupal\Tests\block\Unit\Plugin\migrate\process;
use Drupal\block\Plugin\migrate\process\BlockRegion;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\block\Plugin\migrate\process\BlockRegion
* @group block
*/
class BlockRegionTest extends UnitTestCase {
/**
* Transforms a value through the block_region plugin.
*
* @param array $value
* The value to transform.
* @param \Drupal\migrate\Row|NULL $row
* (optional) The mocked row.
*
* @return array|string
* The transformed value.
*/
protected function transform(array $value, Row $row = NULL) {
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
if (empty($row)) {
$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);
return $plugin->transform($value, $executable, $row, 'foo');
}
/**
* If the source and destination themes are identical, the region should only
* be passed through if it actually exists in the destination theme.
*
* @covers ::transform
*/
public function testTransformSameThemeRegionExists() {
$this->assertSame('triptych_second', $this->transform(['triptych_second', 'bartik', 'bartik']));
}
/**
* If the source and destination themes are identical, the region should be
* changed to 'content' if it doesn't exist in the destination theme.
*
* @covers ::transform
*/
public function testTransformSameThemeRegionNotExists() {
$this->assertSame('content', $this->transform(['footer', 'bartik', 'bartik']));
}
}

View file

@ -0,0 +1,88 @@
<?php
/**
* @file
* Contains \Drupal\Tests\block\Unit\Plugin\migrate\process\BlockVisibilityTest.
*/
namespace Drupal\Tests\block\Unit\Plugin\migrate\process;
use Drupal\block\Plugin\migrate\process\BlockVisibility;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
/**
* Tests the block_visibility process plugin.
*
* @coversDefaultClass \Drupal\block\Plugin\migrate\process\BlockVisibility
* @group block
*/
class BlockVisibilityTest extends MigrateProcessTestCase {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
$this->plugin = new BlockVisibility([], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migration_plugin->reveal());
}
/**
* @covers ::transform
*/
public function testTransformNoData() {
$transformed_value = $this->plugin->transform([0, '', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertEmpty($transformed_value);
}
/**
* @covers ::transform
*/
public function testTransformSinglePageWithFront() {
$visibility = $this->plugin->transform([0, '<front>', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame('request_path', $visibility['request_path']['id']);
$this->assertTrue($visibility['request_path']['negate']);
$this->assertSame('<front>', $visibility['request_path']['pages']);
}
/**
* @covers ::transform
*/
public function testTransformMultiplePagesWithFront() {
$visibility = $this->plugin->transform([1, "foo\n/bar\rbaz\r\n<front>", []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame('request_path', $visibility['request_path']['id']);
$this->assertFalse($visibility['request_path']['negate']);
$this->assertSame("/foo\n/bar\n/baz\n<front>", $visibility['request_path']['pages']);
}
/**
* @covers ::transform
*/
public function testTransformPhpEnabled() {
$this->moduleHandler->moduleExists('php')->willReturn(TRUE);
$visibility = $this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame('php', $visibility['php']['id']);
$this->assertFalse($visibility['php']['negate']);
$this->assertSame('<?php', $visibility['php']['php']);
}
/**
* @covers ::transform
*/
public function testTransformPhpDisabled() {
$this->moduleHandler->moduleExists('php')->willReturn(FALSE);
$transformed_value = $this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertEmpty($transformed_value);
}
}

View file

@ -2,31 +2,27 @@
/**
* @file
* Contains \Drupal\Tests\block\Unit\Plugin\migrate\source\d6\BlockTest.
* Contains \Drupal\Tests\block\Unit\Plugin\migrate\source\BlockTest.
*/
namespace Drupal\Tests\block\Unit\Plugin\migrate\source\d6;
namespace Drupal\Tests\block\Unit\Plugin\migrate\source;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D6 block source plugin.
* Tests block source plugin.
*
* @coversDefaultClass \Drupal\block\Plugin\migrate\source\d6\Block
* @coversDefaultClass \Drupal\block\Plugin\migrate\source\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';
const PLUGIN_CLASS = 'Drupal\block\Plugin\migrate\source\Block';
// The fake Migration configuration entity.
protected $migrationConfiguration = array(
// The ID of the entity, can be any string.
'id' => 'test',
'source' => array(
'plugin' => 'd6_block',
'plugin' => 'block',
),
);
@ -79,6 +75,20 @@ class BlockTest extends MigrateSqlSourceTestCase {
protected function setUp() {
$this->databaseContents['blocks'] = $this->expectedResults;
$this->databaseContents['blocks_roles'] = $this->expectedBlocksRoles;
$this->databaseContents['system'] = array(
array(
'filename' => 'modules/system/system.module',
'name' => 'system',
'type' => 'module',
'owner' => '',
'status' => '1',
'throttle' => '0',
'bootstrap' => '0',
'schema_version' => '6055',
'weight' => '0',
'info' => 'a:0:{}',
)
);
parent::setUp();
}