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
|
@ -0,0 +1,330 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\system\Tests\Extension\ModuleHandlerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\system\Kernel\Extension;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use \Drupal\Core\Extension\ModuleUninstallValidatorException;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests ModuleHandler functionality.
|
||||
*
|
||||
* @group Extension
|
||||
*/
|
||||
class ModuleHandlerTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// @todo ModuleInstaller calls system_rebuild_module_data which is part of
|
||||
// system.module, see https://www.drupal.org/node/2208429.
|
||||
include_once $this->root . '/core/modules/system/system.module';
|
||||
|
||||
// Set up the state values so we know where to find the files when running
|
||||
// drupal_get_filename().
|
||||
// @todo Remove as part of https://www.drupal.org/node/2186491
|
||||
system_rebuild_module_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(ContainerBuilder $container) {
|
||||
parent::register($container);
|
||||
// Put a fake route bumper on the container to be called during uninstall.
|
||||
$container
|
||||
->register('router.dumper', 'Drupal\Core\Routing\NullMatcherDumper');
|
||||
}
|
||||
|
||||
/**
|
||||
* The basic functionality of retrieving enabled modules.
|
||||
*/
|
||||
function testModuleList() {
|
||||
$module_list = array();
|
||||
|
||||
$this->assertModuleList($module_list, 'Initial');
|
||||
|
||||
// Try to install a new module.
|
||||
$this->moduleInstaller()->install(array('ban'));
|
||||
$module_list[] = 'ban';
|
||||
sort($module_list);
|
||||
$this->assertModuleList($module_list, 'After adding a module');
|
||||
|
||||
// Try to mess with the module weights.
|
||||
module_set_weight('ban', 20);
|
||||
|
||||
// Move ban to the end of the array.
|
||||
unset($module_list[array_search('ban', $module_list)]);
|
||||
$module_list[] = 'ban';
|
||||
$this->assertModuleList($module_list, 'After changing weights');
|
||||
|
||||
// Test the fixed list feature.
|
||||
$fixed_list = array(
|
||||
'system' => 'core/modules/system/system.module',
|
||||
'menu' => 'core/modules/menu/menu.module',
|
||||
);
|
||||
$this->moduleHandler()->setModuleList($fixed_list);
|
||||
$new_module_list = array_combine(array_keys($fixed_list), array_keys($fixed_list));
|
||||
$this->assertModuleList($new_module_list, t('When using a fixed list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the extension handler returns the expected values.
|
||||
*
|
||||
* @param array $expected_values
|
||||
* The expected values, sorted by weight and module name.
|
||||
* @param $condition
|
||||
*/
|
||||
protected function assertModuleList(Array $expected_values, $condition) {
|
||||
$expected_values = array_values(array_unique($expected_values));
|
||||
$enabled_modules = array_keys($this->container->get('module_handler')->getModuleList());
|
||||
$this->assertEqual($expected_values, $enabled_modules, format_string('@condition: extension handler returns correct results', array('@condition' => $condition)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests dependency resolution.
|
||||
*
|
||||
* Intentionally using fake dependencies added via hook_system_info_alter()
|
||||
* for modules that normally do not have any dependencies.
|
||||
*
|
||||
* To simplify things further, all of the manipulated modules are either
|
||||
* purely UI-facing or live at the "bottom" of all dependency chains.
|
||||
*
|
||||
* @see module_test_system_info_alter()
|
||||
* @see https://www.drupal.org/files/issues/dep.gv__0.png
|
||||
*/
|
||||
function testDependencyResolution() {
|
||||
$this->enableModules(array('module_test'));
|
||||
$this->assertTrue($this->moduleHandler()->moduleExists('module_test'), 'Test module is enabled.');
|
||||
|
||||
// Ensure that modules are not enabled.
|
||||
$this->assertFalse($this->moduleHandler()->moduleExists('color'), 'Color module is disabled.');
|
||||
$this->assertFalse($this->moduleHandler()->moduleExists('config'), 'Config module is disabled.');
|
||||
$this->assertFalse($this->moduleHandler()->moduleExists('help'), 'Help module is disabled.');
|
||||
|
||||
// Create a missing fake dependency.
|
||||
// Color will depend on Config, which depends on a non-existing module Foo.
|
||||
// Nothing should be installed.
|
||||
\Drupal::state()->set('module_test.dependency', 'missing dependency');
|
||||
drupal_static_reset('system_rebuild_module_data');
|
||||
|
||||
try {
|
||||
$result = $this->moduleInstaller()->install(array('color'));
|
||||
$this->fail(t('ModuleInstaller::install() throws an exception if dependencies are missing.'));
|
||||
}
|
||||
catch (\Drupal\Core\Extension\MissingDependencyException $e) {
|
||||
$this->pass(t('ModuleInstaller::install() throws an exception if dependencies are missing.'));
|
||||
}
|
||||
|
||||
$this->assertFalse($this->moduleHandler()->moduleExists('color'), 'ModuleHandler::install() aborts if dependencies are missing.');
|
||||
|
||||
// Fix the missing dependency.
|
||||
// Color module depends on Config. Config depends on Help module.
|
||||
\Drupal::state()->set('module_test.dependency', 'dependency');
|
||||
drupal_static_reset('system_rebuild_module_data');
|
||||
|
||||
$result = $this->moduleInstaller()->install(array('color'));
|
||||
$this->assertTrue($result, 'ModuleHandler::install() returns the correct value.');
|
||||
|
||||
// Verify that the fake dependency chain was installed.
|
||||
$this->assertTrue($this->moduleHandler()->moduleExists('config') && $this->moduleHandler()->moduleExists('help'), 'Dependency chain was installed.');
|
||||
|
||||
// Verify that the original module was installed.
|
||||
$this->assertTrue($this->moduleHandler()->moduleExists('color'), 'Module installation with dependencies succeeded.');
|
||||
|
||||
// Verify that the modules were enabled in the correct order.
|
||||
$module_order = \Drupal::state()->get('module_test.install_order') ?: array();
|
||||
$this->assertEqual($module_order, array('help', 'config', 'color'));
|
||||
|
||||
// Uninstall all three modules explicitly, but in the incorrect order,
|
||||
// and make sure that ModuleHandler::uninstall() uninstalled them in the
|
||||
// correct sequence.
|
||||
$result = $this->moduleInstaller()->uninstall(array('config', 'help', 'color'));
|
||||
$this->assertTrue($result, 'ModuleHandler::uninstall() returned TRUE.');
|
||||
|
||||
foreach (array('color', 'config', 'help') as $module) {
|
||||
$this->assertEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, "$module module was uninstalled.");
|
||||
}
|
||||
$uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: array();
|
||||
$this->assertEqual($uninstalled_modules, array('color', 'config', 'help'), 'Modules were uninstalled in the correct order.');
|
||||
|
||||
// Enable Color module again, which should enable both the Config module and
|
||||
// Help module. But, this time do it with Config module declaring a
|
||||
// dependency on a specific version of Help module in its info file. Make
|
||||
// sure that Drupal\Core\Extension\ModuleHandler::install() still works.
|
||||
\Drupal::state()->set('module_test.dependency', 'version dependency');
|
||||
drupal_static_reset('system_rebuild_module_data');
|
||||
|
||||
$result = $this->moduleInstaller()->install(array('color'));
|
||||
$this->assertTrue($result, 'ModuleHandler::install() returns the correct value.');
|
||||
|
||||
// Verify that the fake dependency chain was installed.
|
||||
$this->assertTrue($this->moduleHandler()->moduleExists('config') && $this->moduleHandler()->moduleExists('help'), 'Dependency chain was installed.');
|
||||
|
||||
// Verify that the original module was installed.
|
||||
$this->assertTrue($this->moduleHandler()->moduleExists('color'), 'Module installation with version dependencies succeeded.');
|
||||
|
||||
// Finally, verify that the modules were enabled in the correct order.
|
||||
$enable_order = \Drupal::state()->get('module_test.install_order') ?: array();
|
||||
$this->assertIdentical($enable_order, array('help', 'config', 'color'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninstalling a module that is a "dependency" of a profile.
|
||||
*/
|
||||
function testUninstallProfileDependency() {
|
||||
$profile = 'minimal';
|
||||
$dependency = 'dblog';
|
||||
$this->setSetting('install_profile', $profile);
|
||||
// Prime the drupal_get_filename() static cache with the location of the
|
||||
// minimal profile as it is not the currently active profile and we don't
|
||||
// yet have any cached way to retrieve its location.
|
||||
// @todo Remove as part of https://www.drupal.org/node/2186491
|
||||
drupal_get_filename('profile', $profile, 'core/profiles/' . $profile . '/' . $profile . '.info.yml');
|
||||
$this->enableModules(array('module_test', $profile));
|
||||
|
||||
drupal_static_reset('system_rebuild_module_data');
|
||||
$data = system_rebuild_module_data();
|
||||
$this->assertTrue(isset($data[$profile]->requires[$dependency]));
|
||||
|
||||
$this->moduleInstaller()->install(array($dependency));
|
||||
$this->assertTrue($this->moduleHandler()->moduleExists($dependency));
|
||||
|
||||
// Uninstall the profile module "dependency".
|
||||
$result = $this->moduleInstaller()->uninstall(array($dependency));
|
||||
$this->assertTrue($result, 'ModuleHandler::uninstall() returns TRUE.');
|
||||
$this->assertFalse($this->moduleHandler()->moduleExists($dependency));
|
||||
$this->assertEqual(drupal_get_installed_schema_version($dependency), SCHEMA_UNINSTALLED, "$dependency module was uninstalled.");
|
||||
|
||||
// Verify that the installation profile itself was not uninstalled.
|
||||
$uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: array();
|
||||
$this->assertTrue(in_array($dependency, $uninstalled_modules), "$dependency module is in the list of uninstalled modules.");
|
||||
$this->assertFalse(in_array($profile, $uninstalled_modules), 'The installation profile is not in the list of uninstalled modules.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninstalling a module that has content.
|
||||
*/
|
||||
function testUninstallContentDependency() {
|
||||
$this->enableModules(array('module_test', 'entity_test', 'text', 'user', 'help'));
|
||||
$this->assertTrue($this->moduleHandler()->moduleExists('entity_test'), 'Test module is enabled.');
|
||||
$this->assertTrue($this->moduleHandler()->moduleExists('module_test'), 'Test module is enabled.');
|
||||
|
||||
$this->installSchema('user', 'users_data');
|
||||
$entity_types = \Drupal::entityManager()->getDefinitions();
|
||||
foreach ($entity_types as $entity_type) {
|
||||
if ('entity_test' == $entity_type->getProvider()) {
|
||||
$this->installEntitySchema($entity_type->id());
|
||||
}
|
||||
}
|
||||
|
||||
// Create a fake dependency.
|
||||
// entity_test will depend on help. This way help can not be uninstalled
|
||||
// when there is test content preventing entity_test from being uninstalled.
|
||||
\Drupal::state()->set('module_test.dependency', 'dependency');
|
||||
drupal_static_reset('system_rebuild_module_data');
|
||||
|
||||
// Create an entity so that the modules can not be disabled.
|
||||
$entity = entity_create('entity_test', array('name' => $this->randomString()));
|
||||
$entity->save();
|
||||
|
||||
// Uninstalling entity_test is not possible when there is content.
|
||||
try {
|
||||
$message = 'ModuleHandler::uninstall() throws ModuleUninstallValidatorException upon uninstalling a module which does not pass validation.';
|
||||
$this->moduleInstaller()->uninstall(array('entity_test'));
|
||||
$this->fail($message);
|
||||
}
|
||||
catch (ModuleUninstallValidatorException $e) {
|
||||
$this->pass(get_class($e) . ': ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Uninstalling help needs entity_test to be un-installable.
|
||||
try {
|
||||
$message = 'ModuleHandler::uninstall() throws ModuleUninstallValidatorException upon uninstalling a module which does not pass validation.';
|
||||
$this->moduleInstaller()->uninstall(array('help'));
|
||||
$this->fail($message);
|
||||
}
|
||||
catch (ModuleUninstallValidatorException $e) {
|
||||
$this->pass(get_class($e) . ': ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Deleting the entity.
|
||||
$entity->delete();
|
||||
|
||||
$result = $this->moduleInstaller()->uninstall(array('help'));
|
||||
$this->assertTrue($result, 'ModuleHandler::uninstall() returns TRUE.');
|
||||
$this->assertEqual(drupal_get_installed_schema_version('entity_test'), SCHEMA_UNINSTALLED, "entity_test module was uninstalled.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the correct module metadata is returned.
|
||||
*/
|
||||
function testModuleMetaData() {
|
||||
// Generate the list of available modules.
|
||||
$modules = system_rebuild_module_data();
|
||||
// Check that the mtime field exists for the system module.
|
||||
$this->assertTrue(!empty($modules['system']->info['mtime']), 'The system.info.yml file modification time field is present.');
|
||||
// Use 0 if mtime isn't present, to avoid an array index notice.
|
||||
$test_mtime = !empty($modules['system']->info['mtime']) ? $modules['system']->info['mtime'] : 0;
|
||||
// Ensure the mtime field contains a number that is greater than zero.
|
||||
$this->assertTrue(is_numeric($test_mtime) && ($test_mtime > 0), 'The system.info.yml file modification time field contains a timestamp.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether module-provided stream wrappers are registered properly.
|
||||
*/
|
||||
public function testModuleStreamWrappers() {
|
||||
// file_test.module provides (among others) a 'dummy' stream wrapper.
|
||||
// Verify that it is not registered yet to prevent false positives.
|
||||
$stream_wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers();
|
||||
$this->assertFalse(isset($stream_wrappers['dummy']));
|
||||
$this->moduleInstaller()->install(['file_test']);
|
||||
// Verify that the stream wrapper is available even without calling
|
||||
// \Drupal::service('stream_wrapper_manager')->getWrappers() again.
|
||||
// If the stream wrapper is not available file_exists() will raise a notice.
|
||||
file_exists('dummy://');
|
||||
$stream_wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers();
|
||||
$this->assertTrue(isset($stream_wrappers['dummy']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the correct theme metadata is returned.
|
||||
*/
|
||||
function testThemeMetaData() {
|
||||
// Generate the list of available themes.
|
||||
$themes = \Drupal::service('theme_handler')->rebuildThemeData();
|
||||
// Check that the mtime field exists for the bartik theme.
|
||||
$this->assertTrue(!empty($themes['bartik']->info['mtime']), 'The bartik.info.yml file modification time field is present.');
|
||||
// Use 0 if mtime isn't present, to avoid an array index notice.
|
||||
$test_mtime = !empty($themes['bartik']->info['mtime']) ? $themes['bartik']->info['mtime'] : 0;
|
||||
// Ensure the mtime field contains a number that is greater than zero.
|
||||
$this->assertTrue(is_numeric($test_mtime) && ($test_mtime > 0), 'The bartik.info.yml file modification time field contains a timestamp.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ModuleHandler.
|
||||
*
|
||||
* @return \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected function moduleHandler() {
|
||||
return $this->container->get('module_handler');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ModuleInstaller.
|
||||
*
|
||||
* @return \Drupal\Core\Extension\ModuleInstallerInterface
|
||||
*/
|
||||
protected function moduleInstaller() {
|
||||
return $this->container->get('module_installer');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\system\Tests\PhpStorage\PhpStorageFactoryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\system\Kernel\PhpStorage;
|
||||
|
||||
use Drupal\Component\PhpStorage\MTimeProtectedFileStorage;
|
||||
use Drupal\Core\PhpStorage\PhpStorageFactory;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\Core\StreamWrapper\PublicStream;
|
||||
use Drupal\system\PhpStorage\MockPhpStorage;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the PHP storage factory.
|
||||
*
|
||||
* @group PhpStorage
|
||||
* @see \Drupal\Core\PhpStorage\PhpStorageFactory
|
||||
*/
|
||||
class PhpStorageFactoryTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Empty the PHP storage settings, as KernelTestBase sets it by default.
|
||||
$settings = Settings::getAll();
|
||||
unset($settings['php_storage']);
|
||||
new Settings($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the get() method with no settings.
|
||||
*/
|
||||
public function testGetNoSettings() {
|
||||
$php = PhpStorageFactory::get('test');
|
||||
// This should be the default class used.
|
||||
$this->assertTrue($php instanceof MTimeProtectedFileStorage, 'An MTimeProtectedFileStorage instance was returned with no settings.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the get() method using the 'default' settings.
|
||||
*/
|
||||
public function testGetDefault() {
|
||||
$this->setSettings();
|
||||
$php = PhpStorageFactory::get('test');
|
||||
$this->assertTrue($php instanceof MockPhpStorage, 'A FileReadOnlyStorage instance was returned with default settings.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the get() method with overridden settings.
|
||||
*/
|
||||
public function testGetOverride() {
|
||||
$this->setSettings('test');
|
||||
$php = PhpStorageFactory::get('test');
|
||||
// The FileReadOnlyStorage should be used from settings.
|
||||
$this->assertTrue($php instanceof MockPhpStorage, 'A MockPhpStorage instance was returned from overridden settings.');
|
||||
|
||||
// Test that the name is used for the bin when it is NULL.
|
||||
$this->setSettings('test', array('bin' => NULL));
|
||||
$php = PhpStorageFactory::get('test');
|
||||
$this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.');
|
||||
$this->assertIdentical('test', $php->getConfigurationValue('bin'), 'Name value was used for bin.');
|
||||
|
||||
// Test that a default directory is set if it's empty.
|
||||
$this->setSettings('test', array('directory' => NULL));
|
||||
$php = PhpStorageFactory::get('test');
|
||||
$this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.');
|
||||
$this->assertIdentical(PublicStream::basePath() . '/php', $php->getConfigurationValue('directory'), 'Default file directory was used.');
|
||||
|
||||
// Test that a default storage class is set if it's empty.
|
||||
$this->setSettings('test', array('class' => NULL));
|
||||
$php = PhpStorageFactory::get('test');
|
||||
$this->assertTrue($php instanceof MTimeProtectedFileStorage, 'An MTimeProtectedFileStorage instance was returned from overridden settings with no class.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Settings() singleton.
|
||||
*
|
||||
* @param string $name
|
||||
* The storage bin name to set.
|
||||
* @param array $configuration
|
||||
* An array of configuration to set. Will be merged with default values.
|
||||
*/
|
||||
protected function setSettings($name = 'default', array $configuration = array()) {
|
||||
$settings['php_storage'][$name] = $configuration + array(
|
||||
'class' => 'Drupal\system\PhpStorage\MockPhpStorage',
|
||||
'directory' => 'tmp://',
|
||||
'secret' => $this->randomString(),
|
||||
'bin' => 'test',
|
||||
);
|
||||
new Settings($settings);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,8 +7,10 @@
|
|||
|
||||
namespace Drupal\Tests\system\Unit\Breadcrumbs;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Access\AccessResultAllowed;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
@ -16,6 +18,7 @@ use Drupal\Core\Utility\LinkGeneratorInterface;
|
|||
use Drupal\system\PathBasedBreadcrumbBuilder;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
@ -117,6 +120,15 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
|
|||
);
|
||||
|
||||
$this->builder->setStringTranslation($this->getStringTranslationStub());
|
||||
|
||||
$cache_contexts_manager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$cache_contexts_manager->expects($this->any())
|
||||
->method('validate_tokens');
|
||||
$container = new Container();
|
||||
$container->set('cache_contexts_manager', $cache_contexts_manager);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,8 +141,11 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
|
|||
->method('getPathInfo')
|
||||
->will($this->returnValue('/'));
|
||||
|
||||
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
|
||||
$this->assertEquals(array(), $links);
|
||||
$breadcrumb = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
|
||||
$this->assertEquals([], $breadcrumb->getLinks());
|
||||
$this->assertEquals(['url.path'], $breadcrumb->getCacheContexts());
|
||||
$this->assertEquals([], $breadcrumb->getCacheTags());
|
||||
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,8 +158,11 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
|
|||
->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);
|
||||
$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([], $breadcrumb->getCacheTags());
|
||||
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,8 +193,11 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
|
|||
|
||||
$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);
|
||||
$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([], $breadcrumb->getCacheTags());
|
||||
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,14 +234,21 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
|
|||
}
|
||||
}));
|
||||
|
||||
$this->setupAccessManagerToAllow();
|
||||
|
||||
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
|
||||
$this->assertEquals(array(
|
||||
$this->accessManager->expects($this->any())
|
||||
->method('check')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
AccessResult::allowed()->cachePerPermissions(),
|
||||
AccessResult::allowed()->addCacheContexts(['bar'])->addCacheTags(['example'])
|
||||
);
|
||||
$breadcrumb = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
|
||||
$this->assertEquals([
|
||||
new Link('Home', new Url('<front>')),
|
||||
new Link('Example', new Url('example')),
|
||||
new Link('Bar', new Url('example_bar')),
|
||||
), $links);
|
||||
], $breadcrumb->getLinks());
|
||||
$this->assertEquals(['bar', 'url.path', 'user.permissions'], $breadcrumb->getCacheContexts());
|
||||
$this->assertEquals(['example'], $breadcrumb->getCacheTags());
|
||||
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -241,10 +269,13 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
|
|||
->method('matchRequest')
|
||||
->will($this->throwException(new $exception_class($exception_argument)));
|
||||
|
||||
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
|
||||
$breadcrumb = $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);
|
||||
$this->assertEquals([0 => new Link('Home', new Url('<front>'))], $breadcrumb->getLinks());
|
||||
$this->assertEquals(['url.path'], $breadcrumb->getCacheContexts());
|
||||
$this->assertEquals([], $breadcrumb->getCacheTags());
|
||||
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -282,10 +313,13 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
|
|||
->method('matchRequest')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$links = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
|
||||
$breadcrumb = $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);
|
||||
$this->assertEquals([0 => new Link('Home', new Url('<front>'))], $breadcrumb->getLinks());
|
||||
$this->assertEquals(['url.path'], $breadcrumb->getCacheContexts());
|
||||
$this->assertEquals([], $breadcrumb->getCacheTags());
|
||||
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -329,8 +363,11 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
|
|||
->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);
|
||||
$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([], $breadcrumb->getCacheTags());
|
||||
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -339,7 +376,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
|
|||
public function setupAccessManagerToAllow() {
|
||||
$this->accessManager->expects($this->any())
|
||||
->method('check')
|
||||
->willReturn(TRUE);
|
||||
->willReturn((new AccessResultAllowed())->cachePerPermissions());
|
||||
}
|
||||
|
||||
protected function setupStubPathProcessor() {
|
||||
|
|
|
@ -100,7 +100,10 @@ class MenuLinkTreeTest extends UnitTestCase {
|
|||
*
|
||||
* @dataProvider providerTestBuildCacheability
|
||||
*/
|
||||
public function testBuildCacheability($description, $tree, $expected_build) {
|
||||
public function testBuildCacheability($description, $tree, $expected_build, $access, array $access_cache_contexts = []) {
|
||||
if ($access !== NULL) {
|
||||
$access->addCacheContexts($access_cache_contexts);
|
||||
}
|
||||
$build = $this->menuLinkTree->build($tree);
|
||||
sort($expected_build['#cache']['contexts']);
|
||||
$this->assertEquals($expected_build, $build, $description);
|
||||
|
@ -175,13 +178,12 @@ class MenuLinkTreeTest extends UnitTestCase {
|
|||
'description' => 'Empty tree.',
|
||||
'tree' => [],
|
||||
'expected_build' => $base_expected_build_empty,
|
||||
'access' => NULL,
|
||||
'access_cache_contexts' => [],
|
||||
];
|
||||
|
||||
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];
|
||||
|
@ -203,6 +205,8 @@ class MenuLinkTreeTest extends UnitTestCase {
|
|||
'description' => "Single-item tree; access=$i; link=$j.",
|
||||
'tree' => $tree,
|
||||
'expected_build' => $expected_build,
|
||||
'access' => $access,
|
||||
'access_cache_contexts' => $access_cache_contexts,
|
||||
];
|
||||
|
||||
// Single-level tree.
|
||||
|
@ -221,6 +225,8 @@ class MenuLinkTreeTest extends UnitTestCase {
|
|||
'description' => "Single-level tree; access=$i; link=$j.",
|
||||
'tree' => $tree,
|
||||
'expected_build' => $expected_build,
|
||||
'access' => $access,
|
||||
'access_cache_contexts' => $access_cache_contexts,
|
||||
];
|
||||
|
||||
// Multi-level tree.
|
||||
|
@ -251,6 +257,8 @@ class MenuLinkTreeTest extends UnitTestCase {
|
|||
'description' => "Multi-level tree; access=$i; link=$j.",
|
||||
'tree' => $tree,
|
||||
'expected_build' => $expected_build,
|
||||
'access' => $access,
|
||||
'access_cache_contexts' => $access_cache_contexts,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\system\Unit\Plugin\migrate\source\MenuTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\system\Unit\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests menu source plugin.
|
||||
*
|
||||
* @group system
|
||||
*/
|
||||
class MenuTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\system\Plugin\migrate\source\Menu';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'menu',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'menu_name' => 'menu-name-1',
|
||||
'title' => 'menu custom value 1',
|
||||
'description' => 'menu custom description value 1',
|
||||
),
|
||||
array(
|
||||
'menu_name' => 'menu-name-2',
|
||||
'title' => 'menu custom value 2',
|
||||
'description' => 'menu custom description value 2',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['menu_custom'] = $this->expectedResults;
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue