Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,366 @@
<?php
/**
* @file
* Contains \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest.
*/
namespace Drupal\Tests\system\Unit\Breadcrumbs;
use Drupal\Core\Link;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
use Drupal\Core\Utility\LinkGeneratorInterface;
use Drupal\system\PathBasedBreadcrumbBuilder;
use Drupal\Tests\UnitTestCase;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
/**
* @coversDefaultClass \Drupal\system\PathBasedBreadcrumbBuilder
* @group system
*/
class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
/**
* The path based breadcrumb builder object to test.
*
* @var \Drupal\system\PathBasedBreadcrumbBuilder
*/
protected $builder;
/**
* The mocked title resolver.
*
* @var \Drupal\Core\Controller\TitleResolverInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $titleResolver;
/**
* The mocked access manager.
*
* @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $accessManager;
/**
* The request matching mock object.
*
* @var \Symfony\Component\Routing\Matcher\RequestMatcherInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $requestMatcher;
/**
* The mocked route request context.
*
* @var \Drupal\Core\Routing\RequestContext|\PHPUnit_Framework_MockObject_MockObject
*/
protected $context;
/**
* The mocked current user.
*
* @var \Drupal\Core\Session\AccountInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $currentUser;
/**
* The mocked path processor.
*
* @var \Drupal\Core\PathProcessor\InboundPathProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $pathProcessor;
/**
* The mocked current path.
*
* @var \Drupal\Core\Path\CurrentPathStack|\PHPUnit_Framework_MockObject_MockObject
*/
protected $currentPath;
/**
* {@inheritdoc}
*
* @covers ::__construct
*/
protected function setUp() {
parent::setUp();
$this->requestMatcher = $this->getMock('\Symfony\Component\Routing\Matcher\RequestMatcherInterface');
$config_factory = $this->getConfigFactoryStub(array('system.site' => array('front' => 'test_frontpage')));
$this->pathProcessor = $this->getMock('\Drupal\Core\PathProcessor\InboundPathProcessorInterface');
$this->context = $this->getMock('\Drupal\Core\Routing\RequestContext');
$this->accessManager = $this->getMock('\Drupal\Core\Access\AccessManagerInterface');
$this->titleResolver = $this->getMock('\Drupal\Core\Controller\TitleResolverInterface');
$this->currentUser = $this->getMock('Drupal\Core\Session\AccountInterface');
$this->currentPath = $this->getMockBuilder('Drupal\Core\Path\CurrentPathStack')
->disableOriginalConstructor()
->getMock();
$this->builder = new TestPathBasedBreadcrumbBuilder(
$this->context,
$this->accessManager,
$this->requestMatcher,
$this->pathProcessor,
$config_factory,
$this->titleResolver,
$this->currentUser,
$this->currentPath
);
$this->builder->setStringTranslation($this->getStringTranslationStub());
}
/**
* Tests the build method on the frontpage.
*
* @covers ::build
*/
public function testBuildOnFrontpage() {
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/'));
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals(array(), $links);
}
/**
* Tests the build method with one path element.
*
* @covers ::build
*/
public function testBuildWithOnePathElement() {
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/example'));
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals(array(0 => new Link('Home', new Url('<front>'))), $links);
}
/**
* Tests the build method with two path elements.
*
* @covers ::build
* @covers ::getRequestForPath
*/
public function testBuildWithTwoPathElements() {
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/example/baz'));
$this->setupStubPathProcessor();
$route_1 = new Route('/example');
$this->requestMatcher->expects($this->exactly(1))
->method('matchRequest')
->will($this->returnCallback(function(Request $request) use ($route_1) {
if ($request->getPathInfo() == '/example') {
return array(
RouteObjectInterface::ROUTE_NAME => 'example',
RouteObjectInterface::ROUTE_OBJECT => $route_1,
'_raw_variables' => new ParameterBag(array()),
);
}
}));
$this->setupAccessManagerToAllow();
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals(array(0 => new Link('Home', new Url('<front>')), 1 => new Link('Example', new Url('example'))), $links);
}
/**
* Tests the build method with three path elements.
*
* @covers ::build
* @covers ::getRequestForPath
*/
public function testBuildWithThreePathElements() {
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/example/bar/baz'));
$this->setupStubPathProcessor();
$route_1 = new Route('/example/bar');
$route_2 = new Route('/example');
$this->requestMatcher->expects($this->exactly(2))
->method('matchRequest')
->will($this->returnCallback(function(Request $request) use ($route_1, $route_2) {
if ($request->getPathInfo() == '/example/bar') {
return array(
RouteObjectInterface::ROUTE_NAME => 'example_bar',
RouteObjectInterface::ROUTE_OBJECT => $route_1,
'_raw_variables' => new ParameterBag(array()),
);
}
elseif ($request->getPathInfo() == '/example') {
return array(
RouteObjectInterface::ROUTE_NAME => 'example',
RouteObjectInterface::ROUTE_OBJECT => $route_2,
'_raw_variables' => new ParameterBag(array()),
);
}
}));
$this->setupAccessManagerToAllow();
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals(array(
new Link('Home', new Url('<front>')),
new Link('Example', new Url('example')),
new Link('Bar', new Url('example_bar')),
), $links);
}
/**
* Tests that exceptions during request matching are caught.
*
* @covers ::build
* @covers ::getRequestForPath
*
* @dataProvider providerTestBuildWithException
*/
public function testBuildWithException($exception_class, $exception_argument) {
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/example/bar'));
$this->setupStubPathProcessor();
$this->requestMatcher->expects($this->any())
->method('matchRequest')
->will($this->throwException(new $exception_class($exception_argument)));
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
// No path matched, though at least the frontpage is displayed.
$this->assertEquals(array(0 => new Link('Home', new Url('<front>'))), $links);
}
/**
* Provides exception types for testBuildWithException.
*
* @return array
* The list of exception test cases.
*
* @see \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithException()
*/
public function providerTestBuildWithException() {
return array(
array('Drupal\Core\ParamConverter\ParamNotConvertedException', ''),
array('Symfony\Component\Routing\Exception\MethodNotAllowedException', array()),
array('Symfony\Component\Routing\Exception\ResourceNotFoundException', ''),
);
}
/**
* Tests the build method with a non processed path.
*
* @covers ::build
* @covers ::getRequestForPath
*/
public function testBuildWithNonProcessedPath() {
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/example/bar'));
$this->pathProcessor->expects($this->once())
->method('processInbound')
->will($this->returnValue(FALSE));
$this->requestMatcher->expects($this->any())
->method('matchRequest')
->will($this->returnValue(array()));
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
// No path matched, though at least the frontpage is displayed.
$this->assertEquals(array(0 => new Link('Home', new Url('<front>'))), $links);
}
/**
* Tests the applied method.
*
* @covers ::applies
*/
public function testApplies() {
$this->assertTrue($this->builder->applies($this->getMock('Drupal\Core\Routing\RouteMatchInterface')));
}
/**
* Tests the breadcrumb for a user path.
*
* @covers ::build
* @covers ::getRequestForPath
*/
public function testBuildWithUserPath() {
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/user/1/edit'));
$this->setupStubPathProcessor();
$route_1 = new Route('/user/1');
$this->requestMatcher->expects($this->exactly(1))
->method('matchRequest')
->will($this->returnCallback(function(Request $request) use ($route_1) {
if ($request->getPathInfo() == '/user/1') {
return array(
RouteObjectInterface::ROUTE_NAME => 'user_page',
RouteObjectInterface::ROUTE_OBJECT => $route_1,
'_raw_variables' => new ParameterBag(array()),
);
}
}));
$this->setupAccessManagerToAllow();
$this->titleResolver->expects($this->once())
->method('getTitle')
->with($this->anything(), $route_1)
->will($this->returnValue('Admin'));
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals(array(0 => new Link('Home', new Url('<front>')), 1 => new Link('Admin', new Url('user_page'))), $links);
}
/**
* Setup the access manager to always allow access to routes.
*/
public function setupAccessManagerToAllow() {
$this->accessManager->expects($this->any())
->method('check')
->willReturn(TRUE);
}
protected function setupStubPathProcessor() {
$this->pathProcessor->expects($this->any())
->method('processInbound')
->will($this->returnArgument(0));
}
}
/**
* Helper class for testing purposes only.
*/
class TestPathBasedBreadcrumbBuilder extends PathBasedBreadcrumbBuilder {
public function setStringTranslation(TranslationInterface $string_translation) {
$this->stringTranslation = $string_translation;
}
public function setLinkGenerator(LinkGeneratorInterface $link_generator) {
$this->linkGenerator = $link_generator;
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* @file
* Contains \Drupal\Tests\system\Unit\Installer\InstallTranslationFilePatternTest.
*/
namespace Drupal\Tests\system\Unit\Installer;
use Drupal\Core\StringTranslation\Translator\FileTranslation;
use Drupal\Tests\UnitTestCase;
/**
* Tests for installer language support.
*
* @group Installer
*/
class InstallTranslationFilePatternTest extends UnitTestCase {
/**
* @var \Drupal\Core\StringTranslation\Translator\FileTranslation
*/
protected $fileTranslation;
/**
* @var \ReflectionMethod
*/
protected $filePatternMethod;
/**
* {@inheritdoc}
*/
protected function setup() {
parent::setUp();
$this->fileTranslation = new FileTranslation('filename');
$method = new \ReflectionMethod('\Drupal\Core\StringTranslation\Translator\FileTranslation', 'getTranslationFilesPattern');
$method->setAccessible(true);
$this->filePatternMethod = $method;
}
/**
* @dataProvider providerValidTranslationFiles
*/
public function testFilesPatternValid($langcode, $filename) {
$pattern = $this->filePatternMethod->invoke($this->fileTranslation, $langcode);
$this->assertNotEmpty(preg_match($pattern, $filename));
}
/**
* @return array
*/
public function providerValidTranslationFiles() {
return array(
array('hu', 'drupal-8.0.0-alpha1.hu.po'),
array('ta', 'drupal-8.10.10-beta12.ta.po'),
array('hi', 'drupal-8.0.0.hi.po'),
);
}
/**
* @dataProvider providerInvalidTranslationFiles
*/
public function testFilesPatternInvalid($langcode, $filename) {
$pattern = $this->filePatternMethod->invoke($this->fileTranslation, $langcode);
$this->assertEmpty(preg_match($pattern, $filename));
}
/**
* @return array
*/
public function providerInvalidTranslationFiles() {
return array(
array('hu', 'drupal-alpha1-*-hu.po'),
array('ta', 'drupal-beta12.ta'),
array('hi', 'drupal-hi.po'),
array('de', 'drupal-dummy-de.po'),
array('hu', 'drupal-10.0.1.alpha1-hu.po'),
);
}
}

View file

@ -0,0 +1,261 @@
<?php
/**
* @file
* Contains \Drupal\Tests\system\Unit\Menu\MenuLinkTreeTest.
*/
namespace Drupal\Tests\system\Unit\Menu;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\Cache;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Menu\MenuLinkTree;
use Drupal\Core\Menu\MenuLinkTreeElement;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Url;
use Drupal\Tests\Core\Menu\MenuLinkMock;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Core\Menu\MenuLinkTree
* @group Menu
*/
class MenuLinkTreeTest extends UnitTestCase {
/**
* The tested menu link tree service.
*
* @var \Drupal\Core\Menu\MenuLinkTree
*/
protected $menuLinkTree;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->menuLinkTree = new MenuLinkTree(
$this->getMock('\Drupal\Core\Menu\MenuTreeStorageInterface'),
$this->getMock('\Drupal\Core\Menu\MenuLinkManagerInterface'),
$this->getMock('\Drupal\Core\Routing\RouteProviderInterface'),
$this->getMock('\Drupal\Core\Menu\MenuActiveTrailInterface'),
$this->getMock('\Drupal\Core\Controller\ControllerResolverInterface')
);
$cache_contexts_manager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager')
->disableOriginalConstructor()
->getMock();
$container = new ContainerBuilder();
$container->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container);
}
/**
* @covers ::build
*
* MenuLinkTree::build() gathers both:
* 1. the tree's access cacheability: the cacheability of the access result
* of checking a link in a menu tree's access. Callers can opt out of
* this by MenuLinkTreeElement::access to NULL (the default) value, in
* which case the menu link is always visible. Only when an
* AccessResultInterface object is specified, we gather this cacheability
* metadata.
* This means there are three cases:
* a. no access result (NULL): menu link is visible
* b. AccessResultInterface object that is allowed: menu link is visible
* c. AccessResultInterface object that is not allowed: menu link is
* invisible, but cacheability metadata is still applicable
* 2. the tree's menu links' cacheability: the cacheability of a menu link
* itself, because it may be dynamic. For this reason, MenuLinkInterface
* extends CacheableDependencyInterface. It allows any menu link plugin to
* mark itself as uncacheable (max-age=0) or dynamic (by specifying cache
* tags and/or contexts), to indicate the extent of dynamism.
* This means there are two cases:
* a. permanently cacheable, no cache tags, no cache contexts
* b. anything else: non-permanently cacheable, and/or cache tags, and/or
* cache contexts.
*
* Finally, there are four important shapes of trees, all of which we want to
* test:
* 1. the empty tree
* 2. a single-element tree
* 3. a single-level tree (>1 element; just 1 element is case 2)
* 4. a multi-level tree
*
* The associated data provider aims to test the handling of both of these
* types of cacheability, and for all four tree shapes, for each of the types
* of values for the two types of cacheability.
*
* There is another level of cacheability involved when actually rendering
* built menu trees (i.e. when invoking RendererInterface::render() on the
* return value of MenuLinkTreeInterface::build()): the cacheability of the
* generated URLs.
* Fortunately, that doesn't need additional test coverage here because that
* cacheability is handled at the level of the Renderer (i.e. menu.html.twig
* template's link() function invocation). It also has its own test coverage.
*
* @see \Drupal\menu_link_content\Tests\MenuLinkContentCacheabilityBubblingTest
*
* @dataProvider providerTestBuildCacheability
*/
public function testBuildCacheability($description, $tree, $expected_build) {
$build = $this->menuLinkTree->build($tree);
sort($expected_build['#cache']['contexts']);
$this->assertEquals($expected_build, $build, $description);
}
/**
* Provides the test cases to test for ::testBuildCacheability().
*
* As explained in the documentation for ::testBuildCacheability(), this
* generates 1 + (3 * 2 * 3) = 19 test cases.
*
* @see testBuildCacheability
*/
public function providerTestBuildCacheability() {
$base_expected_build_empty = [
'#cache' => [
'contexts' => [],
'tags' => [],
'max-age' => Cache::PERMANENT,
],
];
$base_expected_build = [
'#cache' => [
'contexts' => [],
'tags' => [
'config:system.menu.mock',
],
'max-age' => Cache::PERMANENT,
],
'#sorted' => TRUE,
'#theme' => 'menu__mock',
'#items' => [
// To be filled when generating test cases, using $get_built_element().
]
];
$get_built_element = function(MenuLinkTreeElement $element, array $classes) {
return [
'attributes' => new Attribute(['class' => array_merge(['menu-item'], $classes)]),
'title' => $element->link->getTitle(),
'url' => new Url($element->link->getRouteName(), $element->link->getRouteParameters(), ['set_active_class' => TRUE]),
'below' => [],
'original_link' => $element->link,
];
};
// The three access scenarios described in this method's documentation.
$access_scenarios = [
[NULL, []],
[AccessResult::allowed(), ['access:allowed']],
[AccessResult::neutral(), ['access:neutral']],
];
// The two links scenarios described in this method's documentation.
$cache_defaults = ['cache_max_age' => Cache::PERMANENT, 'cache_tags' => []];
$links_scenarios = [
[
MenuLinkMock::create(['id' => 'test.example1', 'route_name' => 'example1', 'title' => 'Example 1']),
MenuLinkMock::create(['id' => 'test.example2', 'route_name' => 'example1', 'title' => 'Example 2', 'metadata' => ['cache_contexts' => ['llama']] + $cache_defaults]),
],
[
MenuLinkMock::create(['id' => 'test.example1', 'route_name' => 'example1', 'title' => 'Example 1', 'metadata' => ['cache_contexts' => ['foo']] + $cache_defaults]),
MenuLinkMock::create(['id' => 'test.example2', 'route_name' => 'example1', 'title' => 'Example 2', 'metadata' => ['cache_contexts' => ['bar']] + $cache_defaults]),
],
];
$data = [];
// Empty tree.
$data[] = [
'description' => 'Empty tree.',
'tree' => [],
'expected_build' => $base_expected_build_empty,
];
for ($i = 0; $i < count($access_scenarios); $i++) {
list($access, $access_cache_contexts) = $access_scenarios[$i];
if ($access !== NULL) {
$access->addCacheContexts($access_cache_contexts);
}
for ($j = 0; $j < count($links_scenarios); $j++) {
$links = $links_scenarios[$j];
// Single-element tree.
$tree = [
new MenuLinkTreeElement($links[0], FALSE, 0, FALSE, []),
];
$tree[0]->access = $access;
if ($access === NULL || $access->isAllowed()) {
$expected_build = $base_expected_build;
$expected_build['#items']['test.example1'] = $get_built_element($tree[0], []);
}
else {
$expected_build = $base_expected_build_empty;
}
$expected_build['#cache']['contexts'] = array_merge($expected_build['#cache']['contexts'], $access_cache_contexts, $links[0]->getCacheContexts());
$data[] = [
'description' => "Single-item tree; access=$i; link=$j.",
'tree' => $tree,
'expected_build' => $expected_build,
];
// Single-level tree.
$tree = [
new MenuLinkTreeElement($links[0], FALSE, 0, FALSE, []),
new MenuLinkTreeElement($links[1], FALSE, 0, FALSE, []),
];
$tree[0]->access = $access;
$expected_build = $base_expected_build;
if ($access === NULL || $access->isAllowed()) {
$expected_build['#items']['test.example1'] = $get_built_element($tree[0], []);
}
$expected_build['#items']['test.example2'] = $get_built_element($tree[1], []);
$expected_build['#cache']['contexts'] = array_merge($expected_build['#cache']['contexts'], $access_cache_contexts, $links[0]->getCacheContexts(), $links[1]->getCacheContexts());
$data[] = [
'description' => "Single-level tree; access=$i; link=$j.",
'tree' => $tree,
'expected_build' => $expected_build,
];
// Multi-level tree.
$multi_level_root_a = MenuLinkMock::create(['id' => 'test.roota', 'route_name' => 'roota', 'title' => 'Root A']);
$multi_level_root_b = MenuLinkMock::create(['id' => 'test.rootb', 'route_name' => 'rootb', 'title' => 'Root B']);
$multi_level_parent_c = MenuLinkMock::create(['id' => 'test.parentc', 'route_name' => 'parentc', 'title' => 'Parent C']);
$tree = [
new MenuLinkTreeElement($multi_level_root_a, TRUE, 0, FALSE, [
new MenuLinkTreeElement($multi_level_parent_c, TRUE, 0, FALSE, [
new MenuLinkTreeElement($links[0], FALSE, 0, FALSE, []),
])
]),
new MenuLinkTreeElement($multi_level_root_b, TRUE, 0, FALSE, [
new MenuLinkTreeElement($links[1], FALSE, 1, FALSE, [])
]),
];
$tree[0]->subtree[0]->subtree[0]->access = $access;
$expected_build = $base_expected_build;
$expected_build['#items']['test.roota'] = $get_built_element($tree[0], ['menu-item--expanded']);
$expected_build['#items']['test.roota']['below']['test.parentc'] = $get_built_element($tree[0]->subtree[0], ['menu-item--expanded']);
if ($access === NULL || $access->isAllowed()) {
$expected_build['#items']['test.roota']['below']['test.parentc']['below']['test.example1'] = $get_built_element($tree[0]->subtree[0]->subtree[0], []);
}
$expected_build['#items']['test.rootb'] = $get_built_element($tree[1], ['menu-item--expanded']);
$expected_build['#items']['test.rootb']['below']['test.example2'] = $get_built_element($tree[1]->subtree[0], []);
$expected_build['#cache']['contexts'] = array_merge($expected_build['#cache']['contexts'], $access_cache_contexts, $links[0]->getCacheContexts(), $links[1]->getCacheContexts());
$data[] = [
'description' => "Multi-level tree; access=$i; link=$j.",
'tree' => $tree,
'expected_build' => $expected_build,
];
}
}
return $data;
}
}

