Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,10 @@
|
|||
id: test
|
||||
label: 'Test'
|
||||
langcode: en
|
||||
content:
|
||||
value: "<p><strong>Hello World</strong></p>"
|
||||
format: plain_text
|
||||
animals:
|
||||
- kitten
|
||||
- llama
|
||||
- elephant
|
|
@ -0,0 +1,21 @@
|
|||
# Schema for the configuration files of the Configuration translation test module.
|
||||
|
||||
config_translation_test.content:
|
||||
type: config_object
|
||||
label: 'Content'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'Category identifier'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
content:
|
||||
type: text_format
|
||||
label: 'Content'
|
||||
animals:
|
||||
type: sequence
|
||||
label: 'Animals'
|
||||
sequence:
|
||||
type: label
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# Attach to file settings for testing. The base route does not matter.
|
||||
system.file_system_settings:
|
||||
title: 'Test config translation'
|
||||
base_route_name: system.file_system_settings
|
||||
names:
|
||||
- config_translation_test.content
|
|
@ -0,0 +1,9 @@
|
|||
name: 'Configuration Translation Test'
|
||||
description: 'Helpers to test the configuration translation system'
|
||||
type: module
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- config_translation
|
||||
- config_test
|
|
@ -0,0 +1,7 @@
|
|||
# Add a default local task for the file system settings page, so that the local
|
||||
# task added by Configuration Translation becomes visible. This facilitates
|
||||
# manual testing.
|
||||
system.file_system_settings:
|
||||
route_name: system.file_system_settings
|
||||
title: Settings
|
||||
base_route: system.file_system_settings
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Configuration Translation Test module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Extension\Extension;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_system_info_alter().
|
||||
*/
|
||||
function config_translation_test_system_info_alter(array &$info, Extension $file, $type) {
|
||||
// @see \Drupal\config_translation\Tests\ConfigTranslationUiThemeTest
|
||||
if ($file->getType() == 'theme' && $file->getName() == 'config_translation_test_theme') {
|
||||
$info['hidden'] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_type_alter().
|
||||
*/
|
||||
function config_translation_test_entity_type_alter(array &$entity_types) {
|
||||
// Remove entity definition for these entity types from config_test module.
|
||||
unset($entity_types['config_test_no_status']);
|
||||
unset($entity_types['config_query_test']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_config_translation_info_alter().
|
||||
*/
|
||||
function config_translation_test_config_translation_info_alter(&$info) {
|
||||
if (\Drupal::state()->get('config_translation_test_config_translation_info_alter')) {
|
||||
// Limit account settings config files to only one of them.
|
||||
$info['entity.user.admin_form']['names'] = array('user.settings');
|
||||
|
||||
// Add one more config file to the site information page.
|
||||
$info['system.site_information_settings']['names'][] = 'system.rss';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_BASE_FORM_ID_alter() for ConfigTranslationFormBase.
|
||||
*
|
||||
* Adds a list of configuration names to the top of the configuration
|
||||
* translation form.
|
||||
*
|
||||
* @see \Drupal\config_translation\Form\ConfigTranslationFormBase
|
||||
*/
|
||||
function config_translation_test_form_config_translation_form_alter(&$form, FormStateInterface $form_state) {
|
||||
if (\Drupal::state()->get('config_translation_test_alter_form_alter')) {
|
||||
$form['#base_altered'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter() for ConfigTranslationAddForm.
|
||||
*
|
||||
* Changes the title to include the source language.
|
||||
*
|
||||
* @see \Drupal\config_translation\Form\ConfigTranslationAddForm
|
||||
*/
|
||||
function config_translation_test_form_config_translation_add_form_alter(&$form, FormStateInterface $form_state) {
|
||||
if (\Drupal::state()->get('config_translation_test_alter_form_alter')) {
|
||||
$form['#altered'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter() for ConfigTranslationEditForm.
|
||||
*
|
||||
* Adds a column to the configuration translation edit form that shows the
|
||||
* current translation. Note that this column would not be displayed by default,
|
||||
* as the columns are hardcoded in
|
||||
* config_translation_manage_form_element.html.twig. The template would need to
|
||||
* be overridden for the column to be displayed.
|
||||
*
|
||||
* @see \Drupal\config_translation\Form\ConfigTranslationEditForm
|
||||
*/
|
||||
function config_translation_test_form_config_translation_edit_form_alter(&$form, FormStateInterface $form_state) {
|
||||
if (\Drupal::state()->get('config_translation_test_alter_form_alter')) {
|
||||
$form['#altered'] = TRUE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\config_translation\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade i18n maintenance variables to system.*.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateI18nSystemMaintenanceTest extends MigrateDrupal6TestBase {
|
||||
|
||||
public static $modules = ['language', 'config_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d6_i18n_system_maintenance');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of system (maintenance) variables to system.maintenance.yml.
|
||||
*/
|
||||
public function testSystemMaintenance() {
|
||||
$config = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'system.maintenance');
|
||||
$this->assertIdentical('fr - Drupal is currently under maintenance. We should be back shortly. Thank you for your patience.', $config->get('message'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\config_translation\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade i18n_strings site variables to system.*.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateI18nSystemSiteTest extends MigrateDrupal6TestBase {
|
||||
|
||||
public static $modules = ['language', 'config_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d6_i18n_system_site');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of system (site) variables to system.site.yml.
|
||||
*/
|
||||
public function testSystemSite() {
|
||||
$config_translation = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'system.site');
|
||||
$this->assertIdentical('fr site name', $config_translation->get('name'));
|
||||
$this->assertIdentical('fr_site_mail@example.com', $config_translation->get('mail'));
|
||||
$this->assertIdentical('fr Migrate rocks', $config_translation->get('slogan'));
|
||||
$this->assertIdentical('/fr-user', $config_translation->get('page.403'));
|
||||
$this->assertIdentical('/fr-page-not-found', $config_translation->get('page.404'));
|
||||
$this->assertIdentical('/node', $config_translation->get('page.front'));
|
||||
$this->assertIdentical(NULL, $config_translation->get('admin_compact_mode'));
|
||||
|
||||
$config_translation = \Drupal::service('language_manager')->getLanguageConfigOverride('zu', 'system.site');
|
||||
$this->assertIdentical('zu - site_name', $config_translation->get('name'));
|
||||
$this->assertIdentical('site_mail@example.com', $config_translation->get('mail'));
|
||||
$this->assertIdentical('Migrate rocks', $config_translation->get('slogan'));
|
||||
$this->assertIdentical('/zu-user', $config_translation->get('page.403'));
|
||||
$this->assertIdentical('/zu-page-not-found', $config_translation->get('page.404'));
|
||||
$this->assertIdentical('/node', $config_translation->get('page.front'));
|
||||
$this->assertIdentical(NULL, $config_translation->get('admin_compact_mode'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\config_translation\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade i18n variables to user.*.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateI18nUserConfigsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
public static $modules = ['language', 'locale', 'config_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installSchema('locale',
|
||||
['locales_source', 'locales_target', 'locales_location']);
|
||||
$this->executeMigrations(['d6_i18n_user_mail', 'd6_i18n_user_settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of i18n user variables to user.mail.yml.
|
||||
*/
|
||||
public function testUserMail() {
|
||||
$config = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'user.mail');
|
||||
$this->assertIdentical('fr - Account details for [user:name] at [site:name] (approved)', $config->get('status_activated.subject'));
|
||||
$this->assertIdentical("fr - [user:name],\r\n\r\nYour account at [site:name] has been activated.\r\n\r\nYou may now log in by clicking on this link or copying and pasting it in your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis is a one-time login, so it can be used only once.\r\n\r\nAfter logging in, you will be redirected to [user:edit-url] so you can change your password.\r\n\r\nOnce you have set your own password, you will be able to log in to [site:login-url] in the future using:\r\n\r\nusername: [user:name]\r\n", $config->get('status_activated.body'));
|
||||
$this->assertIdentical('fr - Replacement login information for [user:name] at [site:name]', $config->get('password_reset.subject'));
|
||||
$this->assertIdentical("fr - [user:name],\r\n\r\nA request to reset the password for your account has been made at [site:name].\r\n\r\nYou may now log in to [site:url-brief] by clicking on this link or copying and pasting it in your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\r\n\r\nAfter logging in, you will be redirected to [user:edit-url] so you can change your password.", $config->get('password_reset.body'));
|
||||
$this->assertIdentical('fr - Account details for [user:name] at [site:name] (deleted)', $config->get('cancel_confirm.subject'));
|
||||
$this->assertIdentical("fr - [user:name],\r\n\r\nYour account on [site:name] has been deleted.", $config->get('cancel_confirm.body'));
|
||||
$this->assertIdentical('fr - An administrator created an account for you at [site:name]', $config->get('register_admin_created.subject'));
|
||||
$this->assertIdentical("fr - [user:name],\r\n\r\nA site administrator at [site:name] has created an account for you. You may now log in to [site:login-url] using the following username and password:\r\n\r\nusername: [user:name]\r\npassword: \r\n\r\nYou may also log in by clicking on this link or copying and pasting it in your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis is a one-time login, so it can be used only once.\r\n\r\nAfter logging in, you will be redirected to [user:edit-url] so you can change your password.\r\n\r\n\r\n-- [site:name] team", $config->get('register_admin_created.body'));
|
||||
$this->assertIdentical('fr - Account details for [user:name] at [site:name]', $config->get('register_no_approval_required.subject'));
|
||||
$this->assertIdentical("fr - [user:name],\r\n\r\nThank you for registering at [site:name]. You may now log in to [site:login-url] using the following username and password:\r\n\r\nusername: [user:name]\r\npassword: \r\n\r\nYou may also log in by clicking on this link or copying and pasting it in your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis is a one-time login, so it can be used only once.\r\n\r\nAfter logging in, you will be redirected to [user:edit-url] so you can change your password.\r\n\r\n\r\n-- [site:name] team", $config->get('register_no_approval_required.body'));
|
||||
$this->assertIdentical('fr - Account details for [user:name] at [site:name] (pending admin approval)', $config->get('register_pending_approval.subject'));
|
||||
$this->assertIdentical("fr - [user:name],\r\n\r\nThank you for registering at [site:name]. Your application for an account is currently pending approval. Once it has been approved, you will receive another email containing information about how to log in, set your password, and other details.\r\n\r\n\r\n-- [site:name] team", $config->get('register_pending_approval.body'));
|
||||
$this->assertIdentical('fr - Account details for [user:name] at [site:name] (blocked)', $config->get('status_blocked.subject'));
|
||||
$this->assertIdentical("fr - [user:name],\r\n\r\nYour account on [site:name] has been blocked.", $config->get('status_blocked.body'));
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), 'user.mail', $config->get());
|
||||
|
||||
$config = \Drupal::service('language_manager')->getLanguageConfigOverride('zu', 'user.mail');
|
||||
$this->assertIdentical('zu - An administrator created an account for you at [site:name]', $config->get('register_admin_created.subject'));
|
||||
$this->assertIdentical("zu - [user:name],\r\n\r\nA site administrator at [site:name] has created an account for you. You may now log in to [site:login-url] using the following username and password:\r\n\r\nusername: [user:name]\r\npassword: \r\n\r\nYou may also log in by clicking on this link or copying and pasting it in your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis is a one-time login, so it can be used only once.\r\n\r\nAfter logging in, you will be redirected to [user:edit-url] so you can change your password.\r\n\r\n\r\n-- [site:name] team", $config->get('register_admin_created.body'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of i18n user variables to user.settings.yml.
|
||||
*/
|
||||
public function testUserSettings() {
|
||||
$config = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'user.settings');
|
||||
$this->assertIdentical(1, $config->get('notify.status_blocked'));
|
||||
$this->assertIdentical(0, $config->get('notify.status_activated'));
|
||||
$this->assertIdentical(0, $config->get('verify_mail'));
|
||||
$this->assertIdentical('admin_only', $config->get('register'));
|
||||
$this->assertIdentical('fr Guest', $config->get('anonymous'));
|
||||
|
||||
$config = \Drupal::service('language_manager')->getLanguageConfigOverride('zu', 'user.settings');
|
||||
$this->assertIdentical(1, $config->get('notify.status_blocked'));
|
||||
$this->assertIdentical(0, $config->get('notify.status_activated'));
|
||||
$this->assertIdentical(0, $config->get('verify_mail'));
|
||||
$this->assertIdentical('admin_only', $config->get('register'));
|
||||
$this->assertIdentical('Guest', $config->get('anonymous'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,218 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\config_translation\Unit;
|
||||
|
||||
use Drupal\config_translation\ConfigEntityMapper;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Tests the functionality provided by the configuration entity mapper.
|
||||
*
|
||||
* @group config_translation
|
||||
*/
|
||||
class ConfigEntityMapperTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The configuration entity mapper to test.
|
||||
*
|
||||
* @var \Drupal\config_translation\ConfigEntityMapper
|
||||
*/
|
||||
protected $configEntityMapper;
|
||||
|
||||
/**
|
||||
* The entity manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The entity instance used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* The route provider used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RouteProviderInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $routeProvider;
|
||||
|
||||
/**
|
||||
* The mocked language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface $language_manager|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
protected function setUp() {
|
||||
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
|
||||
$this->entity = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
|
||||
|
||||
$this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
|
||||
|
||||
$this->routeProvider
|
||||
->expects($this->any())
|
||||
->method('getRouteByName')
|
||||
->with('entity.configurable_language.edit_form')
|
||||
->will($this->returnValue(new Route('/admin/config/regional/language/edit/{configurable_language}')));
|
||||
|
||||
$definition = array(
|
||||
'class' => '\Drupal\config_translation\ConfigEntityMapper',
|
||||
'base_route_name' => 'entity.configurable_language.edit_form',
|
||||
'title' => '@label language',
|
||||
'names' => array(),
|
||||
'entity_type' => 'configurable_language',
|
||||
'route_name' => 'config_translation.item.overview.entity.configurable_language.edit_form',
|
||||
);
|
||||
|
||||
$typed_config_manager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
|
||||
|
||||
$locale_config_manager = $this->getMockBuilder('Drupal\locale\LocaleConfigManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
|
||||
$this->configEntityMapper = new ConfigEntityMapper(
|
||||
'configurable_language',
|
||||
$definition,
|
||||
$this->getConfigFactoryStub(),
|
||||
$typed_config_manager,
|
||||
$locale_config_manager,
|
||||
$this->getMock('Drupal\config_translation\ConfigMapperManagerInterface'),
|
||||
$this->routeProvider,
|
||||
$this->getStringTranslationStub(),
|
||||
$this->entityManager,
|
||||
$this->languageManager
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigEntityMapper::setEntity() and ConfigEntityMapper::getEntity().
|
||||
*/
|
||||
public function testEntityGetterAndSetter() {
|
||||
$this->entity
|
||||
->expects($this->once())
|
||||
->method('id')
|
||||
->with()
|
||||
->will($this->returnValue('entity_id'));
|
||||
|
||||
$entity_type = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
|
||||
$entity_type
|
||||
->expects($this->any())
|
||||
->method('getConfigPrefix')
|
||||
->will($this->returnValue('config_prefix'));
|
||||
$this->entityManager
|
||||
->expects($this->once())
|
||||
->method('getDefinition')
|
||||
->with('configurable_language')
|
||||
->will($this->returnValue($entity_type));
|
||||
|
||||
// No entity is set.
|
||||
$this->assertNull($this->configEntityMapper->getEntity());
|
||||
|
||||
$result = $this->configEntityMapper->setEntity($this->entity);
|
||||
$this->assertTrue($result);
|
||||
|
||||
// Ensure that the getter provides the entity.
|
||||
$this->assertEquals($this->entity, $this->configEntityMapper->getEntity());
|
||||
|
||||
// Ensure that the configuration name was added to the mapper.
|
||||
$plugin_definition = $this->configEntityMapper->getPluginDefinition();
|
||||
$this->assertTrue(in_array('config_prefix.entity_id', $plugin_definition['names']));
|
||||
|
||||
// Make sure setEntity() returns FALSE when called a second time.
|
||||
$result = $this->configEntityMapper->setEntity($this->entity);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigEntityMapper::getOverviewRouteParameters().
|
||||
*/
|
||||
public function testGetOverviewRouteParameters() {
|
||||
$entity_type = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
|
||||
$this->entityManager
|
||||
->expects($this->once())
|
||||
->method('getDefinition')
|
||||
->with('configurable_language')
|
||||
->will($this->returnValue($entity_type));
|
||||
$this->configEntityMapper->setEntity($this->entity);
|
||||
|
||||
$this->entity
|
||||
->expects($this->once())
|
||||
->method('id')
|
||||
->with()
|
||||
->will($this->returnValue('entity_id'));
|
||||
|
||||
$result = $this->configEntityMapper->getOverviewRouteParameters();
|
||||
|
||||
$this->assertSame(array('configurable_language' => 'entity_id'), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigEntityMapper::getType().
|
||||
*/
|
||||
public function testGetType() {
|
||||
$result = $this->configEntityMapper->getType();
|
||||
$this->assertSame('configurable_language', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigEntityMapper::getTypeName().
|
||||
*/
|
||||
public function testGetTypeName() {
|
||||
$entity_type = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
|
||||
$entity_type->expects($this->once())
|
||||
->method('getLabel')
|
||||
->will($this->returnValue('test'));
|
||||
$this->entityManager
|
||||
->expects($this->once())
|
||||
->method('getDefinition')
|
||||
->with('configurable_language')
|
||||
->will($this->returnValue($entity_type));
|
||||
|
||||
$result = $this->configEntityMapper->getTypeName();
|
||||
$this->assertSame('test', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigEntityMapper::getTypeLabel().
|
||||
*/
|
||||
public function testGetTypeLabel() {
|
||||
$entity_type = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
|
||||
$entity_type->expects($this->once())
|
||||
->method('getLabel')
|
||||
->will($this->returnValue('test'));
|
||||
$this->entityManager
|
||||
->expects($this->once())
|
||||
->method('getDefinition')
|
||||
->with('configurable_language')
|
||||
->will($this->returnValue($entity_type));
|
||||
|
||||
$result = $this->configEntityMapper->getTypeLabel();
|
||||
$this->assertSame('test', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigEntityMapper::getOperations().
|
||||
*/
|
||||
public function testGetOperations() {
|
||||
$result = $this->configEntityMapper->getOperations();
|
||||
|
||||
$expected = array(
|
||||
'list' => array(
|
||||
'title' => 'List',
|
||||
'url' => Url::fromRoute('config_translation.entity_list', ['mapper_id' => 'configurable_language']),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\config_translation\Unit;
|
||||
|
||||
use Drupal\config_translation\ConfigFieldMapper;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Tests the functionality provided by the configuration field mapper.
|
||||
*
|
||||
* @group config_translation
|
||||
*
|
||||
* @coversDefaultClass \Drupal\config_translation\ConfigFieldMapper
|
||||
*/
|
||||
class ConfigFieldMapperTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The configuration field mapper to test.
|
||||
*
|
||||
* @var \Drupal\config_translation\ConfigFieldMapper
|
||||
*/
|
||||
protected $configFieldMapper;
|
||||
|
||||
/**
|
||||
* The field config instance used for testing.
|
||||
*
|
||||
* @var \Drupal\field\FieldConfigInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* The entity manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entity = $this->getMock('Drupal\field\FieldConfigInterface');
|
||||
|
||||
$definition = array(
|
||||
'class' => '\Drupal\config_translation\ConfigFieldMapper',
|
||||
'base_route_name' => 'entity.field_config.node_field_edit_form',
|
||||
'title' => '@label field',
|
||||
'names' => array(),
|
||||
'entity_type' => 'field_config',
|
||||
);
|
||||
|
||||
$locale_config_manager = $this->getMockBuilder('Drupal\locale\LocaleConfigManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->configFieldMapper = new ConfigFieldMapper(
|
||||
'node_fields',
|
||||
$definition,
|
||||
$this->getConfigFactoryStub(),
|
||||
$this->getMock('Drupal\Core\Config\TypedConfigManagerInterface'),
|
||||
$locale_config_manager,
|
||||
$this->getMock('Drupal\config_translation\ConfigMapperManagerInterface'),
|
||||
$this->getMock('Drupal\Core\Routing\RouteProviderInterface'),
|
||||
$this->getStringTranslationStub(),
|
||||
$this->entityManager,
|
||||
$this->getMock('Drupal\Core\Language\LanguageManagerInterface')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigFieldMapper::setEntity().
|
||||
*
|
||||
* @covers ::setEntity
|
||||
*/
|
||||
public function testSetEntity() {
|
||||
$entity_type = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
|
||||
$entity_type
|
||||
->expects($this->any())
|
||||
->method('getConfigPrefix')
|
||||
->will($this->returnValue('config_prefix'));
|
||||
|
||||
$this->entityManager
|
||||
->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->will($this->returnValue($entity_type));
|
||||
|
||||
$field_storage = $this->getMock('Drupal\field\FieldStorageConfigInterface');
|
||||
$field_storage
|
||||
->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue('field_storage_id'));
|
||||
|
||||
$this->entity
|
||||
->expects($this->any())
|
||||
->method('getFieldStorageDefinition')
|
||||
->will($this->returnValue($field_storage));
|
||||
|
||||
$result = $this->configFieldMapper->setEntity($this->entity);
|
||||
$this->assertTrue($result);
|
||||
|
||||
// Ensure that the configuration name was added to the mapper.
|
||||
$plugin_definition = $this->configFieldMapper->getPluginDefinition();
|
||||
$this->assertTrue(in_array('config_prefix.field_storage_id', $plugin_definition['names']));
|
||||
|
||||
// Make sure setEntity() returns FALSE when called a second time.
|
||||
$result = $this->configFieldMapper->setEntity($this->entity);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\config_translation\Unit;
|
||||
|
||||
use Drupal\config_translation\ConfigMapperManager;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\TypedData\TypedDataInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Core\TypedData\DataDefinition;
|
||||
|
||||
/**
|
||||
* Tests the functionality provided by configuration translation mapper manager.
|
||||
*
|
||||
* @group config_translation
|
||||
*/
|
||||
class ConfigMapperManagerTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The configuration mapper manager to test.
|
||||
*
|
||||
* @var \Drupal\config_translation\ConfigMapperManager
|
||||
*/
|
||||
protected $configMapperManager;
|
||||
|
||||
/**
|
||||
* The typed configuration manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $typedConfigManager;
|
||||
|
||||
protected function setUp() {
|
||||
$language = new Language(array('id' => 'en'));
|
||||
$language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
$language_manager->expects($this->once())
|
||||
->method('getCurrentLanguage')
|
||||
->with(LanguageInterface::TYPE_INTERFACE)
|
||||
->will($this->returnValue($language));
|
||||
|
||||
$this->typedConfigManager = $this->getMockBuilder('Drupal\Core\Config\TypedConfigManagerInterface')
|
||||
->getMock();
|
||||
|
||||
$module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
|
||||
$theme_handler = $this->getMock('Drupal\Core\Extension\ThemeHandlerInterface');
|
||||
|
||||
$this->configMapperManager = new ConfigMapperManager(
|
||||
$this->getMock('Drupal\Core\Cache\CacheBackendInterface'),
|
||||
$language_manager,
|
||||
$module_handler,
|
||||
$this->typedConfigManager,
|
||||
$theme_handler
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigMapperManager::hasTranslatable().
|
||||
*
|
||||
* @param \Drupal\Core\TypedData\TypedDataInterface $element
|
||||
* The schema element to test.
|
||||
* @param bool $expected
|
||||
* The expected return value of ConfigMapperManager::hasTranslatable().
|
||||
*
|
||||
* @dataProvider providerTestHasTranslatable
|
||||
*/
|
||||
public function testHasTranslatable(TypedDataInterface $element, $expected) {
|
||||
$this->typedConfigManager
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('test')
|
||||
->will($this->returnValue($element));
|
||||
|
||||
$result = $this->configMapperManager->hasTranslatable('test');
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for ConfigMapperManager::testHasTranslatable()
|
||||
*
|
||||
* @return array
|
||||
* An array of arrays, where each inner array contains the schema element
|
||||
* to test as the first key and the expected result of
|
||||
* ConfigMapperManager::hasTranslatable() as the second key.
|
||||
*/
|
||||
public function providerTestHasTranslatable() {
|
||||
return array(
|
||||
array($this->getElement(array()), FALSE),
|
||||
array($this->getElement(array('aaa' => 'bbb')), FALSE),
|
||||
array($this->getElement(array('translatable' => FALSE)), FALSE),
|
||||
array($this->getElement(array('translatable' => TRUE)), TRUE),
|
||||
array($this->getNestedElement(array(
|
||||
$this->getElement(array()),
|
||||
)), FALSE),
|
||||
array($this->getNestedElement(array(
|
||||
$this->getElement(array('translatable' => TRUE)),
|
||||
)), TRUE),
|
||||
array($this->getNestedElement(array(
|
||||
$this->getElement(array('aaa' => 'bbb')),
|
||||
$this->getElement(array('ccc' => 'ddd')),
|
||||
$this->getElement(array('eee' => 'fff')),
|
||||
)), FALSE),
|
||||
array($this->getNestedElement(array(
|
||||
$this->getElement(array('aaa' => 'bbb')),
|
||||
$this->getElement(array('ccc' => 'ddd')),
|
||||
$this->getElement(array('translatable' => TRUE)),
|
||||
)), TRUE),
|
||||
array($this->getNestedElement(array(
|
||||
$this->getElement(array('aaa' => 'bbb')),
|
||||
$this->getNestedElement(array(
|
||||
$this->getElement(array('ccc' => 'ddd')),
|
||||
$this->getElement(array('eee' => 'fff')),
|
||||
)),
|
||||
$this->getNestedElement(array(
|
||||
$this->getElement(array('ggg' => 'hhh')),
|
||||
$this->getElement(array('iii' => 'jjj')),
|
||||
)),
|
||||
)), FALSE),
|
||||
array($this->getNestedElement(array(
|
||||
$this->getElement(array('aaa' => 'bbb')),
|
||||
$this->getNestedElement(array(
|
||||
$this->getElement(array('ccc' => 'ddd')),
|
||||
$this->getElement(array('eee' => 'fff')),
|
||||
)),
|
||||
$this->getNestedElement(array(
|
||||
$this->getElement(array('ggg' => 'hhh')),
|
||||
$this->getElement(array('translatable' => TRUE)),
|
||||
)),
|
||||
)), TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mocked schema element.
|
||||
*
|
||||
* @param array $definition
|
||||
* The definition of the schema element.
|
||||
*
|
||||
* @return \Drupal\Core\Config\Schema\Element
|
||||
* The mocked schema element.
|
||||
*/
|
||||
protected function getElement(array $definition) {
|
||||
$data_definition = new DataDefinition($definition);
|
||||
$element = $this->getMock('Drupal\Core\TypedData\TypedDataInterface');
|
||||
$element->expects($this->any())
|
||||
->method('getDataDefinition')
|
||||
->will($this->returnValue($data_definition));
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mocked nested schema element.
|
||||
*
|
||||
* @param array $elements
|
||||
* An array of simple schema elements.
|
||||
*
|
||||
* @return \Drupal\Core\Config\Schema\Mapping
|
||||
* A nested schema element, containing the passed-in elements.
|
||||
*/
|
||||
protected function getNestedElement(array $elements) {
|
||||
// ConfigMapperManager::findTranslatable() checks for
|
||||
// \Drupal\Core\TypedData\TraversableTypedDataInterface, but mocking that
|
||||
// directly does not work, because we need to implement \IteratorAggregate
|
||||
// in order for getIterator() to be called. Therefore we need to mock
|
||||
// \Drupal\Core\Config\Schema\ArrayElement, but that is abstract, so we
|
||||
// need to mock one of the subclasses of it.
|
||||
$nested_element = $this->getMockBuilder('Drupal\Core\Config\Schema\Mapping')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$nested_element->expects($this->once())
|
||||
->method('getIterator')
|
||||
->will($this->returnValue(new \ArrayIterator($elements)));
|
||||
return $nested_element;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,683 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\config_translation\Unit\ConfigNamesMapperTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\config_translation\Unit;
|
||||
|
||||
use Drupal\config_translation\ConfigNamesMapper;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Routing\RouteMatch;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Tests the functionality provided by the configuration names mapper.
|
||||
*
|
||||
* @group config_translation
|
||||
*/
|
||||
class ConfigNamesMapperTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The plugin definition of the test mapper.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $pluginDefinition;
|
||||
|
||||
/**
|
||||
* The configuration names mapper to test.
|
||||
*
|
||||
* @see \Drupal\config_translation\ConfigNamesMapper
|
||||
*
|
||||
* @var \Drupal\Tests\config_translation\Unit\TestConfigNamesMapper
|
||||
*/
|
||||
protected $configNamesMapper;
|
||||
|
||||
/**
|
||||
* The locale configuration manager.
|
||||
*
|
||||
* @var \Drupal\locale\LocaleConfigManager|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $localeConfigManager;
|
||||
|
||||
/**
|
||||
* The locale configuration manager.
|
||||
*
|
||||
* @var \Drupal\locale\LocaleConfigManager|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $typedConfigManager;
|
||||
|
||||
/**
|
||||
* The configuration mapper manager.
|
||||
*
|
||||
* @var \Drupal\config_translation\ConfigMapperManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $configMapperManager;
|
||||
|
||||
/**
|
||||
* The base route used for testing.
|
||||
*
|
||||
* @var \Symfony\Component\Routing\Route
|
||||
*/
|
||||
protected $baseRoute;
|
||||
|
||||
/**
|
||||
* The route provider used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RouteProviderInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $routeProvider;
|
||||
|
||||
/**
|
||||
* The mocked URL generator.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\UrlGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $urlGenerator;
|
||||
|
||||
/**
|
||||
* The mocked language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface $language_manager|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
protected function setUp() {
|
||||
$this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
|
||||
|
||||
$this->pluginDefinition = array(
|
||||
'class' => '\Drupal\config_translation\ConfigNamesMapper',
|
||||
'base_route_name' => 'system.site_information_settings',
|
||||
'title' => 'System information',
|
||||
'names' => array('system.site'),
|
||||
'weight' => 42,
|
||||
);
|
||||
|
||||
$this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
|
||||
|
||||
$this->localeConfigManager = $this->getMockBuilder('Drupal\locale\LocaleConfigManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->configMapperManager = $this->getMock('Drupal\config_translation\ConfigMapperManagerInterface');
|
||||
|
||||
$this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface');
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('url_generator', $this->urlGenerator);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
$this->baseRoute = new Route('/admin/config/system/site-information');
|
||||
|
||||
$this->routeProvider
|
||||
->expects($this->any())
|
||||
->method('getRouteByName')
|
||||
->with('system.site_information_settings')
|
||||
->will($this->returnValue($this->baseRoute));
|
||||
|
||||
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
|
||||
$this->configNamesMapper = new TestConfigNamesMapper(
|
||||
'system.site_information_settings',
|
||||
$this->pluginDefinition,
|
||||
$this->getConfigFactoryStub(),
|
||||
$this->typedConfigManager,
|
||||
$this->localeConfigManager,
|
||||
$this->configMapperManager,
|
||||
$this->routeProvider,
|
||||
$this->getStringTranslationStub(),
|
||||
$this->languageManager
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getTitle().
|
||||
*/
|
||||
public function testGetTitle() {
|
||||
$result = $this->configNamesMapper->getTitle();
|
||||
$this->assertSame($this->pluginDefinition['title'], (string) $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getBaseRouteName().
|
||||
*/
|
||||
public function testGetBaseRouteName() {
|
||||
$result = $this->configNamesMapper->getBaseRouteName();
|
||||
$this->assertSame($this->pluginDefinition['base_route_name'], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getBaseRouteParameters().
|
||||
*/
|
||||
public function testGetBaseRouteParameters() {
|
||||
$result = $this->configNamesMapper->getBaseRouteParameters();
|
||||
$this->assertSame(array(), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getBaseRoute().
|
||||
*/
|
||||
public function testGetBaseRoute() {
|
||||
$result = $this->configNamesMapper->getBaseRoute();
|
||||
$this->assertSame($this->baseRoute, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getBasePath().
|
||||
*/
|
||||
public function testGetBasePath() {
|
||||
$this->urlGenerator->expects($this->once())
|
||||
->method('getPathFromRoute')
|
||||
->with('system.site_information_settings', [])
|
||||
->willReturn('/admin/config/system/site-information');
|
||||
$result = $this->configNamesMapper->getBasePath();
|
||||
$this->assertSame('/admin/config/system/site-information', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getOverviewRouteName().
|
||||
*/
|
||||
public function testGetOverviewRouteName() {
|
||||
$result = $this->configNamesMapper->getOverviewRouteName();
|
||||
$expected = 'config_translation.item.overview.' . $this->pluginDefinition['base_route_name'];
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getOverviewRouteParameters().
|
||||
*/
|
||||
public function testGetOverviewRouteParameters() {
|
||||
$result = $this->configNamesMapper->getOverviewRouteParameters();
|
||||
$this->assertSame(array(), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getOverviewRoute().
|
||||
*/
|
||||
public function testGetOverviewRoute() {
|
||||
$expected = new Route('/admin/config/system/site-information/translate',
|
||||
array(
|
||||
'_controller' => '\Drupal\config_translation\Controller\ConfigTranslationController::itemPage',
|
||||
'plugin_id' => 'system.site_information_settings',
|
||||
),
|
||||
array(
|
||||
'_config_translation_overview_access' => 'TRUE',
|
||||
)
|
||||
);
|
||||
$result = $this->configNamesMapper->getOverviewRoute();
|
||||
$this->assertSame(serialize($expected), serialize($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getOverviewPath().
|
||||
*/
|
||||
public function testGetOverviewPath() {
|
||||
$this->urlGenerator->expects($this->once())
|
||||
->method('getPathFromRoute')
|
||||
->with('config_translation.item.overview.system.site_information_settings', [])
|
||||
->willReturn('/admin/config/system/site-information/translate');
|
||||
|
||||
$result = $this->configNamesMapper->getOverviewPath();
|
||||
$this->assertSame('/admin/config/system/site-information/translate', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getAddRouteName().
|
||||
*/
|
||||
public function testGetAddRouteName() {
|
||||
$result = $this->configNamesMapper->getAddRouteName();
|
||||
$expected = 'config_translation.item.add.' . $this->pluginDefinition['base_route_name'];
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getAddRouteParameters().
|
||||
*/
|
||||
public function testGetAddRouteParameters() {
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
|
||||
$expected = array('langcode' => 'xx');
|
||||
$result = $this->configNamesMapper->getAddRouteParameters();
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getAddRoute().
|
||||
*/
|
||||
public function testGetAddRoute() {
|
||||
$expected = new Route('/admin/config/system/site-information/translate/{langcode}/add',
|
||||
array(
|
||||
'_form' => '\Drupal\config_translation\Form\ConfigTranslationAddForm',
|
||||
'plugin_id' => 'system.site_information_settings',
|
||||
),
|
||||
array(
|
||||
'_config_translation_form_access' => 'TRUE',
|
||||
)
|
||||
);
|
||||
$result = $this->configNamesMapper->getAddRoute();
|
||||
$this->assertSame(serialize($expected), serialize($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getEditRouteName().
|
||||
*/
|
||||
public function testGetEditRouteName() {
|
||||
$result = $this->configNamesMapper->getEditRouteName();
|
||||
$expected = 'config_translation.item.edit.' . $this->pluginDefinition['base_route_name'];
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getEditRouteParameters().
|
||||
*/
|
||||
public function testGetEditRouteParameters() {
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
|
||||
$expected = array('langcode' => 'xx');
|
||||
$result = $this->configNamesMapper->getEditRouteParameters();
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getEditRoute().
|
||||
*/
|
||||
public function testGetEditRoute() {
|
||||
$expected = new Route('/admin/config/system/site-information/translate/{langcode}/edit',
|
||||
array(
|
||||
'_form' => '\Drupal\config_translation\Form\ConfigTranslationEditForm',
|
||||
'plugin_id' => 'system.site_information_settings',
|
||||
),
|
||||
array(
|
||||
'_config_translation_form_access' => 'TRUE',
|
||||
)
|
||||
);
|
||||
$result = $this->configNamesMapper->getEditRoute();
|
||||
$this->assertSame(serialize($expected), serialize($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getDeleteRouteName().
|
||||
*/
|
||||
public function testGetDeleteRouteName() {
|
||||
$result = $this->configNamesMapper->getDeleteRouteName();
|
||||
$expected = 'config_translation.item.delete.' . $this->pluginDefinition['base_route_name'];
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getDeleteRouteParameters().
|
||||
*/
|
||||
public function testGetDeleteRouteParameters() {
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
|
||||
$expected = array('langcode' => 'xx'); $result = $this->configNamesMapper->getDeleteRouteParameters();
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getRoute().
|
||||
*/
|
||||
public function testGetDeleteRoute() {
|
||||
$expected = new Route('/admin/config/system/site-information/translate/{langcode}/delete',
|
||||
array(
|
||||
'_form' => '\Drupal\config_translation\Form\ConfigTranslationDeleteForm',
|
||||
'plugin_id' => 'system.site_information_settings',
|
||||
),
|
||||
array(
|
||||
'_config_translation_form_access' => 'TRUE',
|
||||
)
|
||||
);
|
||||
$result = $this->configNamesMapper->getDeleteRoute();
|
||||
$this->assertSame(serialize($expected), serialize($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getConfigNames().
|
||||
*/
|
||||
public function testGetConfigNames() {
|
||||
$result = $this->configNamesMapper->getConfigNames();
|
||||
$this->assertSame($this->pluginDefinition['names'], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::addConfigName().
|
||||
*/
|
||||
public function testAddConfigName() {
|
||||
$names = $this->configNamesMapper->getConfigNames();
|
||||
$this->configNamesMapper->addConfigName('test');
|
||||
$names[] = 'test';
|
||||
$result = $this->configNamesMapper->getConfigNames();
|
||||
$this->assertSame($names, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getWeight().
|
||||
*/
|
||||
public function testGetWeight() {
|
||||
$result = $this->configNamesMapper->getWeight();
|
||||
$this->assertSame($this->pluginDefinition['weight'], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::populateFromRouteMatch().
|
||||
*/
|
||||
public function testPopulateFromRouteMatch() {
|
||||
// Make sure the language code is not set initially.
|
||||
$this->assertSame(NULL, $this->configNamesMapper->getInternalLangcode());
|
||||
|
||||
// Test that an empty request does not set the language code.
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'));
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
$this->assertSame(NULL, $this->configNamesMapper->getInternalLangcode());
|
||||
|
||||
// Test that a request with a 'langcode' attribute sets the language code.
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
$this->assertSame('xx', $this->configNamesMapper->getInternalLangcode());
|
||||
|
||||
// Test that the language code gets unset with the wrong request.
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'));
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
$this->assertSame(NULL, $this->configNamesMapper->getInternalLangcode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getTypeLabel().
|
||||
*/
|
||||
public function testGetTypeLabel() {
|
||||
$result = $this->configNamesMapper->getTypeLabel();
|
||||
$this->assertSame($this->pluginDefinition['title'], (string) $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getLangcode().
|
||||
*/
|
||||
public function testGetLangcode() {
|
||||
// Test that the getLangcode() falls back to 'en', if no explicit language
|
||||
// code is provided.
|
||||
$config_factory = $this->getConfigFactoryStub(array(
|
||||
'system.site' => array('key' => 'value'),
|
||||
));
|
||||
$this->configNamesMapper->setConfigFactory($config_factory);
|
||||
$result = $this->configNamesMapper->getLangcode();
|
||||
$this->assertSame('en', $result);
|
||||
|
||||
// Test that getLangcode picks up the language code provided by the
|
||||
// configuration.
|
||||
$config_factory = $this->getConfigFactoryStub(array(
|
||||
'system.site' => array('langcode' => 'xx'),
|
||||
));
|
||||
$this->configNamesMapper->setConfigFactory($config_factory);
|
||||
$result = $this->configNamesMapper->getLangcode();
|
||||
$this->assertSame('xx', $result);
|
||||
|
||||
// Test that getLangcode() works for multiple configuration names.
|
||||
$this->configNamesMapper->addConfigName('system.maintenance');
|
||||
$config_factory = $this->getConfigFactoryStub(array(
|
||||
'system.site' => array('langcode' => 'xx'),
|
||||
'system.maintenance' => array('langcode' => 'xx'),
|
||||
));
|
||||
$this->configNamesMapper->setConfigFactory($config_factory);
|
||||
$result = $this->configNamesMapper->getLangcode();
|
||||
$this->assertSame('xx', $result);
|
||||
|
||||
// Test that getLangcode() throws an exception when different language codes
|
||||
// are given.
|
||||
$config_factory = $this->getConfigFactoryStub(array(
|
||||
'system.site' => array('langcode' => 'xx'),
|
||||
'system.maintenance' => array('langcode' => 'yy'),
|
||||
));
|
||||
$this->configNamesMapper->setConfigFactory($config_factory);
|
||||
try {
|
||||
$this->configNamesMapper->getLangcode();
|
||||
$this->fail();
|
||||
}
|
||||
catch (\RuntimeException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getConfigData().
|
||||
*/
|
||||
public function testGetConfigData() {
|
||||
$configs = array(
|
||||
'system.site' => array(
|
||||
'name' => 'Drupal',
|
||||
'slogan' => 'Come for the software, stay for the community!',
|
||||
),
|
||||
'system.maintenance' => array(
|
||||
'enabled' => FALSE,
|
||||
'message' => '@site is currently under maintenance.',
|
||||
),
|
||||
'system.rss' => array(
|
||||
'items' => array(
|
||||
'limit' => 10,
|
||||
'view_mode' => 'rss',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->configNamesMapper->setConfigNames(array_keys($configs));
|
||||
$config_factory = $this->getConfigFactoryStub($configs);
|
||||
$this->configNamesMapper->setConfigFactory($config_factory);
|
||||
|
||||
$result = $this->configNamesMapper->getConfigData();
|
||||
$this->assertSame($configs, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::hasSchema().
|
||||
*
|
||||
* @param array $mock_return_values
|
||||
* An array of values that the mocked locale configuration manager should
|
||||
* return for hasConfigSchema().
|
||||
* @param bool $expected
|
||||
* The expected return value of ConfigNamesMapper::hasSchema().
|
||||
*
|
||||
* @dataProvider providerTestHasSchema
|
||||
*/
|
||||
public function testHasSchema(array $mock_return_values, $expected) {
|
||||
// As the configuration names are arbitrary, simply use integers.
|
||||
$config_names = range(1, count($mock_return_values));
|
||||
$this->configNamesMapper->setConfigNames($config_names);
|
||||
|
||||
$map = array();
|
||||
foreach ($config_names as $i => $config_name) {
|
||||
$map[] = array($config_name, $mock_return_values[$i]);
|
||||
}
|
||||
$this->typedConfigManager
|
||||
->expects($this->any())
|
||||
->method('hasConfigSchema')
|
||||
->will($this->returnValueMap($map));
|
||||
|
||||
$result = $this->configNamesMapper->hasSchema();
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for ConfigMapperTest::testHasSchema().
|
||||
*
|
||||
* @return array
|
||||
* An array of arrays, where each inner array has an array of values that
|
||||
* the mocked locale configuration manager should return for
|
||||
* hasConfigSchema() as the first value and the expected return value of
|
||||
* ConfigNamesMapper::hasSchema() as the second value.
|
||||
*/
|
||||
public function providerTestHasSchema() {
|
||||
return array(
|
||||
array(array(TRUE), TRUE),
|
||||
array(array(FALSE), FALSE),
|
||||
array(array(TRUE, TRUE, TRUE), TRUE),
|
||||
array(array(TRUE, FALSE, TRUE), FALSE),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::hasTranslatable().
|
||||
*
|
||||
* @param array $mock_return_values
|
||||
* An array of values that the mocked configuration mapper manager should
|
||||
* return for hasTranslatable().
|
||||
* @param bool $expected
|
||||
* The expected return value of ConfigNamesMapper::hasTranslatable().
|
||||
*
|
||||
* @dataProvider providerTestHasTranslatable
|
||||
*/
|
||||
public function testHasTranslatable(array $mock_return_values, $expected) {
|
||||
// As the configuration names are arbitrary, simply use integers.
|
||||
$config_names = range(1, count($mock_return_values));
|
||||
$this->configNamesMapper->setConfigNames($config_names);
|
||||
|
||||
$map = array();
|
||||
foreach ($config_names as $i => $config_name) {
|
||||
$map[] = isset($mock_return_values[$i]) ? array($config_name, $mock_return_values[$i]) : array();
|
||||
}
|
||||
$this->configMapperManager
|
||||
->expects($this->any())
|
||||
->method('hasTranslatable')
|
||||
->will($this->returnValueMap($map));
|
||||
|
||||
$result = $this->configNamesMapper->hasTranslatable();
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for ConfigNamesMapperTest::testHasTranslatable().
|
||||
*
|
||||
* @return array
|
||||
* An array of arrays, where each inner array has an array of values that
|
||||
* the mocked configuration mapper manager should return for
|
||||
* hasTranslatable() as the first value and the expected return value of
|
||||
* ConfigNamesMapper::hasTranslatable() as the second value.
|
||||
*/
|
||||
public function providerTestHasTranslatable() {
|
||||
return array(
|
||||
array(array(), FALSE),
|
||||
array(array(TRUE), TRUE),
|
||||
array(array(FALSE), FALSE),
|
||||
array(array(TRUE, TRUE, TRUE), TRUE),
|
||||
array(array(FALSE, FALSE, FALSE), FALSE),
|
||||
array(array(TRUE, FALSE, TRUE), TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::hasTranslation().
|
||||
*
|
||||
* @param array $mock_return_values
|
||||
* An array of values that the mocked configuration mapper manager should
|
||||
* return for hasTranslation().
|
||||
* @param bool $expected
|
||||
* The expected return value of ConfigNamesMapper::hasTranslation().
|
||||
*
|
||||
* @dataProvider providerTestHasTranslation
|
||||
*/
|
||||
public function testHasTranslation(array $mock_return_values, $expected) {
|
||||
$language = new Language();
|
||||
|
||||
// As the configuration names are arbitrary, simply use integers.
|
||||
$config_names = range(1, count($mock_return_values));
|
||||
$this->configNamesMapper->setConfigNames($config_names);
|
||||
|
||||
$map = array();
|
||||
foreach ($config_names as $i => $config_name) {
|
||||
$map[] = array($config_name, $language->getId(), $mock_return_values[$i]);
|
||||
}
|
||||
$this->localeConfigManager
|
||||
->expects($this->any())
|
||||
->method('hasTranslation')
|
||||
->will($this->returnValueMap($map));
|
||||
|
||||
$result = $this->configNamesMapper->hasTranslation($language);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for for ConfigNamesMapperTest::testHasTranslation().
|
||||
*
|
||||
* @return array
|
||||
* An array of arrays, where each inner array has an array of values that
|
||||
* the mocked configuration mapper manager should return for
|
||||
* hasTranslation() as the first value and the expected return value of
|
||||
* ConfigNamesMapper::hasTranslation() as the second value.
|
||||
*/
|
||||
public function providerTestHasTranslation() {
|
||||
return array(
|
||||
array(array(TRUE), TRUE),
|
||||
array(array(FALSE), FALSE),
|
||||
array(array(TRUE, TRUE, TRUE), TRUE),
|
||||
array(array(FALSE, FALSE, TRUE), TRUE),
|
||||
array(array(FALSE, FALSE, FALSE), FALSE),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::getTypeName().
|
||||
*/
|
||||
public function testGetTypeName() {
|
||||
$result = $this->configNamesMapper->getTypeName();
|
||||
$this->assertSame('Settings', (string) $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::hasTranslation().
|
||||
*/
|
||||
public function testGetOperations() {
|
||||
$expected = array(
|
||||
'translate' => array(
|
||||
'title' => 'Translate',
|
||||
'url' => Url::fromRoute('config_translation.item.overview.system.site_information_settings'),
|
||||
),
|
||||
);
|
||||
$result = $this->configNamesMapper->getOperations();
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a test mapper class.
|
||||
*/
|
||||
class TestConfigNamesMapper extends ConfigNamesMapper {
|
||||
|
||||
/**
|
||||
* Gets the internal language code of this mapper, if any.
|
||||
*
|
||||
* This method is not to be confused with
|
||||
* ConfigMapperInterface::getLangcode().
|
||||
*
|
||||
* @return string|null
|
||||
* The language code of this mapper if it is set; NULL otherwise.
|
||||
*/
|
||||
public function getInternalLangcode() {
|
||||
return isset($this->langcode) ? $this->langcode : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list of configuration names.
|
||||
*
|
||||
* @param array $config_names
|
||||
*/
|
||||
public function setConfigNames(array $config_names) {
|
||||
$this->pluginDefinition['names'] = $config_names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the configuration factory.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The config factory to set.
|
||||
*/
|
||||
public function setConfigFactory(ConfigFactoryInterface $config_factory) {
|
||||
$this->configFactory = $config_factory;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
# Attach to performance settings for testing. The base route does not matter.
|
||||
system.performance_settings:
|
||||
title: 'Theme translation test'
|
||||
base_route_name: system.performance_settings
|
||||
names:
|
||||
- system.site
|
|
@ -0,0 +1,5 @@
|
|||
name: 'Configuration Translation Test Theme'
|
||||
type: theme
|
||||
description: 'Theme for testing the configuration translation mapper system'
|
||||
version: VERSION
|
||||
core: 8.x
|
Reference in a new issue