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,34 @@
<?php
/**
* @file
* Contains \Drupal\KernelTests\Core\Common\DrupalSetMessageTest.
*/
namespace Drupal\KernelTests\Core\Common;
use Drupal\KernelTests\KernelTestBase;
/**
* @covers ::drupal_set_message
* @group PHPUnit
*/
class DrupalSetMessageTest extends KernelTestBase {
/**
* The basic functionality of drupal_set_message().
*/
public function testDrupalSetMessage() {
drupal_set_message(t('A message: @foo', ['@foo' => 'bar']));
$messages = drupal_get_messages();
$this->assertInstanceOf('Drupal\Core\Render\Markup', $messages['status'][0]);
$this->assertEquals('A message: bar', (string) $messages['status'][0]);
}
public function tearDown() {
// Clear session to prevent global leakage.
unset($_SESSION['messages']);
parent::tearDown();
}
}

View file

@ -0,0 +1,74 @@
<?php
/**
* @file
* Contains \Drupal\KernelTests\Core\StringTranslation\TranslationStringTest.
*/
namespace Drupal\KernelTests\Core\StringTranslation;
use Drupal\Core\Site\Settings;
use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
/**
* Tests the TranslatableMarkup class.
*
* @group StringTranslation
*/
class TranslationStringTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'language'
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
ConfigurableLanguage::createFromLangcode('de')->save();
}
/**
* Tests that TranslatableMarkup objects can be compared.
*/
public function testComparison() {
$this->rebootAndPrepareSettings();
$a = \Drupal::service('string_translation')->translate('Example @number', ['@number' => 42], ['langcode' => 'de']);
$this->rebootAndPrepareSettings();
$b = \Drupal::service('string_translation')->translate('Example @number', ['@number' => 42], ['langcode' => 'de']);
$c = \Drupal::service('string_translation')->translate('Example @number', ['@number' => 43], ['langcode' => 'de']);
$d = \Drupal::service('string_translation')->translate('Example @number', ['@number' => 42], ['langcode' => 'en']);
// The two objects have the same settings so == comparison will work.
$this->assertEquals($a, $b);
// The two objects are not the same object.
$this->assertNotSame($a, $b);
// TranslationWrappers which have different settings are not equal.
$this->assertNotEquals($a, $c);
$this->assertNotEquals($a, $d);
}
/**
* Reboots the kernel to set custom translations in Settings.
*/
protected function rebootAndPrepareSettings() {
// Reboot the container so that different services are injected and the new
// settings are picked.
$kernel = $this->container->get('kernel');
$kernel->shutdown();
$kernel->boot();
$settings = Settings::getAll();
$settings['locale_custom_strings_de'] = ['' => ['Example @number' => 'Example @number translated']];
// Recreate the settings static.
new Settings($settings);
}
}

View file

@ -0,0 +1,93 @@
<?php
/**
* @file
* Contains \Drupal\KernelTests\Core\Theme\ThemeRenderAndAutoescapeTest.
*/
namespace Drupal\KernelTests\Core\Theme;
use Drupal\Component\Utility\Html;
use Drupal\Core\Link;
use Drupal\Core\Render\RenderContext;
use Drupal\Core\Render\Markup;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the theme_render_and_autoescape() function.
*
* @group Theme
*/
class ThemeRenderAndAutoescapeTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', 'router');
\Drupal::service('router.builder')->rebuild();
}
/**
* @dataProvider providerTestThemeRenderAndAutoescape
*/
public function testThemeRenderAndAutoescape($arg, $expected) {
if (is_array($arg) && isset($arg['#type']) && $arg['#type'] === 'link') {
$arg = Link::createFromRoute($arg['#title'], $arg['#url']);
}
$context = new RenderContext();
// Use a closure here since we need to render with a render context.
$theme_render_and_autoescape = function () use ($arg) {
return theme_render_and_autoescape($arg);
};
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$output = $renderer->executeInRenderContext($context, $theme_render_and_autoescape);
$this->assertEquals($expected, $output);
$this-> assertInternalType('string', $output);
}
/**
* Provide test examples.
*/
public function providerTestThemeRenderAndAutoescape() {
return [
'empty string unchanged' => ['', ''],
'simple string unchanged' => ['ab', 'ab'],
'int (scalar) cast to string' => [111, '111'],
'float (scalar) cast to string' => [2.10, '2.10'],
'> is escaped' => ['>', '&gt;'],
'Markup EM tag is unchanged' => [Markup::create('<em>hi</em>'), '<em>hi</em>'],
'Markup SCRIPT tag is unchanged' => [Markup::create('<script>alert("hi");</script>'), '<script>alert("hi");</script>'],
'EM tag in string is escaped' => ['<em>hi</em>', Html::escape('<em>hi</em>')],
'type link render array is rendered' => [['#type' => 'link', '#title' => 'Text', '#url' => '<none>'], '<a href="">Text</a>'],
'type markup with EM tags is rendered' => [['#markup' => '<em>hi</em>'], '<em>hi</em>'],
'SCRIPT tag in string is escaped' => [
'<script>alert(123)</script>',
Html::escape('<script>alert(123)</script>')
],
'type plain_text render array EM tag is escaped' => [['#plain_text' => '<em>hi</em>'], Html::escape('<em>hi</em>')],
'type hidden render array is rendered' => [['#type' => 'hidden', '#name' => 'foo', '#value' => 'bar'], "<input type=\"hidden\" name=\"foo\" value=\"bar\" />\n"],
];
}
/**
* Ensures invalid content is handled correctly.
*
* @expectedException \Exception
*/
public function testThemeEscapeAndRenderNotPrintable() {
theme_render_and_autoescape(new NonPrintable());
}
}
class NonPrintable { }