View file

@ -0,0 +1,72 @@
<?php
/**
* @file
* Contains \Drupal\Tests\system\Unit\Menu\SystemLocalTasksTest.
*/
namespace Drupal\Tests\system\Unit\Menu;
use Drupal\Core\Extension\Extension;
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
/**
* Tests existence of system local tasks.
*
* @group system
*/
class SystemLocalTasksTest extends LocalTaskIntegrationTestBase {
/**
* The mocked theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $themeHandler;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->directoryList = array(
'system' => 'core/modules/system',
);
$this->themeHandler = $this->getMock('Drupal\Core\Extension\ThemeHandlerInterface');
$theme = new Extension($this->root, 'theme', '/core/themes/bartik', 'bartik.info.yml');
$theme->status = 1;
$theme->info = array('name' => 'bartik');
$this->themeHandler->expects($this->any())
->method('listInfo')
->will($this->returnValue(array(
'bartik' => $theme,
)));
$this->container->set('theme_handler', $this->themeHandler);
}
/**
* Tests local task existence.
*
* @dataProvider getSystemAdminRoutes
*/
public function testSystemAdminLocalTasks($route, $expected) {
$this->assertLocalTasks($route, $expected);
}
/**
* Provides a list of routes to test.
*/
public function getSystemAdminRoutes() {
return array(
array('system.admin_content', array(array('system.admin_content'))),
array('system.theme_settings_theme', array(
array('system.themes_page', 'system.theme_settings'),
array('system.theme_settings_global', 'system.theme_settings_theme:bartik'),
)),
);
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
* @file
* Contains \Drupal\Tests\system\Unit\SystemRequirementsTest.
*/
namespace Drupal\Tests\system\Unit;
use Drupal\system\SystemRequirements;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass Drupal\system\SystemRequirements
* @group system
*/
class SystemRequirementsTest extends UnitTestCase {
/**
* @dataProvider providerTestPhpVersionWithPdoDisallowMultipleStatements
*/
public function testPhpVersionWithPdoDisallowMultipleStatements($version, $expected) {
$this->assertEquals($expected, SystemRequirements::phpVersionWithPdoDisallowMultipleStatements($version));
}
public function providerTestPhpVersionWithPdoDisallowMultipleStatements() {
$data = [];
$data[] = ['5.4.2', FALSE];
$data[] = ['5.4.21', FALSE];
$data[] = ['5.5.9', FALSE];
$data[] = ['5.5.20', FALSE];
$data[] = ['5.5.21', TRUE];
$data[] = ['5.5.30', TRUE];
$data[] = ['5.6.2', FALSE];
$data[] = ['5.6.5', TRUE];
$data[] = ['5.5.21', TRUE];
return $data;
}
}

View file

@ -0,0 +1,74 @@
<?php
/**
* @file
* Contains \Drupal\Tests\system\Unit\Transliteration\MachineNameControllerTest.
*/
namespace Drupal\Tests\system\Unit\Transliteration;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Transliteration\PhpTransliteration;
use Drupal\system\MachineNameController;
use Symfony\Component\HttpFoundation\Request;
/**
* Tests that the machine name controller can transliterate strings as expected.
*
* @group system
*/
class MachineNameControllerTest extends UnitTestCase {
/**
* The machine name controller.
*
* @var \Drupal\system\MachineNameController
*/
protected $machineNameController;
protected function setUp() {
parent::setUp();
// Create the machine name controller.
$this->machineNameController = new MachineNameController(new PhpTransliteration());
}
/**
* Data provider for testMachineNameController().
*
* @see testMachineNameController()
*
* @return array
* An array containing:
* - An array of request parameters.
* - The expected content of the JSONresponse.
*/
public function providerTestMachineNameController() {
return array(
array(array('text' => 'Bob', 'langcode' => 'en'), '"Bob"'),
array(array('text' => 'Bob', 'langcode' => 'en', 'lowercase' => TRUE), '"bob"'),
array(array('text' => 'Bob', 'langcode' => 'en', 'replace' => 'Alice', 'replace_pattern' => 'Bob'), '"Alice"'),
array(array('text' => 'Bob', 'langcode' => 'en', 'replace' => 'Alice', 'replace_pattern' => 'Tom'), '"Bob"'),
array(array('text' => 'Äwesome', 'langcode' => 'en', 'lowercase' => TRUE), '"awesome"'),
array(array('text' => 'Äwesome', 'langcode' => 'de', 'lowercase' => TRUE), '"aewesome"'),
);
}
/**
* Tests machine name controller's transliteration functionality.
*
* @param array $request_params
* An array of request parameters.
* @param $expected_content
* The expected content of the JSONresponse.
*
* @see \Drupal\system\MachineNameController::transliterate()
*
* @dataProvider providerTestMachineNameController
*/
public function testMachineNameController(array $request_params, $expected_content) {
$request = Request::create('', 'GET', $request_params);
$json = $this->machineNameController->transliterate($request);
$this->assertEquals($expected_content, $json->getContent());
}
}