Update to Drupal 8.1.2. For more information, see https://www.drupal.org/project/drupal/releases/8.1.2

This commit is contained in:
Pantheon Automation 2016-06-02 15:56:09 -07:00 committed by Greg Anderson
parent 9eae24d844
commit 28556d630e
1322 changed files with 6699 additions and 2064 deletions

View file

@ -568,4 +568,5 @@ class AccessManagerTest extends UnitTestCase {
*/
interface TestAccessCheckInterface extends AccessCheckInterface {
public function access();
}

View file

@ -91,5 +91,4 @@ class AjaxResponseTest extends UnitTestCase {
$this->assertEquals($response->getContent(), '<textarea>[]</textarea>');
}
}

View file

@ -165,4 +165,5 @@ class TestMemoryBackend extends MemoryBackend {
public function getAllCids() {
return array_keys($this->cache);
}
}

View file

@ -500,5 +500,6 @@ class CssCollectionRendererUnitTest extends UnitTestCase {
);
$this->renderer->render($css_group);
}
}
}

View file

@ -77,7 +77,7 @@ class CssOptimizerUnitTest extends UnitTestCase {
*/
function providerTestOptimize() {
$path = 'core/tests/Drupal/Tests/Core/Asset/css_test_files/';
$absolute_path = dirname(__FILE__) . '/css_test_files/';
$absolute_path = dirname(__FILE__) . '/css_test_files/';
return array(
// File. Tests:
// - Stripped comments and white-space.
@ -188,7 +188,7 @@ class CssOptimizerUnitTest extends UnitTestCase {
'browsers' => array('IE' => TRUE, '!IE' => TRUE),
'basename' => 'css_input_with_bom.css',
),
'.byte-order-mark-test{content:"☃";}'. "\n",
'.byte-order-mark-test{content:"☃";}' . "\n",
),
array(
array(

View file

@ -31,13 +31,13 @@ class JsOptimizerUnitTest extends UnitTestCase {
/**
* Provides data for the JS asset cleaning test.
*
* @see \Drupal\Core\Asset\JsOptimizer::clean().
* @see \Drupal\Core\Asset\JsOptimizer::clean()
*
* @returns array
* An array of test data.
*/
function providerTestClean() {
$path = dirname(__FILE__) . '/js_test_files/';
$path = dirname(__FILE__) . '/js_test_files/';
return array(
// File. Tests:
// - Stripped sourceMappingURL with comment # syntax.
@ -78,13 +78,13 @@ class JsOptimizerUnitTest extends UnitTestCase {
/**
* Provides data for the JS asset optimize test.
*
* @see \Drupal\Core\Asset\JsOptimizer::optimize().
* @see \Drupal\Core\Asset\JsOptimizer::optimize()
*
* @returns array
* An array of test data.
*/
function providerTestOptimize() {
$path = dirname(__FILE__) . '/js_test_files/';
$path = dirname(__FILE__) . '/js_test_files/';
return array(
0 => array(
array(

View file

@ -14,7 +14,7 @@ class BlockBaseTest extends UnitTestCase {
/**
* Tests the machine name suggestion.
*
* @see \Drupal\Core\Block\BlockBase::getMachineNameSuggestion().
* @see \Drupal\Core\Block\BlockBase::getMachineNameSuggestion()
*/
public function testGetMachineNameSuggestion() {
$module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');

View file

@ -297,4 +297,5 @@ class BackendChainImplementationUnitTest extends UnitTestCase {
$chain->removeBin();
}
}

View file

@ -18,7 +18,7 @@ class PathParentCacheContextTest extends UnitTestCase {
*
* @dataProvider providerTestGetContext
*/
public function testgetContext($original_path, $context) {
public function testGetContext($original_path, $context) {
$request_stack = new RequestStack();
$request = Request::create($original_path);
$request_stack->push($request);

View file

@ -0,0 +1,46 @@
<?php
namespace Drupal\Tests\Core\Cache\Context;
use Drupal\Core\Cache\Context\QueryArgsCacheContext;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* @coversDefaultClass \Drupal\Core\Cache\Context\QueryArgsCacheContext
* @group Cache
*/
class QueryArgsCacheContextTest extends UnitTestCase {
/**
* @covers ::getContext
*
* @dataProvider providerTestGetContext
*/
public function testGetContext(array $query_args, $cache_context_parameter, $context) {
$request_stack = new RequestStack();
$request = Request::create('/', 'GET', $query_args);
$request_stack->push($request);
$cache_context = new QueryArgsCacheContext($request_stack);
$this->assertSame($cache_context->getContext($cache_context_parameter), $context);
}
/**
* Provides a list of query arguments and expected cache contexts.
*/
public function providerTestGetContext() {
return [
[[], NULL, NULL],
[[], 'foo', NULL],
// Non-empty query arguments.
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], NULL, 'alpaca=&llama=rocks&panda=drools&z=0'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'llama', 'rocks'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'alpaca', '?valueless?'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'panda', 'drools'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'z', '0'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'chicken', NULL],
];
}
}

View file

@ -24,4 +24,5 @@ class NullBackendTest extends UnitTestCase {
$null_cache->set($key, $value);
$this->assertFalse($null_cache->get($key));
}
}

View file

@ -88,4 +88,5 @@ class TestConditionAccessResolverTrait {
use \Drupal\Core\Condition\ConditionAccessResolverTrait {
resolveConditions as public;
}
}

View file

@ -130,4 +130,5 @@ class QueryFactoryTest extends UnitTestCase {
->getMock();
return $config->setName($name);
}
}

View file

@ -278,14 +278,17 @@ class MockContainerInjection implements ContainerInjectionInterface {
public function getResult() {
return $this->result;
}
}
class MockContainerAware extends ContainerAware {
public function getResult() {
return 'This is container aware.';
}
}
class MockInvokeController {
public function __invoke() {
return 'This used __invoke().';
}
}

View file

@ -38,4 +38,5 @@ class EmptyStatementTest extends UnitTestCase {
$this->assertEquals($result->fetchAll(), array(), 'Empty array returned from empty result set.');
}
}

View file

@ -46,4 +46,5 @@ class OrderByTest extends UnitTestCase {
$sql = $this->query->__toString();
$this->assertStringEndsWith('ORDER BY xDROPtablenode ASC', $sql, 'Order by field is escaped correctly.');
}
}

View file

@ -0,0 +1,159 @@
<?php
namespace Drupal\Tests\Core\Datetime;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Core\Datetime\DrupalDateTime
* @group Datetime
*/
class DrupalDateTimeTest extends UnitTestCase {
/**
* Test date diffs.
*
* @param mixed $input1
* A DrupalDateTime object.
* @param mixed $input2
* Date argument for DrupalDateTime::diff method.
* @param bool $absolute
* Absolute flag for DrupalDateTime::diff method.
* @param \DateInterval $expected
* The expected result of the DrupalDateTime::diff operation.
*
* @dataProvider providerTestDateDiff
*/
public function testDateDiff($input1, $input2, $absolute, \DateInterval $expected) {
$interval = $input1->diff($input2, $absolute);
$this->assertEquals($interval, $expected);
}
/**
* Test date diff exception caused by invalid input.
*
* @param mixed $input1
* A DateTimePlus object.
* @param mixed $input2
* Date argument for DateTimePlus::diff method.
* @param bool $absolute
* Absolute flag for DateTimePlus::diff method.
*
* @dataProvider providerTestInvalidDateDiff
*/
public function testInvalidDateDiff($input1, $input2, $absolute) {
$this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
$interval = $input1->diff($input2, $absolute);
}
/**
* Provides data for date tests.
*
* @return array
* An array of arrays, each containing the input parameters for
* DrupalDateTimeTest::testDateDiff().
*
* @see DrupalDateTimeTest::testDateDiff()
*/
public function providerTestDateDiff() {
$settings = ['langcode' => 'en'];
$utc_tz = new \DateTimeZone('UTC');
$empty_interval = new \DateInterval('PT0S');
$positive_19_hours = new \DateInterval('PT19H');
$positive_18_hours = new \DateInterval('PT18H');
$positive_1_hour = new \DateInterval('PT1H');
$negative_1_hour = new \DateInterval('PT1H');
$negative_1_hour->invert = 1;
return array(
// There should be a 19 hour time interval between
// new years in Sydney and new years in LA in year 2000.
array(
'input2' => DrupalDateTime::createFromFormat('Y-m-d H:i:s', '2000-01-01 00:00:00', new \DateTimeZone('Australia/Sydney'), $settings),
'input1' => DrupalDateTime::createFromFormat('Y-m-d H:i:s', '2000-01-01 00:00:00', new \DateTimeZone('America/Los_Angeles'), $settings),
'absolute' => FALSE,
'expected' => $positive_19_hours,
),
// In 1970 Sydney did not observe daylight savings time
// So there is only a 18 hour time interval.
array(
'input2' => DrupalDateTime::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00', new \DateTimeZone('Australia/Sydney'), $settings),
'input1' => DrupalDateTime::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00', new \DateTimeZone('America/Los_Angeles'), $settings),
'absolute' => FALSE,
'expected' => $positive_18_hours,
),
array(
'input1' => DrupalDateTime::createFromFormat('U', 3600, new \DateTimeZone('America/Los_Angeles'), $settings),
'input2' => DrupalDateTime::createFromFormat('U', 0, $utc_tz, $settings),
'absolute' => FALSE,
'expected' => $negative_1_hour,
),
array(
'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
'input2' => DrupalDateTime::createFromFormat('U', 0, $utc_tz, $settings),
'absolute' => FALSE,
'expected' => $negative_1_hour,
),
array(
'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
'input2' => \DateTime::createFromFormat('U', 0),
'absolute' => FALSE,
'expected' => $negative_1_hour,
),
array(
'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
'input2' => DrupalDateTime::createFromFormat('U', 0, $utc_tz, $settings),
'absolute' => TRUE,
'expected' => $positive_1_hour,
),
array(
'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
'input2' => \DateTime::createFromFormat('U', 0),
'absolute' => TRUE,
'expected' => $positive_1_hour,
),
array(
'input1' => DrupalDateTime::createFromFormat('U', 0, $utc_tz, $settings),
'input2' => DrupalDateTime::createFromFormat('U', 0, $utc_tz, $settings),
'absolute' => FALSE,
'expected' => $empty_interval,
),
);
}
/**
* Provides data for date tests.
*
* @return array
* An array of arrays, each containing the input parameters for
* DateTimePlusTest::testInvalidDateDiff().
*
* @see DateTimePlusTest::testInvalidDateDiff()
*/
public function providerTestInvalidDateDiff() {
$settings = ['langcode' => 'en'];
$utc_tz = new \DateTimeZone('UTC');
return array(
array(
'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
'input2' => '1970-01-01 00:00:00',
'absolute' => FALSE,
),
array(
'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
'input2' => NULL,
'absolute' => FALSE,
),
);
}
}

View file

@ -359,10 +359,12 @@ class ValidConsumer {
}
public function addWithId(HandlerInterface $instance, $id, $priority = 0) {
}
}
class InvalidConsumer {
public function addHandler($instance, $priority = 0) {
}
}
class ValidConsumerWithExtraArguments {
public function addHandler(HandlerInterface $instance, $priority = 0, $extra1 = '', $extra2 = '') {
@ -373,6 +375,7 @@ class ValidConsumerWithExtraArguments {
}
public function addWithDifferentOrder(HandlerInterface $instance, $extra1, $priority = 0, $extra2 = 'default2', $extra3 = 'default3') {
}
}
class ValidHandler implements HandlerInterface {
}

View file

@ -90,4 +90,5 @@ class DependencySerializationTestDummy implements ContainerAwareInterface {
public function getServiceIds() {
return $this->_serviceIds;
}
}

View file

@ -133,6 +133,7 @@ EOD;
$request->server->set('SCRIPT_NAME', '/index.php');
$this->assertEquals('sites/example', DrupalKernel::findSitePath($request));
}
}
}

View file

@ -7,6 +7,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Language\Language;
@ -130,9 +131,7 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$this->typedDataManager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$this->typedDataManager = $this->getMock(TypedDataManagerInterface::class);
$this->typedDataManager->expects($this->any())
->method('getDefinition')
->with('entity')

View file

@ -784,6 +784,7 @@ class TestEntityFieldManager extends EntityFieldManager {
$this->fieldDefinitions = [];
$this->fieldStorageDefinitions = [];
}
}
/**

View file

@ -143,4 +143,5 @@ class TestEntityListBuilder extends EntityTestListBuilder {
public function buildOperations(EntityInterface $entity) {
return array();
}
}

View file

@ -218,6 +218,15 @@ class DefaultTableMappingTest extends UnitTestCase {
$table_mapping = new DefaultTableMapping($this->entityType, $definitions);
$expected = ['value' => 'test__value', 'format' => 'test__format'];
$this->assertSame($expected, $table_mapping->getColumnNames('test'));
$definitions['test'] = $this->setUpDefinition('test', ['value']);
// Set custom storage.
$definitions['test']->expects($this->any())
->method('hasCustomStorage')
->wilLReturn(TRUE);
$table_mapping = new DefaultTableMapping($this->entityType, $definitions);
// Should return empty for column names.
$this->assertSame([], $table_mapping->getColumnNames('test'));
}
/**

View file

@ -6,6 +6,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Language\Language;
@ -136,9 +137,7 @@ class EntityAdapterUnitTest extends UnitTestCase {
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$this->typedDataManager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$this->typedDataManager = $this->getMock(TypedDataManagerInterface::class);
$this->typedDataManager->expects($this->any())
->method('getDefinition')
->with('entity')
@ -412,4 +411,5 @@ class EntityAdapterUnitTest extends UnitTestCase {
$this->entityAdapter->setValue(NULL);
$this->assertEquals(new \ArrayIterator([]), $this->entityAdapter->getIterator());
}
}

View file

@ -267,4 +267,5 @@ class RedirectResponseSubscriberTest extends UnitTestCase {
return $data;
}
}

View file

@ -0,0 +1,157 @@
<?php
namespace Drupal\Tests\Core\Extension;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use Symfony\Component\Yaml\Yaml;
/**
* Tests discovery of extensions.
*
* @coversDefaultClass \Drupal\Core\Extension\ExtensionDiscovery
* @group Extension
*/
class ExtensionDiscoveryTest extends UnitTestCase {
/**
* Tests extension discovery in a virtual filesystem with vfsStream.
*
* @covers ::scan
*/
public function testExtensionDiscoveryVfs() {
// Set up the file system.
$filesystem = [];
$files_by_type_and_name_expected = $this->populateFilesystemStructure($filesystem);
$vfs = vfsStream::setup('root', NULL, $filesystem);
$root = $vfs->url();
$this->assertFileExists($root . '/core/modules/system/system.module');
$this->assertFileExists($root . '/core/modules/system/system.info.yml');
// Create an ExtensionDiscovery with $root.
$extension_discovery = new ExtensionDiscovery($root, FALSE, NULL, 'sites/default');
/** @var \Drupal\Core\Extension\Extension[][] $extensions_by_type */
$extensions_by_type = [];
$files_by_type_and_name = [];
foreach (['profile', 'module', 'theme', 'theme_engine'] as $type) {
$extensions_by_type[$type] = $extension_discovery->scan($type, FALSE);
foreach ($extensions_by_type[$type] as $name => $extension) {
$files_by_type_and_name[$type][$name] = $extension->getPathname();
}
if ($type === 'profile') {
// Set profile directories for discovery of the other extension types.
$extension_discovery->setProfileDirectories(['myprofile' => 'profiles/myprofile']);
}
}
$this->assertEquals($files_by_type_and_name_expected, $files_by_type_and_name);
$extension_expected = new Extension($root, 'module', 'core/modules/system/system.info.yml', 'system.module');
$extension_expected->subpath = 'modules/system';
$extension_expected->origin = 'core';
$this->assertEquals($extension_expected, $extensions_by_type['module']['system'], 'system');
$extension_expected = new Extension($root, 'theme_engine', 'core/themes/engines/twig/twig.info.yml', 'twig.engine');
$extension_expected->subpath = 'themes/engines/twig';
$extension_expected->origin = 'core';
$this->assertEquals($extension_expected, $extensions_by_type['theme_engine']['twig'], 'twig');
}
/**
* Adds example files to the filesystem structure.
*
* @param array $filesystem_structure
*
* @return string[][]
* Format: $[$type][$name] = $yml_file
* E.g. $['module']['system'] = 'system.info.yml'
*/
protected function populateFilesystemStructure(array &$filesystem_structure) {
$info_by_file = [
'core/profiles/standard/standard.info.yml' => [
'type' => 'profile',
],
'core/profiles/minimal/minimal.info.yml' => [
'type' => 'profile',
],
// Override the core instance of the 'minimal' profile.
'sites/default/profiles/minimal/minimal.info.yml' => [
'type' => 'profile',
],
'profiles/myprofile/myprofile.info.yml' => [
'type' => 'profile',
],
'profiles/myprofile/modules/myprofile_nested_module/myprofile_nested_module.info.yml' => [],
'profiles/otherprofile/otherprofile.info.yml' => [
'type' => 'profile',
],
'core/modules/user/user.info.yml' => [],
'profiles/otherprofile/modules/otherprofile_nested_module/otherprofile_nested_module.info.yml' => [],
'core/modules/system/system.info.yml' => [],
'core/themes/seven/seven.info.yml' => [
'type' => 'theme',
],
// Override the core instance of the 'seven' theme.
'sites/default/themes/seven/seven.info.yml' => [
'type' => 'theme',
],
'modules/devel/devel.info.yml' => [],
'modules/poorly_placed_theme/poorly_placed_theme.info.yml' => [
'type' => 'theme',
],
'core/themes/engines/twig/twig.info.yml' => [
'type' => 'theme_engine',
],
];
$files_by_type_and_name_expected = [];
$content_by_file = [];
foreach ($info_by_file as $file => $info) {
$name = basename($file, '.info.yml');
$info += [
'type' => 'module',
'name' => "Name of ($name)",
'core' => '8.x',
];
$type = $info['type'];
$content_by_file[$file] = Yaml::dump($info);
$files_by_type_and_name_expected[$type][$name] = $file;
}
$content_by_file['core/modules/system/system.module'] = '<?php';
$content_by_file['core/themes/engines/twig/twig.engine'] = '<?php';
foreach ($content_by_file as $file => $content) {
$pieces = explode('/', $file);
$this->addFileToFilesystemStructure($filesystem_structure, $pieces, $content);
}
unset($files_by_type_and_name_expected['module']['otherprofile_nested_module']);
return $files_by_type_and_name_expected;
}
/**
* @param array $filesystem_structure
* @param string[] $pieces
* Fragments of the file path.
* @param string $content
*/
protected function addFileToFilesystemStructure(array &$filesystem_structure, array $pieces, $content) {
$piece = array_shift($pieces);
if ($pieces !== []) {
$filesystem_structure += [$piece => []];
$this->addFileToFilesystemStructure($filesystem_structure[$piece], $pieces, $content);
}
else {
$filesystem_structure[$piece] = $content;
}
}
}

View file

@ -511,4 +511,5 @@ class ModuleHandlerTest extends UnitTestCase {
$this->moduleHandler->addModule('module', 'place');
$this->assertEquals(array('module' => $this->root . '/place'), $this->moduleHandler->getModuleDirectories());
}
}

View file

@ -5,5 +5,7 @@
* Test module.
*/
// return an array to test nested merge in invoke all.
/**
* Returns an array to test nested merge in invoke all.
*/
function module_handler_test_all1_hook($arg) { return array($arg); }

View file

@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\Field;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldTypePluginManager;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
@ -35,9 +36,7 @@ abstract class BaseFieldDefinitionTestBase extends UnitTestCase {
->method('moduleExists')
->with($module_name)
->will($this->returnValue(TRUE));
$typed_data_manager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$typed_data_manager = $this->getMock(TypedDataManagerInterface::class);
$plugin_manager = new FieldTypePluginManager(
$namespaces,
$this->getMock('Drupal\Core\Cache\CacheBackendInterface'),

View file

@ -208,4 +208,5 @@ class FieldItemListTest extends UnitTestCase {
$this->assertNull($field_list->defaultValuesFormSubmit([], $form, $form_state));
}
}

View file

@ -886,11 +886,13 @@ class TestForm implements FormInterface {
}
public function validateForm(array &$form, FormStateInterface $form_state) { }
public function submitForm(array &$form, FormStateInterface $form_state) { }
}
class TestFormInjected extends TestForm implements ContainerInjectionInterface {
public static function create(ContainerInterface $container) {
return new static();
}
}

View file

@ -583,6 +583,7 @@ class FormStateTest extends UnitTestCase {
$form_state->setValue('value_to_keep', 'magic_ponies');
$this->assertSame($form_state->cleanValues()->getValues(), ['value_to_keep' => 'magic_ponies']);
}
}
/**
@ -596,4 +597,5 @@ class PrepareCallbackTestForm implements FormInterface {
public function buildForm(array $form, FormStateInterface $form_state) {}
public function validateForm(array &$form, FormStateInterface $form_state) { }
public function submitForm(array &$form, FormStateInterface $form_state) { }
}

View file

@ -147,7 +147,7 @@ class LoggerChannelTest extends UnitTestCase {
}
class NaughtyRecursiveLogger implements LoggerInterface {
class NaughtyRecursiveLogger implements LoggerInterface {
use LoggerTrait;
protected $channel;
@ -160,4 +160,5 @@ class NaughtyRecursiveLogger implements LoggerInterface {
public function log($level, $message, array $context = []) {
$this->channel->log(rand(0, 7), $message, $context);
}
}

View file

@ -123,6 +123,7 @@ class MailManagerTest extends UnitTestCase {
$instance = $this->mailManager->getInstance($options);
$this->assertInstanceOf('Drupal\Core\Mail\Plugin\Mail\TestMailCollector', $instance);
}
}
/**
@ -138,4 +139,5 @@ class TestMailManager extends MailManager {
public function setDiscovery(DiscoveryInterface $discovery) {
$this->discovery = $discovery;
}
}

View file

@ -321,4 +321,5 @@ class TestLocalTaskDefault extends LocalTaskDefault {
$this->routeProvider = $route_provider;
return $this;
}
}

View file

@ -57,4 +57,5 @@ class NoSessionOpenTest extends UnitTestCase {
$result = $this->policy->check($request_with_session);
$this->assertSame(NULL, $result);
}
}

View file

@ -65,7 +65,7 @@ class ParamConverterManagerTest extends UnitTestCase {
* An array of arrays, each containing the input parameters for
* providerTestResolvers::testAddConverter().
*
* @see ParamConverterManagerTest::testAddConverter().
* @see ParamConverterManagerTest::testAddConverter()
*/
public function providerTestAddConverter() {
$converters[0]['unsorted'] = array(
@ -108,7 +108,7 @@ class ParamConverterManagerTest extends UnitTestCase {
* An array of arrays, each containing the input parameters for
* providerTestResolvers::testGetConverter().
*
* @see ParamConverterManagerTest::testGetConverter().
* @see ParamConverterManagerTest::testGetConverter()
*/
public function providerTestGetConverter() {
return array(

View file

@ -181,7 +181,9 @@ class FakePhpassHashedPassword extends PhpassHashedPassword {
// Noop.
}
// Expose this method as public for tests.
/**
* Exposes this method as public for tests.
*/
public function enforceLog2Boundaries($count_log2) {
return parent::enforceLog2Boundaries($count_log2);
}

View file

@ -152,4 +152,5 @@ class PathMatcherTest extends UnitTestCase {
),
);
}
}

View file

@ -82,4 +82,5 @@ class PathProcessorFrontTest extends UnitTestCase {
['/user', '/user'],
];
}
}

View file

@ -29,7 +29,7 @@ class PathProcessorTest extends UnitTestCase {
protected $languages;
/**
* The language manager stub used to construct a PathProcessorLanguage object.
* The language manager stub used to construct a PathProcessorLanguage object.
*
* @var \Drupal\language\ConfigurableLanguageManagerInterface|\PHPUnit_Framework_MockObject_MockBuilder
*/
@ -209,4 +209,5 @@ class PathProcessorTest extends UnitTestCase {
$processed = $processor_manager->processInbound($test_path, $request);
$this->assertEquals('/user/1', $processed, 'Processing in the correct order resolves the system path from an alias.');
}
}

View file

@ -3,6 +3,7 @@
namespace Drupal\Tests\Core\Plugin\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
@ -61,10 +62,7 @@ class ContextDefinitionTest extends UnitTestCase {
if ($is_multiple) {
$create_definition_method = 'createListDataDefinition';
}
$mock_data_manager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->setMethods(array($create_definition_method))
->getMock();
$mock_data_manager = $this->getMock(TypedDataManagerInterface::class);
// Our mocked data manager will return our mocked data definition for a
// valid data type.
$mock_data_manager->expects($this->once())
@ -127,10 +125,7 @@ class ContextDefinitionTest extends UnitTestCase {
if ($is_multiple) {
$create_definition_method = 'createListDataDefinition';
}
$mock_data_manager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->setMethods(array($create_definition_method))
->getMock();
$mock_data_manager = $this->getMock(TypedDataManagerInterface::class);
// Our mocked data manager will return NULL for a non-valid data type. This
// will eventually cause getDataDefinition() to throw an exception.
$mock_data_manager->expects($this->once())

View file

@ -10,6 +10,7 @@ namespace Drupal\Tests\Core\Plugin\Context;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\Container;
@ -46,10 +47,7 @@ class ContextTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
$this->typedDataManager = $this->getMockBuilder('Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->setMethods(array('create'))
->getMock();
$this->typedDataManager = $this->getMock(TypedDataManagerInterface::class);
}
/**
@ -164,6 +162,7 @@ class ContextTest extends UnitTestCase {
->with($mock_data_definition, $default_value)
->willReturn($this->typedData);
}
}
/**

View file

@ -7,6 +7,7 @@ use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\Plugin\DataType\StringData;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
@ -34,9 +35,7 @@ class ContextTypedDataTest extends UnitTestCase {
*/
public function testGetContextValue() {
// Prepare a container that holds the typed data manager mock.
$typed_data_manager = $this->getMockBuilder('Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$typed_data_manager = $this->getMock(TypedDataManagerInterface::class);
$typed_data_manager->expects($this->once())
->method('getCanonicalRepresentation')
->will($this->returnCallback(array($this, 'getCanonicalRepresentation')));

View file

@ -2,6 +2,8 @@
namespace Drupal\Tests\Core\Plugin;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
/**
@ -15,11 +17,15 @@ class DefaultSingleLazyPluginCollectionTest extends LazyPluginCollectionTestBase
*/
protected function setupPluginCollection(\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $create_count = NULL) {
$definitions = $this->getPluginDefinitions();
$this->pluginInstances['apple'] = $this->getPluginMock('apple', $definitions['apple']);
$this->pluginInstances['apple'] = new ConfigurablePlugin(['id' => 'apple', 'key' => 'value'], 'apple', $definitions['apple']);
$this->pluginInstances['banana'] = new ConfigurablePlugin(['id' => 'banana', 'key' => 'other_value'], 'banana', $definitions['banana']);
$create_count = $create_count ?: $this->never();
$this->pluginManager->expects($create_count)
->method('createInstance')
->will($this->returnValue($this->pluginInstances['apple']));
->willReturnCallback(function ($id) {
return $this->pluginInstances[$id];
});
$this->defaultPluginCollection = new DefaultSingleLazyPluginCollection($this->pluginManager, 'apple', array('id' => 'apple', 'key' => 'value'));
}
@ -34,4 +40,48 @@ class DefaultSingleLazyPluginCollectionTest extends LazyPluginCollectionTestBase
$this->assertSame($apple, $this->defaultPluginCollection->get('apple'));
}
/**
* @covers ::addInstanceId
* @covers ::getConfiguration
* @covers ::setConfiguration
*/
public function testAddInstanceId() {
$this->setupPluginCollection($this->any());
$this->assertEquals(['id' => 'apple', 'key' => 'value'], $this->defaultPluginCollection->get('apple')->getConfiguration());
$this->assertEquals(['id' => 'apple', 'key' => 'value'], $this->defaultPluginCollection->getConfiguration());
$this->defaultPluginCollection->addInstanceId('banana', ['id' => 'banana', 'key' => 'other_value']);
$this->assertEquals(['id' => 'apple', 'key' => 'value'], $this->defaultPluginCollection->get('apple')->getConfiguration());
$this->assertEquals(['id' => 'banana', 'key' => 'other_value'], $this->defaultPluginCollection->getConfiguration());
$this->assertEquals(['id' => 'banana', 'key' => 'other_value'], $this->defaultPluginCollection->get('banana')->getConfiguration());
}
}
class ConfigurablePlugin extends PluginBase implements ConfigurablePluginInterface {
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configuration = $configuration + $this->defaultConfiguration();
}
public function defaultConfiguration() {
return [];
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
public function calculateDependencies() {
return [];
}
}

View file

@ -29,7 +29,7 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase {
/**
* Tests the getDerivativeFetcher method.
*
* @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDerivativeFetcher().
* @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDerivativeFetcher()
*/
public function testGetDerivativeFetcher() {
$definitions = array();

View file

@ -156,6 +156,7 @@ EOS;
return $expected_string;
}
}
class TestServiceNoMethod {

View file

@ -691,4 +691,5 @@ class BubbleableMetadataTest extends UnitTestCase {
],
];
}
}

View file

@ -151,6 +151,7 @@ class ElementInfoManagerTest extends UnitTestCase {
$this->assertNull($element_info->getInfoProperty('foo', '#non_existing_property'));
$this->assertSame('qux', $element_info->getInfoProperty('foo', '#non_existing_property', 'qux'));
}
}
/**

View file

@ -587,6 +587,7 @@ class RendererBubblingTest extends RendererTestBase {
];
$this->renderer->renderRoot($data);
}
}

View file

@ -273,6 +273,7 @@ class RouteBuilderTest extends UnitTestCase {
// This will not trigger a rebuild.
$this->assertFalse($this->routeBuilder->rebuildIfNeeded());
}
}
/**
@ -320,4 +321,5 @@ class TestRouteSubscriber {
$collection->add('test_route.2', new Route('/test-route/2'));
return $collection;
}
}

View file

@ -238,4 +238,5 @@ class RoutingFixtures {
return $tables;
}
}

View file

@ -178,7 +178,7 @@ class UrlGeneratorTest extends UnitTestCase {
*/
public function aliasManagerCallback() {
$args = func_get_args();
switch($args[0]) {
switch ($args[0]) {
case '/test/one':
return '/hello/world';
case '/test/two/5':

View file

@ -135,7 +135,7 @@ class UserSessionTest extends UnitTestCase {
*
* @dataProvider providerTestHasPermission
*
* @see \Drupal\Core\Session\UserSession::hasPermission().
* @see \Drupal\Core\Session\UserSession::hasPermission()
*/
public function testHasPermission($permission, array $sessions_with_access, array $sessions_without_access) {
foreach ($sessions_with_access as $name) {

View file

@ -174,4 +174,5 @@ class WriteSafeSessionHandlerTest extends UnitTestCase {
['gc', TRUE, [42]],
];
}
}

View file

@ -139,4 +139,5 @@ class NegotiationMiddlewareTest extends UnitTestCase {
class StubNegotiationMiddleware extends NegotiationMiddleware {
public function getContentType(Request $request) { return parent::getContentType($request); }
}

View file

@ -94,4 +94,5 @@ class ReverseProxyMiddlewareTest extends UnitTestCase {
$this->assertSame($settings->get('reverse_proxy_forwarded_header'), $request->getTrustedHeaderName($request::HEADER_FORWARDED));
$this->assertSame($settings->get('reverse_proxy_addresses'), $request->getTrustedProxies());
}
}

View file

@ -97,6 +97,7 @@ class TranslationManagerTest extends UnitTestCase {
['bar %baz @bar', ['%baz' => 'baz', '@bar' => 'bar'], 'bar <em class="placeholder">baz</em> bar'],
];
}
}
class TestTranslationManager extends TranslationManager {

View file

@ -7,8 +7,10 @@
namespace Drupal\Tests\Core\Template;
use Drupal\Core\GeneratedLink;
use Drupal\Core\Render\RenderableInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Template\Loader\StringLoader;
use Drupal\Core\Template\TwigEnvironment;
@ -240,6 +242,63 @@ class TwigExtensionTest extends UnitTestCase {
return $data;
}
/**
* @covers ::escapeFilter
* @covers ::bubbleArgMetadata
*/
public function testEscapeWithGeneratedLink() {
$renderer = $this->prophesize(RendererInterface::class);
$twig = new \Twig_Environment(NULL, [
'debug' => TRUE,
'cache' => FALSE,
'autoescape' => 'html',
'optimizations' => 0,
]
);
$twig_extension = new TwigExtension($renderer->reveal());
$twig->addExtension($twig_extension->setUrlGenerator($this->prophesize(UrlGeneratorInterface::class)->reveal()));
$link = new GeneratedLink();
$link->setGeneratedLink('<a href="http://example.com"></a>');
$link->addCacheTags(['foo']);
$link->addAttachments(['library' => ['system/base']]);
$result = $twig_extension->escapeFilter($twig, $link, 'html', NULL, TRUE);
$renderer->render([
"#cache" => [
"contexts" => [],
"tags" => ["foo"],
"max-age" => -1
],
"#attached" => ['library' => ['system/base']],
])->shouldHaveBeenCalled();
$this->assertEquals('<a href="http://example.com"></a>', $result);
}
/**
* @covers ::renderVar
* @covers ::bubbleArgMetadata
*/
public function testRenderVarWithGeneratedLink() {
$renderer = $this->prophesize(RendererInterface::class);
$twig_extension = new TwigExtension($renderer->reveal());
$link = new GeneratedLink();
$link->setGeneratedLink('<a href="http://example.com"></a>');
$link->addCacheTags(['foo']);
$link->addAttachments(['library' => ['system/base']]);
$result = $twig_extension->renderVar($link);
$renderer->render([
"#cache" => [
"contexts" => [],
"tags" => ["foo"],
"max-age" => -1
],
"#attached" => ['library' => ['system/base']],
])->shouldHaveBeenCalled();
$this->assertEquals('<a href="http://example.com"></a>', $result);
}
}
class TwigExtensionTestString {

View file

@ -835,5 +835,4 @@ class TestUrl extends Url {
$this->accessManager = $access_manager;
}
}

View file

@ -20,7 +20,6 @@ class ErrorTest extends UnitTestCase {
* The expected return array.
*
* @dataProvider providerTestGetLastCaller
*
*/
public function testGetLastCaller($backtrace, $expected) {
$this->assertSame($expected, Error::getLastCaller($backtrace));