Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\system\Tests\Theme;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Session\UserSession;
|
||||
use Drupal\Core\Url;
|
||||
|
@ -218,13 +219,13 @@ class FunctionsTest extends WebTestBase {
|
|||
|
||||
$expected_links = '';
|
||||
$expected_links .= '<ul id="somelinks">';
|
||||
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base:a/link')->toString() . '">' . SafeMarkup::checkPlain('A <link>') . '</a></li>';
|
||||
$expected_links .= '<li class="plain-text">' . SafeMarkup::checkPlain('Plain "text"') . '</li>';
|
||||
$expected_links .= '<li class="html-text"><span class="unescaped">' . SafeMarkup::checkPlain('potentially unsafe text that <should> be escaped') . '</span></li>';
|
||||
$expected_links .= '<li class="front-page"><a href="' . Url::fromRoute('<front>')->toString() . '">' . SafeMarkup::checkPlain('Front page') . '</a></li>';
|
||||
$expected_links .= '<li class="router-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '">' . SafeMarkup::checkPlain('Test route') . '</a></li>';
|
||||
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base:a/link')->toString() . '">' . Html::escape('A <link>') . '</a></li>';
|
||||
$expected_links .= '<li class="plain-text">' . Html::escape('Plain "text"') . '</li>';
|
||||
$expected_links .= '<li class="html-text"><span class="unescaped">' . Html::escape('potentially unsafe text that <should> be escaped') . '</span></li>';
|
||||
$expected_links .= '<li class="front-page"><a href="' . Url::fromRoute('<front>')->toString() . '">' . Html::escape('Front page') . '</a></li>';
|
||||
$expected_links .= '<li class="router-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '">' . Html::escape('Test route') . '</a></li>';
|
||||
$query = array('key' => 'value');
|
||||
$expected_links .= '<li class="query-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1', $query) . '">' . SafeMarkup::checkPlain('Query test route') . '</a></li>';
|
||||
$expected_links .= '<li class="query-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1', $query) . '">' . Html::escape('Query test route') . '</a></li>';
|
||||
$expected_links .= '</ul>';
|
||||
|
||||
// Verify that passing a string as heading works.
|
||||
|
@ -258,13 +259,13 @@ class FunctionsTest extends WebTestBase {
|
|||
);
|
||||
$expected_links = '';
|
||||
$expected_links .= '<ul id="somelinks">';
|
||||
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base:a/link')->toString() . '">' . SafeMarkup::checkPlain('A <link>') . '</a></li>';
|
||||
$expected_links .= '<li class="plain-text"><span class="a/class">' . SafeMarkup::checkPlain('Plain "text"') . '</span></li>';
|
||||
$expected_links .= '<li class="html-text"><span class="unescaped">' . SafeMarkup::checkPlain('potentially unsafe text that <should> be escaped') . '</span></li>';
|
||||
$expected_links .= '<li class="front-page"><a href="' . Url::fromRoute('<front>')->toString() . '">' . SafeMarkup::checkPlain('Front page') . '</a></li>';
|
||||
$expected_links .= '<li class="router-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '">' . SafeMarkup::checkPlain('Test route') . '</a></li>';
|
||||
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base:a/link')->toString() . '">' . Html::escape('A <link>') . '</a></li>';
|
||||
$expected_links .= '<li class="plain-text"><span class="a/class">' . Html::escape('Plain "text"') . '</span></li>';
|
||||
$expected_links .= '<li class="html-text"><span class="unescaped">' . Html::escape('potentially unsafe text that <should> be escaped') . '</span></li>';
|
||||
$expected_links .= '<li class="front-page"><a href="' . Url::fromRoute('<front>')->toString() . '">' . Html::escape('Front page') . '</a></li>';
|
||||
$expected_links .= '<li class="router-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '">' . Html::escape('Test route') . '</a></li>';
|
||||
$query = array('key' => 'value');
|
||||
$expected_links .= '<li class="query-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1', $query) . '">' . SafeMarkup::checkPlain('Query test route') . '</a></li>';
|
||||
$expected_links .= '<li class="query-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1', $query) . '">' . Html::escape('Query test route') . '</a></li>';
|
||||
$expected_links .= '</ul>';
|
||||
$expected = $expected_heading . $expected_links;
|
||||
$this->assertThemeOutput('links', $variables, $expected);
|
||||
|
@ -274,14 +275,14 @@ class FunctionsTest extends WebTestBase {
|
|||
$variables['set_active_class'] = TRUE;
|
||||
$expected_links = '';
|
||||
$expected_links .= '<ul id="somelinks">';
|
||||
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base:a/link')->toString() . '">' . SafeMarkup::checkPlain('A <link>') . '</a></li>';
|
||||
$expected_links .= '<li class="plain-text"><span class="a/class">' . SafeMarkup::checkPlain('Plain "text"') . '</span></li>';
|
||||
$expected_links .= '<li class="html-text"><span class="unescaped">' . SafeMarkup::checkPlain('potentially unsafe text that <should> be escaped') . '</span></li>';
|
||||
$expected_links .= '<li data-drupal-link-system-path="<front>" class="front-page"><a href="' . Url::fromRoute('<front>')->toString() . '" data-drupal-link-system-path="<front>">' . SafeMarkup::checkPlain('Front page') . '</a></li>';
|
||||
$expected_links .= '<li data-drupal-link-system-path="router_test/test1" class="router-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '" data-drupal-link-system-path="router_test/test1">' . SafeMarkup::checkPlain('Test route') . '</a></li>';
|
||||
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base:a/link')->toString() . '">' . Html::escape('A <link>') . '</a></li>';
|
||||
$expected_links .= '<li class="plain-text"><span class="a/class">' . Html::escape('Plain "text"') . '</span></li>';
|
||||
$expected_links .= '<li class="html-text"><span class="unescaped">' . Html::escape('potentially unsafe text that <should> be escaped') . '</span></li>';
|
||||
$expected_links .= '<li data-drupal-link-system-path="<front>" class="front-page"><a href="' . Url::fromRoute('<front>')->toString() . '" data-drupal-link-system-path="<front>">' . Html::escape('Front page') . '</a></li>';
|
||||
$expected_links .= '<li data-drupal-link-system-path="router_test/test1" class="router-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '" data-drupal-link-system-path="router_test/test1">' . Html::escape('Test route') . '</a></li>';
|
||||
$query = array('key' => 'value');
|
||||
$encoded_query = SafeMarkup::checkPlain(Json::encode($query));
|
||||
$expected_links .= '<li data-drupal-link-query="'.$encoded_query.'" data-drupal-link-system-path="router_test/test1" class="query-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1', $query) . '" data-drupal-link-query="'.$encoded_query.'" data-drupal-link-system-path="router_test/test1">' . SafeMarkup::checkPlain('Query test route') . '</a></li>';
|
||||
$encoded_query = Html::escape(Json::encode($query));
|
||||
$expected_links .= '<li data-drupal-link-query="'.$encoded_query.'" data-drupal-link-system-path="router_test/test1" class="query-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1', $query) . '" data-drupal-link-query="'.$encoded_query.'" data-drupal-link-system-path="router_test/test1">' . Html::escape('Query test route') . '</a></li>';
|
||||
$expected_links .= '</ul>';
|
||||
$expected = $expected_heading . $expected_links;
|
||||
$this->assertThemeOutput('links', $variables, $expected);
|
||||
|
|
|
@ -99,6 +99,47 @@ class RegistryTest extends KernelTestBase {
|
|||
'template_preprocess',
|
||||
'test_basetheme_preprocess_theme_test_template_test',
|
||||
], $preprocess_functions);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the theme registry with suggestions.
|
||||
*/
|
||||
public function testSuggestionPreprocessFunctions() {
|
||||
$theme_handler = \Drupal::service('theme_handler');
|
||||
$theme_handler->install(['test_theme']);
|
||||
|
||||
$registry_theme = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme');
|
||||
$registry_theme->setThemeManager(\Drupal::theme());
|
||||
|
||||
$suggestions = ['__kitten', '__flamingo'];
|
||||
$expected_preprocess_functions = [
|
||||
'template_preprocess',
|
||||
'theme_test_preprocess_theme_test_preprocess_suggestions',
|
||||
];
|
||||
$suggestion = '';
|
||||
$hook = 'theme_test_preprocess_suggestions';
|
||||
do {
|
||||
$hook .= "$suggestion";
|
||||
$expected_preprocess_functions[] = "test_theme_preprocess_$hook";
|
||||
$preprocess_functions = $registry_theme->get()[$hook]['preprocess functions'];
|
||||
$this->assertIdentical($expected_preprocess_functions, $preprocess_functions, "$hook has correct preprocess functions.");
|
||||
} while ($suggestion = array_shift($suggestions));
|
||||
|
||||
$expected_preprocess_functions = [
|
||||
'template_preprocess',
|
||||
'theme_test_preprocess_theme_test_preprocess_suggestions',
|
||||
'test_theme_preprocess_theme_test_preprocess_suggestions',
|
||||
'test_theme_preprocess_theme_test_preprocess_suggestions__kitten',
|
||||
];
|
||||
|
||||
$preprocess_functions = $registry_theme->get()['theme_test_preprocess_suggestions__kitten__meerkat']['preprocess functions'];
|
||||
$this->assertIdentical($expected_preprocess_functions, $preprocess_functions, 'Suggestion implemented as a function correctly inherits preprocess functions.');
|
||||
|
||||
$preprocess_functions = $registry_theme->get()['theme_test_preprocess_suggestions__kitten__bearcat']['preprocess functions'];
|
||||
$this->assertIdentical($expected_preprocess_functions, $preprocess_functions, 'Suggestion implemented as a template correctly inherits preprocess functions.');
|
||||
|
||||
$this->assertTrue(isset($registry_theme->get()['theme_test_preprocess_suggestions__kitten__meerkat__tarsier__moose']), 'Preprocess function with an unimplemented lower-level suggestion is added to the registry.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,16 +71,17 @@ class ThemeInfoTest extends WebTestBase {
|
|||
// should work nevertheless.
|
||||
$this->drupalGet('theme-test/info/stylesheets');
|
||||
|
||||
$this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$base/base-add.css')]")), "$base/base-add.css found");
|
||||
$this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'base-remove.css')]")), "base-remove.css not found");
|
||||
$this->assertIdentical(1, count($this->xpath('//style[contains(text(), :text)]', array(':text' => "$base/base-add.css"))), "$base/base-add.css found");
|
||||
$this->assertIdentical(0, count($this->xpath('//style[contains(text(), :text)]', array(':text' => "base-remove.css"))), "base-remove.css not found");
|
||||
|
||||
$this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$sub/sub-add.css')]")), "$sub/sub-add.css found");
|
||||
$this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'sub-remove.css')]")), "sub-remove.css not found");
|
||||
$this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'base-add.sub-remove.css')]")), "base-add.sub-remove.css not found");
|
||||
$this->assertIdentical(1, count($this->xpath('//style[contains(text(), :text)]', array(':text' => "$sub/sub-add.css"))), "$sub/sub-add.css found");
|
||||
$this->assertIdentical(0, count($this->xpath('//style[contains(text(), :text)]', array(':text' => "sub-remove.css"))), "sub-remove.css not found");
|
||||
$this->assertIdentical(0, count($this->xpath('//style[contains(text(), :text)]', array(':text' => "base-add.sub-remove.css"))), "base-add.sub-remove.css not found");
|
||||
|
||||
// Verify that CSS files with the same name are loaded from both the base theme and subtheme.
|
||||
$this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$base/samename.css')]")), "$base/samename.css found");
|
||||
$this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$sub/samename.css')]")), "$sub/samename.css found");
|
||||
$this->assertIdentical(1, count($this->xpath('//style[contains(text(), :text)]', array(':text' => "$base/samename.css"))), "$base/samename.css found");
|
||||
$this->assertIdentical(1, count($this->xpath('//style[contains(text(), :text)]', array(':text' => "$sub/samename.css"))), "$sub/samename.css found");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,6 +13,7 @@ use Drupal\test_theme\ThemeClass;
|
|||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Drupal\Component\Utility\SafeStringInterface;
|
||||
|
||||
/**
|
||||
* Tests low-level theme functions.
|
||||
|
@ -59,12 +60,19 @@ class ThemeTest extends WebTestBase {
|
|||
* Test that _theme() returns expected data types.
|
||||
*/
|
||||
function testThemeDataTypes() {
|
||||
// theme_test_false is an implemented theme hook so \Drupal::theme() service should
|
||||
// return a string, even though the theme function itself can return anything.
|
||||
$foos = array('null' => NULL, 'false' => FALSE, 'integer' => 1, 'string' => 'foo');
|
||||
// theme_test_false is an implemented theme hook so \Drupal::theme() service
|
||||
// should return a string or an object that implements SafeStringInterface,
|
||||
// even though the theme function itself can return anything.
|
||||
$foos = array('null' => NULL, 'false' => FALSE, 'integer' => 1, 'string' => 'foo', 'empty_string' => '');
|
||||
foreach ($foos as $type => $example) {
|
||||
$output = \Drupal::theme()->render('theme_test_foo', array('foo' => $example));
|
||||
$this->assertTrue(is_string($output), format_string('\Drupal::theme() returns a string for data type !type.', array('!type' => $type)));
|
||||
$this->assertTrue($output instanceof SafeStringInterface || is_string($output), format_string('\Drupal::theme() returns an object that implements SafeStringInterface or a string for data type !type.', array('!type' => $type)));
|
||||
if ($output instanceof SafeStringInterface) {
|
||||
$this->assertIdentical((string) $example, $output->__toString());
|
||||
}
|
||||
elseif (is_string($output)) {
|
||||
$this->assertIdentical($output, '', 'A string will be return when the theme returns an empty string.');
|
||||
}
|
||||
}
|
||||
|
||||
// suggestionnotimplemented is not an implemented theme hook so \Drupal::theme() service
|
||||
|
@ -277,7 +285,7 @@ class ThemeTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that region attributes can be manipulated via preprocess functions.
|
||||
*/
|
||||
function testRegionClass() {
|
||||
public function testRegionClass() {
|
||||
\Drupal::service('module_installer')->install(array('block', 'theme_region_test'));
|
||||
|
||||
// Place a block.
|
||||
|
@ -287,4 +295,31 @@ class ThemeTest extends WebTestBase {
|
|||
$this->assertEqual(count($elements), 1, 'New class found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures suggestion preprocess functions run for default implementations.
|
||||
*
|
||||
* The theme hook used by this test has its base preprocess function in a
|
||||
* separate file, so this test also ensures that that file is correctly loaded
|
||||
* when needed.
|
||||
*/
|
||||
public function testSuggestionPreprocessForDefaults() {
|
||||
\Drupal::service('theme_handler')->setDefault('test_theme');
|
||||
// Test with both an unprimed and primed theme registry.
|
||||
drupal_theme_rebuild();
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$this->drupalGet('theme-test/preprocess-suggestions');
|
||||
$items = $this->cssSelect('.suggestion');
|
||||
$expected_values = [
|
||||
'Suggestion',
|
||||
'Kitten',
|
||||
'Monkey',
|
||||
'Kitten',
|
||||
'Flamingo',
|
||||
];
|
||||
foreach ($expected_values as $key => $value) {
|
||||
$this->assertEqual((string) $value, $items[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\system\Tests\Theme;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
|
||||
|
@ -44,7 +44,7 @@ class TwigEnvironmentTest extends KernelTestBase {
|
|||
'#template' => 'test-with-context <label>{{ unsafe_content }}</label>',
|
||||
'#context' => array('unsafe_content' => $unsafe_string),
|
||||
);
|
||||
$this->assertEqual($renderer->renderRoot($element), 'test-with-context <label>' . SafeMarkup::checkPlain($unsafe_string) . '</label>');
|
||||
$this->assertEqual($renderer->renderRoot($element), 'test-with-context <label>' . Html::escape($unsafe_string) . '</label>');
|
||||
|
||||
// Enable twig_auto_reload and twig_debug.
|
||||
$settings = Settings::getAll();
|
||||
|
@ -83,5 +83,25 @@ class TwigEnvironmentTest extends KernelTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that cacheFilename() varies by extensions + deployment identifier.
|
||||
*/
|
||||
public function testCacheFilename() {
|
||||
/** @var \Drupal\Core\Template\TwigEnvironment $environment */
|
||||
// Note: Later we refetch the twig service in order to bypass its internal
|
||||
// static cache.
|
||||
$environment = \Drupal::service('twig');
|
||||
|
||||
$original_filename = $environment->getCacheFilename('core/modules/system/templates/container.html.twig');
|
||||
\Drupal::getContainer()->set('twig', NULL);
|
||||
|
||||
\Drupal::service('module_installer')->install(['twig_extension_test']);
|
||||
$environment = \Drupal::service('twig');
|
||||
$new_extension_filename = $environment->getCacheFilename('core/modules/system/templates/container.html.twig');
|
||||
\Drupal::getContainer()->set('twig', NULL);
|
||||
|
||||
$this->assertNotEqual($new_extension_filename, $original_filename);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ class TwigExtensionTest extends WebTestBase {
|
|||
|
||||
$this->drupalGet('twig-extension-test/filter');
|
||||
$this->assertText('Every plant is not a mineral.', 'Success: String filtered.');
|
||||
// Test safe_join filter.
|
||||
$this->assertRaw('<em>will be escaped</em><br/><em>will be markup</em><br/><strong>will be rendered</strong>');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue