Update to Drupal 8.1.1. For more information, see https://www.drupal.org/node/2718713

This commit is contained in:
Pantheon Automation 2016-05-04 14:35:41 -07:00 committed by Greg Anderson
parent c0a0d5a94c
commit 9eae24d844
669 changed files with 3873 additions and 1553 deletions

View file

@ -2,6 +2,7 @@
namespace Drupal\Tests\system\Kernel\Extension;
use Drupal\Core\Extension\MissingDependencyException;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use \Drupal\Core\Extension\ModuleUninstallValidatorException;
use Drupal\entity_test\Entity\EntityTest;
@ -121,7 +122,7 @@ class ModuleHandlerTest extends KernelTestBase {
$result = $this->moduleInstaller()->install(array('color'));
$this->fail(t('ModuleInstaller::install() throws an exception if dependencies are missing.'));
}
catch (\Drupal\Core\Extension\MissingDependencyException $e) {
catch (MissingDependencyException $e) {
$this->pass(t('ModuleInstaller::install() throws an exception if dependencies are missing.'));
}

View file

@ -0,0 +1,156 @@
<?php
namespace Drupal\Tests\system\Kernel\Token;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Render\BubbleableMetadata;
/**
* Generates text using placeholders for dummy content to check token
* replacement.
*
* @group system
*/
class TokenReplaceKernelTest extends TokenReplaceKernelTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Set the site name to something other than an empty string.
$this->config('system.site')->set('name', 'Drupal')->save();
}
/**
* Test whether token-replacement works in various contexts.
*/
public function testSystemTokenRecognition() {
// Generate prefixes and suffixes for the token context.
$tests = array(
array('prefix' => 'this is the ', 'suffix' => ' site'),
array('prefix' => 'this is the', 'suffix' => 'site'),
array('prefix' => '[', 'suffix' => ']'),
array('prefix' => '', 'suffix' => ']]]'),
array('prefix' => '[[[', 'suffix' => ''),
array('prefix' => ':[:', 'suffix' => '--]'),
array('prefix' => '-[-', 'suffix' => ':]:'),
array('prefix' => '[:', 'suffix' => ']'),
array('prefix' => '[site:', 'suffix' => ':name]'),
array('prefix' => '[site:', 'suffix' => ']'),
);
// Check if the token is recognized in each of the contexts.
foreach ($tests as $test) {
$input = $test['prefix'] . '[site:name]' . $test['suffix'];
$expected = $test['prefix'] . 'Drupal' . $test['suffix'];
$output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->getId()));
$this->assertTrue($output == $expected, format_string('Token recognized in string %string', array('%string' => $input)));
}
// Test token replacement when the string contains no tokens.
$this->assertEqual($this->tokenService->replace('No tokens here.'), 'No tokens here.');
}
/**
* Tests the clear parameter.
*/
public function testClear() {
// Valid token.
$source = '[site:name]';
// No user passed in, should be untouched.
$source .= '[user:name]';
// Non-existing token.
$source .= '[bogus:token]';
// Replace with the clear parameter, only the valid token should remain.
$target = Html::escape($this->config('system.site')->get('name'));
$result = $this->tokenService->replace($source, array(), array('langcode' => $this->interfaceLanguage->getId(), 'clear' => TRUE));
$this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.');
$target .= '[user:name]';
$target .= '[bogus:token]';
$result = $this->tokenService->replace($source, array(), array('langcode' => $this->interfaceLanguage->getId()));
$this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.');
}
/**
* Tests the generation of all system site information tokens.
*/
public function testSystemSiteTokenReplacement() {
$url_options = array(
'absolute' => TRUE,
'language' => $this->interfaceLanguage,
);
$slogan = '<blink>Slogan</blink>';
$safe_slogan = Xss::filterAdmin($slogan);
// Set a few site variables.
$config = $this->config('system.site');
$config
->set('name', '<strong>Drupal<strong>')
->set('slogan', $slogan)
->set('mail', 'simpletest@example.com')
->save();
// Generate and test tokens.
$tests = array();
$tests['[site:name]'] = Html::escape($config->get('name'));
$tests['[site:slogan]'] = $safe_slogan;
$tests['[site:mail]'] = $config->get('mail');
$tests['[site:url]'] = \Drupal::url('<front>', [], $url_options);
$tests['[site:url-brief]'] = preg_replace(array('!^https?://!', '!/$!'), '', \Drupal::url('<front>', [], $url_options));
$tests['[site:login-url]'] = \Drupal::url('user.page', [], $url_options);
$base_bubbleable_metadata = new BubbleableMetadata();
$metadata_tests = [];
$metadata_tests['[site:name]'] = BubbleableMetadata::createFromObject(\Drupal::config('system.site'));
$metadata_tests['[site:slogan]'] = BubbleableMetadata::createFromObject(\Drupal::config('system.site'));
$metadata_tests['[site:mail]'] = BubbleableMetadata::createFromObject(\Drupal::config('system.site'));
$bubbleable_metadata = clone $base_bubbleable_metadata;
$metadata_tests['[site:url]'] = $bubbleable_metadata->addCacheContexts(['url.site']);
$metadata_tests['[site:url-brief]'] = $bubbleable_metadata;
$metadata_tests['[site:login-url]'] = $bubbleable_metadata;
// Test to make sure that we generated something for each token.
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
foreach ($tests as $input => $expected) {
$bubbleable_metadata = new BubbleableMetadata();
$output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->getId()), $bubbleable_metadata);
$this->assertEqual($output, $expected, new FormattableMarkup('System site information token %token replaced.', ['%token' => $input]));
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
}
}
/**
* Tests the generation of all system date tokens.
*/
public function testSystemDateTokenReplacement() {
// Set time to one hour before request.
$date = REQUEST_TIME - 3600;
// Generate and test tokens.
$tests = array();
$date_formatter = \Drupal::service('date.formatter');
$tests['[date:short]'] = $date_formatter->format($date, 'short', '', NULL, $this->interfaceLanguage->getId());
$tests['[date:medium]'] = $date_formatter->format($date, 'medium', '', NULL, $this->interfaceLanguage->getId());
$tests['[date:long]'] = $date_formatter->format($date, 'long', '', NULL, $this->interfaceLanguage->getId());
$tests['[date:custom:m/j/Y]'] = $date_formatter->format($date, 'custom', 'm/j/Y', NULL, $this->interfaceLanguage->getId());
$tests['[date:since]'] = $date_formatter->formatTimeDiffSince($date, array('langcode' => $this->interfaceLanguage->getId()));
$tests['[date:raw]'] = Xss::filter($date);
// Test to make sure that we generated something for each token.
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
foreach ($tests as $input => $expected) {
$output = $this->tokenService->replace($input, array('date' => $date), array('langcode' => $this->interfaceLanguage->getId()));
$this->assertEqual($output, $expected, format_string('Date token %token replaced.', array('%token' => $input)));
}
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace Drupal\Tests\system\Kernel\Token;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
/**
* Base class for token replacement tests.
*/
abstract class TokenReplaceKernelTestBase extends EntityKernelTestBase {
/**
* The interface language.
*
* @var \Drupal\Core\Language\LanguageInterface
*/
protected $interfaceLanguage;
/**
* Token service.
*
* @var \Drupal\Core\Utility\Token
*/
protected $tokenService;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('system');
protected function setUp() {
parent::setUp();
// Install default system configuration.
$this->installConfig(array('system'));
\Drupal::service('router.builder')->rebuild();
$this->interfaceLanguage = \Drupal::languageManager()->getCurrentLanguage();
$this->tokenService = \Drupal::token();
}
}

View file

@ -142,7 +142,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
$breadcrumb = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals([], $breadcrumb->getLinks());
$this->assertEquals(['url.path'], $breadcrumb->getCacheContexts());
$this->assertEquals(['url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
@ -159,7 +159,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
$breadcrumb = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals([0 => new Link('Home', new Url('<front>'))], $breadcrumb->getLinks());
$this->assertEquals(['url.path'], $breadcrumb->getCacheContexts());
$this->assertEquals(['url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
@ -194,7 +194,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
$breadcrumb = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals([0 => new Link('Home', new Url('<front>')), 1 => new Link('Example', new Url('example'))], $breadcrumb->getLinks());
$this->assertEquals(['url.path', 'user.permissions'], $breadcrumb->getCacheContexts());
$this->assertEquals(['url.path.parent', 'user.permissions'], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
@ -245,7 +245,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
new Link('Example', new Url('example')),
new Link('Bar', new Url('example_bar')),
], $breadcrumb->getLinks());
$this->assertEquals(['bar', 'url.path', 'user.permissions'], $breadcrumb->getCacheContexts());
$this->assertEquals(['bar', 'url.path.parent', 'user.permissions'], $breadcrumb->getCacheContexts());
$this->assertEquals(['example'], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
@ -272,7 +272,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
// No path matched, though at least the frontpage is displayed.
$this->assertEquals([0 => new Link('Home', new Url('<front>'))], $breadcrumb->getLinks());
$this->assertEquals(['url.path'], $breadcrumb->getCacheContexts());
$this->assertEquals(['url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
@ -316,7 +316,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
// No path matched, though at least the frontpage is displayed.
$this->assertEquals([0 => new Link('Home', new Url('<front>'))], $breadcrumb->getLinks());
$this->assertEquals(['url.path'], $breadcrumb->getCacheContexts());
$this->assertEquals(['url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
@ -364,7 +364,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
$breadcrumb = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals([0 => new Link('Home', new Url('<front>')), 1 => new Link('Admin', new Url('user_page'))], $breadcrumb->getLinks());
$this->assertEquals(['url.path', 'user.permissions'], $breadcrumb->getCacheContexts());
$this->assertEquals(['url.path.parent', 'user.permissions'], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}

View file

@ -29,7 +29,7 @@ class InstallTranslationFilePatternTest extends UnitTestCase {
parent::setUp();
$this->fileTranslation = new FileTranslation('filename');
$method = new \ReflectionMethod('\Drupal\Core\StringTranslation\Translator\FileTranslation', 'getTranslationFilesPattern');
$method->setAccessible(true);
$method->setAccessible(TRUE);
$this->filePatternMethod = $method;
}

View file

@ -6,12 +6,13 @@ use Drupal\system\SystemRequirements;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass Drupal\system\SystemRequirements
* @coversDefaultClass \Drupal\system\SystemRequirements
* @group system
*/
class SystemRequirementsTest extends UnitTestCase {
/**
* @covers ::phpVersionWithPdoDisallowMultipleStatements
* @dataProvider providerTestPhpVersionWithPdoDisallowMultipleStatements
*/
public function testPhpVersionWithPdoDisallowMultipleStatements($version, $expected) {