Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
|
@ -0,0 +1 @@
|
|||
name: 'Deutsch'
|
|
@ -0,0 +1,6 @@
|
|||
name: 'Language config overridetest'
|
||||
type: module
|
||||
description: 'Support module for the language config override test.'
|
||||
core: 8.x
|
||||
package: Testing
|
||||
version: VERSION
|
|
@ -0,0 +1,8 @@
|
|||
name: 'Language form elements test'
|
||||
type: module
|
||||
description: 'Support module for the language form elements tests.'
|
||||
core: 8.x
|
||||
package: Testing
|
||||
version: VERSION
|
||||
dependencies:
|
||||
- entity_test
|
|
@ -0,0 +1,15 @@
|
|||
language_elements_test.config_element:
|
||||
path: '/language-tests/language_configuration_element'
|
||||
defaults:
|
||||
_form: '\Drupal\language_elements_test\Form\LanguageConfigurationElement'
|
||||
_title: 'Language configuration form element'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
language_elements_test.config_element_test:
|
||||
path: '/language-tests/language_configuration_element_test'
|
||||
defaults:
|
||||
_form: '\Drupal\language_elements_test\Form\LanguageConfigurationElementTest'
|
||||
_title: 'Language configuration form element'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\language_elements_test\Form\LanguageConfigurationElement.
|
||||
*/
|
||||
|
||||
namespace Drupal\language_elements_test\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
|
||||
/**
|
||||
* A form containing a language configuration element.
|
||||
*/
|
||||
class LanguageConfigurationElement extends FormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'language_elements_configuration_element';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle');
|
||||
|
||||
$form['lang_configuration'] = array(
|
||||
'#type' => 'language_configuration',
|
||||
'#entity_information' => array(
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'some_bundle',
|
||||
),
|
||||
'#default_value' => $conf,
|
||||
);
|
||||
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Save',
|
||||
);
|
||||
$form['#submit'][] = 'language_configuration_element_submit';
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\language_elements_test\Form\LanguageConfigurationElementTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\language_elements_test\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* A form containing a language select element.
|
||||
*/
|
||||
class LanguageConfigurationElementTest extends FormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'language_elements_configuration_element_test';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['langcode'] = array(
|
||||
'#title' => t('Language select'),
|
||||
'#type' => 'language_select',
|
||||
'#default_value' => language_get_default_langcode('entity_test', 'some_bundle'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
name: 'Language test'
|
||||
type: module
|
||||
description: 'Support module for the language layer tests.'
|
||||
core: 8.x
|
||||
package: Testing
|
||||
version: VERSION
|
101
core/modules/language/tests/language_test/language_test.module
Normal file
101
core/modules/language/tests/language_test/language_test.module
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Mock module for language layer tests.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
|
||||
|
||||
/**
|
||||
* Implements hook_page_top().
|
||||
*/
|
||||
function language_test_page_top() {
|
||||
if (\Drupal::moduleHandler()->moduleExists('language')) {
|
||||
language_test_store_language_negotiation();
|
||||
drupal_set_message(t('Language negotiation method: @name', array('@name' => \Drupal::languageManager()->getNegotiatedLanguageMethod())));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_types_info().
|
||||
*/
|
||||
function language_test_language_types_info() {
|
||||
if (\Drupal::state()->get('language_test.language_types')) {
|
||||
return array(
|
||||
'test_language_type' => array(
|
||||
'name' => t('Test'),
|
||||
'description' => t('A test language type.'),
|
||||
),
|
||||
'fixed_test_language_type' => array(
|
||||
'fixed' => array('test_language_negotiation_method'),
|
||||
'locked' => TRUE,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_types_info_alter().
|
||||
*/
|
||||
function language_test_language_types_info_alter(array &$language_types) {
|
||||
if (\Drupal::state()->get('language_test.content_language_type')) {
|
||||
$language_types[LanguageInterface::TYPE_CONTENT]['locked'] = FALSE;
|
||||
unset($language_types[LanguageInterface::TYPE_CONTENT]['fixed']);
|
||||
// By default languages are not configurable. Make
|
||||
// LanguageInterface::TYPE_CONTENT configurable.
|
||||
$config = \Drupal::configFactory()->getEditable('language.types');
|
||||
$configurable = $config->get('configurable');
|
||||
if (!in_array(LanguageInterface::TYPE_CONTENT, $configurable)) {
|
||||
$configurable[] = LanguageInterface::TYPE_CONTENT;
|
||||
$config->set('configurable', $configurable)->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_negotiation_info_alter().
|
||||
*/
|
||||
function language_test_language_negotiation_info_alter(array &$negotiation_info) {
|
||||
if (\Drupal::state()->get('language_test.language_negotiation_info_alter')) {
|
||||
unset($negotiation_info[LanguageNegotiationUI::METHOD_ID]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the last negotiated languages.
|
||||
*/
|
||||
function language_test_store_language_negotiation() {
|
||||
$last = array();
|
||||
foreach (\Drupal::languageManager()->getDefinedLanguageTypes() as $type) {
|
||||
$last[$type] = \Drupal::languageManager()->getCurrentLanguage($type)->getId();
|
||||
}
|
||||
\Drupal::state()->set('language_test.language_negotiation_last', $last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_fallback_candidates_alter().
|
||||
*/
|
||||
function language_test_language_fallback_candidates_alter(array &$candidates, array $context) {
|
||||
if (Drupal::state()->get('language_test.fallback_alter.candidates')) {
|
||||
unset($candidates[LanguageInterface::LANGCODE_NOT_SPECIFIED]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_fallback_candidates_OPERATION_alter().
|
||||
*/
|
||||
function language_test_language_fallback_candidates_test_alter(array &$candidates, array $context) {
|
||||
if (Drupal::state()->get('language_test.fallback_operation_alter.candidates')) {
|
||||
$langcode = LanguageInterface::LANGCODE_NOT_APPLICABLE;
|
||||
$candidates[$langcode] = $langcode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_module_preinstall().
|
||||
*/
|
||||
function language_test_module_preinstall() {
|
||||
\Drupal::state()->set('language_test.language_count_preinstall', count(\Drupal::languageManager()->getLanguages()));
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
language_test.l_active_class:
|
||||
path: '/language_test/type-link-active-class'
|
||||
defaults:
|
||||
_controller: '\Drupal\language_test\Controller\LanguageTestController::typeLinkActiveClass'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
language_test.subrequest:
|
||||
path: '/language_test/subrequest'
|
||||
defaults:
|
||||
_controller: '\Drupal\language_test\Controller\LanguageTestController::testSubRequest'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
language_test.entity_using_original_language:
|
||||
path: '/admin/language_test/entity_using_original_language/{configurable_language}'
|
||||
defaults:
|
||||
_controller: '\Drupal\language_test\Controller\LanguageTestController::testEntity'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
language_test.entity_using_current_language:
|
||||
path: '/admin/language_test/entity_using_current_language/{configurable_language}'
|
||||
defaults:
|
||||
_controller: '\Drupal\language_test\Controller\LanguageTestController::testEntity'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
options:
|
||||
parameters:
|
||||
configurable_language:
|
||||
type: entity:configurable_language
|
||||
# Force load in the interface text language selected for page.
|
||||
with_config_overrides: TRUE
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\language_test\Controller\LanguageTestController.
|
||||
*/
|
||||
|
||||
namespace Drupal\language_test\Controller;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\language\ConfigurableLanguageInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
* Controller routines for language_test routes.
|
||||
*/
|
||||
class LanguageTestController implements ContainerInjectionInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The HTTP kernel service.
|
||||
*
|
||||
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
|
||||
*/
|
||||
protected $httpKernel;
|
||||
|
||||
/**
|
||||
* The language manager service.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Constructs a new LanguageTestController object.
|
||||
*
|
||||
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel
|
||||
* An HTTP kernel.
|
||||
*/
|
||||
public function __construct(HttpKernelInterface $httpKernel, LanguageManagerInterface $language_manager) {
|
||||
$this->httpKernel = $httpKernel;
|
||||
$this->languageManager = $language_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('http_kernel'), $container->get('language_manager'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Route entity upcasting test helper.
|
||||
*
|
||||
* @param \Drupal\language\ConfigurableLanguageInterface $language
|
||||
* The ConfigurableLanguage object from the route.
|
||||
*
|
||||
* @return string
|
||||
* Testing feedback based on (translated) entity title.
|
||||
*/
|
||||
public function testEntity(ConfigurableLanguageInterface $configurable_language) {
|
||||
return array('#markup' => $this->t('Loaded %label.', array('%label' => $configurable_language->label())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns links to the current page with different langcodes.
|
||||
*
|
||||
* Using #type 'link' causes these links to be rendered with _l().
|
||||
*/
|
||||
public function typeLinkActiveClass() {
|
||||
// We assume that 'en' and 'fr' have been configured.
|
||||
$languages = $this->languageManager->getLanguages();
|
||||
return array(
|
||||
'no_language' => array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link to the current path with no langcode provided.'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => array(
|
||||
'attributes' => array(
|
||||
'id' => 'no_lang_link',
|
||||
),
|
||||
'set_active_class' => TRUE,
|
||||
),
|
||||
),
|
||||
'fr' => array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link to a French version of the current path.'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => array(
|
||||
'language' => $languages['fr'],
|
||||
'attributes' => array(
|
||||
'id' => 'fr_link',
|
||||
),
|
||||
'set_active_class' => TRUE,
|
||||
),
|
||||
),
|
||||
'en' => array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link to an English version of the current path.'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => array(
|
||||
'language' => $languages['en'],
|
||||
'attributes' => array(
|
||||
'id' => 'en_link',
|
||||
),
|
||||
'set_active_class' => TRUE,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses a sub request to retrieve the 'user' page.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* The kernels response to the sub request.
|
||||
*/
|
||||
public function testSubRequest() {
|
||||
$request = Request::createFromGlobals();
|
||||
$server = $request->server->all();
|
||||
if (basename($server['SCRIPT_FILENAME']) != basename($server['SCRIPT_NAME'])) {
|
||||
// We need this for when the test is executed by run-tests.sh.
|
||||
// @todo Remove this once run-tests.sh has been converted to use a Request
|
||||
// object.
|
||||
$server['SCRIPT_FILENAME'] = $server['SCRIPT_NAME'];
|
||||
$base_path = ltrim($server['REQUEST_URI'], '/');
|
||||
}
|
||||
else {
|
||||
$base_path = $request->getBasePath();
|
||||
}
|
||||
$sub_request = Request::create($base_path . '/user', 'GET', $request->query->all(), $request->cookies->all(), array(), $server);
|
||||
return $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\language_test\Plugin\LanguageNegotiation\LanguageNegotiationTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\language_test\Plugin\LanguageNegotiation;
|
||||
|
||||
use Drupal\language\LanguageNegotiationMethodBase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Class for identifying language from a selected language.
|
||||
*
|
||||
* @LanguageNegotiation(
|
||||
* id = "test_language_negotiation_method",
|
||||
* weight = -10,
|
||||
* name = @Translation("Test"),
|
||||
* description = @Translation("This is a test language negotiation method."),
|
||||
* types = {Drupal\Core\Language\LanguageInterface::TYPE_CONTENT,
|
||||
* "test_language_type", "fixed_test_language_type"}
|
||||
* )
|
||||
*/
|
||||
class LanguageNegotiationTest extends LanguageNegotiationMethodBase {
|
||||
|
||||
/**
|
||||
* The language negotiation method id.
|
||||
*/
|
||||
const METHOD_ID = 'test_language_negotiation_method';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLangcode(Request $request = NULL) {
|
||||
return 'it';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\language_test\Plugin\LanguageNegotiation\LanguageNegotiationTestTs.
|
||||
*/
|
||||
|
||||
namespace Drupal\language_test\Plugin\LanguageNegotiation;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Class for identifying language from a selected language.
|
||||
*
|
||||
* @LanguageNegotiation(
|
||||
* id = "test_language_negotiation_method_ts",
|
||||
* weight = -10,
|
||||
* name = @Translation("Type-specific test"),
|
||||
* description = @Translation("This is a test language negotiation method."),
|
||||
* types = {"test_language_type"}
|
||||
* )
|
||||
*/
|
||||
class LanguageNegotiationTestTs extends LanguageNegotiationTest {
|
||||
|
||||
/**
|
||||
* The language negotiation method id.
|
||||
*/
|
||||
const METHOD_ID = 'test_language_negotiation_method_ts';
|
||||
|
||||
}
|
38
core/modules/language/tests/src/ConfigurableLanguageTest.php
Normal file
38
core/modules/language/tests/src/ConfigurableLanguageTest.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\ConfigurableLanguageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language;
|
||||
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests the ConfigurableLanguage entity.
|
||||
*
|
||||
* @group language
|
||||
* @see \Drupal\language\Entity\ConfigurableLanguage.
|
||||
*/
|
||||
class ConfigurableLanguageTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
|
||||
/**
|
||||
* Tests configurable language name methods.
|
||||
*/
|
||||
public function testName() {
|
||||
$name = $this->randomMachineName();
|
||||
$language_code = $this->randomMachineName(2);
|
||||
$configurableLanguage = new ConfigurableLanguage(array('label' => $name, 'id' => $language_code), 'configurable_language');
|
||||
$this->assertEqual($configurableLanguage->getName(), $name);
|
||||
$this->assertEqual($configurableLanguage->setName('Test language')->getName(), 'Test language');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\Unit\Config\LanguageConfigOverrideTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language\Unit\Config;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\language\Config\LanguageConfigOverride;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Config\LanguageConfigOverride
|
||||
* @group Config
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigOverrideTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Language configuration override.
|
||||
*
|
||||
* @var \Drupal\language\Config\LanguageConfigOverride
|
||||
*/
|
||||
protected $configTranslation;
|
||||
|
||||
/**
|
||||
* Storage.
|
||||
*
|
||||
* @var \Drupal\Core\Config\StorageInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* Event Dispatcher.
|
||||
*
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* Typed Config.
|
||||
*
|
||||
* @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $typedConfig;
|
||||
|
||||
/**
|
||||
* The mocked cache tags invalidator.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $cacheTagsInvalidator;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->storage = $this->getMock('Drupal\Core\Config\StorageInterface');
|
||||
$this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
$this->typedConfig = $this->getMock('\Drupal\Core\Config\TypedConfigManagerInterface');
|
||||
$this->configTranslation = new LanguageConfigOverride('config.test', $this->storage, $this->typedConfig, $this->eventDispatcher);
|
||||
$this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testSaveNew() {
|
||||
$this->cacheTagsInvalidator->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['config:config.test']);
|
||||
$this->assertTrue($this->configTranslation->isNew());
|
||||
$this->configTranslation->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testSaveExisting() {
|
||||
$this->cacheTagsInvalidator->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['config:config.test']);
|
||||
$this->configTranslation->initWithData([]);
|
||||
$this->configTranslation->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*/
|
||||
public function testDelete() {
|
||||
$this->cacheTagsInvalidator->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['config:config.test']);
|
||||
$this->configTranslation->initWithData([]);
|
||||
$this->configTranslation->delete();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\Unit\ConfigurableLanguageUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language\Unit;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityType;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Tests the ConfigurableLanguage entity class.
|
||||
*
|
||||
* @group language
|
||||
* @coversDefaultClass \Drupal\language\Entity\ConfigurableLanguage
|
||||
* @see \Drupal\language\Entity\ConfigurableLanguage.
|
||||
*/
|
||||
class ConfigurableLanguageUnitTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::getDirection
|
||||
*/
|
||||
public function testDirection() {
|
||||
// Direction of language writing, an integer. Usually either
|
||||
// ConfigurableLanguage::DIRECTION_LTR or
|
||||
// ConfigurableLanguage::DIRECTION_RTL.
|
||||
$configurableLanguage = new ConfigurableLanguage(array('direction' => ConfigurableLanguage::DIRECTION_LTR), 'configurable_language');
|
||||
$this->assertEquals(ConfigurableLanguage::DIRECTION_LTR, $configurableLanguage->getDirection());
|
||||
|
||||
// Test direction again, setting direction to RTL.
|
||||
$configurableLanguage = new ConfigurableLanguage(array('direction' => ConfigurableLanguage::DIRECTION_RTL), 'configurable_language');
|
||||
$this->assertEquals(ConfigurableLanguage::DIRECTION_RTL, $configurableLanguage->getDirection());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getWeight
|
||||
* @covers ::setWeight
|
||||
*/
|
||||
public function testWeight() {
|
||||
// The weight, an integer. Used to order languages with larger positive
|
||||
// weights sinking items toward the bottom of lists.
|
||||
$configurableLanguage = new ConfigurableLanguage(array('weight' => -5), 'configurable_language');
|
||||
$this->assertEquals($configurableLanguage->getWeight(), -5);
|
||||
$this->assertEquals($configurableLanguage->setWeight(13)->getWeight(), 13);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,321 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\Unit\ContentLanguageSettingsUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language\Unit;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Entity\ContentLanguageSettings
|
||||
* @group language
|
||||
*/
|
||||
class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The entity type used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* The entity manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The ID of the type of the entity under test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $entityTypeId;
|
||||
|
||||
/**
|
||||
* The UUID generator used for testing.
|
||||
*
|
||||
* @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $uuid;
|
||||
|
||||
/**
|
||||
* The typed configuration manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $typedConfigManager;
|
||||
|
||||
/**
|
||||
* The typed configuration manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Config\Entity\ConfigEntityStorage|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $configEntityStorageInterface;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityTypeId = $this->randomMachineName();
|
||||
$this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
|
||||
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
|
||||
|
||||
$this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
|
||||
|
||||
$this->configEntityStorageInterface = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('uuid', $this->uuid);
|
||||
$container->set('config.typed', $this->typedConfigManager);
|
||||
$container->set('config.storage', $this->configEntityStorageInterface);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::calculateDependencies
|
||||
*/
|
||||
public function testCalculateDependencies() {
|
||||
// Mock the interfaces necessary to create a dependency on a bundle entity.
|
||||
$bundle_entity = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
|
||||
$bundle_entity->expects($this->any())
|
||||
->method('getConfigDependencyName')
|
||||
->will($this->returnValue('test.test_entity_type.id'));
|
||||
|
||||
$storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface');
|
||||
$storage->expects($this->any())
|
||||
->method('load')
|
||||
->with('test_bundle')
|
||||
->will($this->returnValue($bundle_entity));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with('bundle_entity_type')
|
||||
->will($this->returnValue($storage));
|
||||
|
||||
$target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
$target_entity_type->expects($this->any())
|
||||
->method('getBundleEntityType')
|
||||
->will($this->returnValue('bundle_entity_type'));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with('test_entity_type')
|
||||
->will($this->returnValue($target_entity_type));
|
||||
|
||||
$config = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$dependencies = $config->calculateDependencies();
|
||||
$this->assertContains('test.test_entity_type.id', $dependencies['config']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::id
|
||||
*/
|
||||
public function testId() {
|
||||
$config = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$this->assertSame('test_entity_type.test_bundle', $config->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTargetEntityTypeId
|
||||
*/
|
||||
public function testTargetEntityTypeId() {
|
||||
$config = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$this->assertSame('test_entity_type', $config->getTargetEntityTypeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTargetBundle
|
||||
*/
|
||||
public function testTargetBundle() {
|
||||
$config = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$this->assertSame('test_bundle', $config->getTargetBundle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getDefaultLangcode
|
||||
* @covers ::setDefaultLangcode
|
||||
*
|
||||
* @dataProvider providerDefaultLangcode
|
||||
*/
|
||||
public function testDefaultLangcode(ContentLanguageSettings $config, $expected) {
|
||||
$this->assertSame($expected, $config->getDefaultLangcode());
|
||||
}
|
||||
|
||||
public function providerDefaultLangcode() {
|
||||
$langcode = $this->randomMachineName();
|
||||
$config = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$config->setDefaultLangcode($langcode);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$config, $langcode],
|
||||
[$defaultConfig, LanguageInterface::LANGCODE_SITE_DEFAULT],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setLanguageAlterable
|
||||
* @covers ::isLanguageAlterable
|
||||
*
|
||||
* @dataProvider providerLanguageAlterable
|
||||
*/
|
||||
public function testLanguageAlterable(ContentLanguageSettings $config, $expected) {
|
||||
$this->assertSame($expected, $config->isLanguageAlterable());
|
||||
}
|
||||
|
||||
public function providerLanguageAlterable() {
|
||||
$alterableConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$alterableConfig->setLanguageAlterable(true);
|
||||
|
||||
$nonAlterableConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
), 'language_content_settings');
|
||||
$nonAlterableConfig->setLanguageAlterable(false);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$alterableConfig, true],
|
||||
[$nonAlterableConfig, false],
|
||||
[$defaultConfig, false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isDefaultConfiguration
|
||||
*
|
||||
* @dataProvider providerIsDefaultConfiguration
|
||||
*/
|
||||
public function testIsDefaultConfiguration(ContentLanguageSettings $config, $expected) {
|
||||
$this->assertSame($expected, $config->isDefaultConfiguration());
|
||||
}
|
||||
|
||||
public function providerIsDefaultConfiguration() {
|
||||
$alteredLanguage= new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$alteredLanguage->setLanguageAlterable(true);
|
||||
|
||||
$alteredDefaultLangcode = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
), 'language_content_settings');
|
||||
$alteredDefaultLangcode->setDefaultLangcode($this->randomMachineName());
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$alteredLanguage, false],
|
||||
[$alteredDefaultLangcode, false],
|
||||
[$defaultConfig, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::loadByEntityTypeBundle
|
||||
*
|
||||
* @dataProvider providerLoadByEntityTypeBundle
|
||||
*/
|
||||
public function testLoadByEntityTypeBundle($config_id, ContentLanguageSettings $existing_config = NULL, $expected_langcode, $expected_language_alterable) {
|
||||
list($type, $bundle) = explode('.', $config_id);
|
||||
|
||||
$nullConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => $type,
|
||||
'target_bundle' => $bundle,
|
||||
), 'language_content_settings');
|
||||
$this->configEntityStorageInterface
|
||||
->expects($this->any())
|
||||
->method('load')
|
||||
->with($config_id)
|
||||
->will($this->returnValue($existing_config));
|
||||
$this->configEntityStorageInterface
|
||||
->expects($this->any())
|
||||
->method('create')
|
||||
->will($this->returnValue($nullConfig));
|
||||
|
||||
$this->entityManager
|
||||
->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with('language_content_settings')
|
||||
->will($this->returnValue($this->configEntityStorageInterface));
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getEntityTypeFromClass')
|
||||
->with('Drupal\language\Entity\ContentLanguageSettings')
|
||||
->willReturn('language_content_settings');
|
||||
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle($type, $bundle);
|
||||
|
||||
$this->assertSame($expected_langcode, $config->getDefaultLangcode());
|
||||
$this->assertSame($expected_language_alterable, $config->isLanguageAlterable());
|
||||
}
|
||||
|
||||
public function providerLoadByEntityTypeBundle() {
|
||||
$alteredLanguage= new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$alteredLanguage->setLanguageAlterable(true);
|
||||
|
||||
$langcode = $this->randomMachineName();
|
||||
$alteredDefaultLangcode = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
), 'language_content_settings');
|
||||
$alteredDefaultLangcode->setDefaultLangcode($langcode);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
|
||||
return [
|
||||
['test_entity_type.test_bundle', $alteredLanguage, LanguageInterface::LANGCODE_SITE_DEFAULT, true],
|
||||
['test_entity_type.test_fixed_language_bundle', $alteredDefaultLangcode, $langcode, false],
|
||||
['test_entity_type.test_default_language_bundle', $defaultConfig, LanguageInterface::LANGCODE_SITE_DEFAULT, false],
|
||||
['test_entity_type.null_bundle', NULL, LanguageInterface::LANGCODE_SITE_DEFAULT, false],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,268 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\Unit\LanguageNegotiationUrlTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language\Unit {
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Session\UserSession;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationUrlTest extends UnitTestCase {
|
||||
|
||||
protected $languageManager;
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
|
||||
// Set up some languages to be used by the language-based path processor.
|
||||
$language_de = $this->getMock('\Drupal\Core\Language\LanguageInterface');
|
||||
$language_de->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('de'));
|
||||
$language_en = $this->getMock('\Drupal\Core\Language\LanguageInterface');
|
||||
$language_en->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('en'));
|
||||
$languages = array(
|
||||
'de' => $language_de,
|
||||
'en' => $language_en,
|
||||
);
|
||||
$this->languages = $languages;
|
||||
|
||||
// Create a language manager stub.
|
||||
$language_manager = $this->getMockBuilder('Drupal\language\ConfigurableLanguageManagerInterface')
|
||||
->getMock();
|
||||
$language_manager->expects($this->any())
|
||||
->method('getLanguages')
|
||||
->will($this->returnValue($languages));
|
||||
$this->languageManager = $language_manager;
|
||||
|
||||
// Create a user stub.
|
||||
$this->user = $this->getMockBuilder('Drupal\Core\Session\AccountInterface')
|
||||
->getMock();
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test path prefix language negotiation and outbound path processing.
|
||||
*
|
||||
* @dataProvider providerTestPathPrefix
|
||||
*/
|
||||
public function testPathPrefix($prefix, $prefixes, $expected_langcode) {
|
||||
$this->languageManager->expects($this->any())
|
||||
->method('getCurrentLanguage')
|
||||
->will($this->returnValue($this->languages[(in_array($expected_langcode, ['en', 'de'])) ? $expected_langcode : 'en']));
|
||||
|
||||
$config = $this->getConfigFactoryStub([
|
||||
'language.negotiation' => [
|
||||
'url' => [
|
||||
'source' => LanguageNegotiationUrl::CONFIG_PATH_PREFIX,
|
||||
'prefixes' => $prefixes,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$request = Request::create('/' . $prefix . '/foo', 'GET');
|
||||
$method = new LanguageNegotiationUrl();
|
||||
$method->setLanguageManager($this->languageManager);
|
||||
$method->setConfig($config);
|
||||
$method->setCurrentUser($this->user);
|
||||
$this->assertEquals($expected_langcode, $method->getLangcode($request));
|
||||
|
||||
$cacheability = new CacheableMetadata();
|
||||
$options = [];
|
||||
$method->processOutbound('foo', $options, $request, $cacheability);
|
||||
$expected_cacheability = new CacheableMetadata();
|
||||
if ($expected_langcode) {
|
||||
$this->assertSame($prefix . '/', $options['prefix']);
|
||||
$expected_cacheability->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL]);
|
||||
}
|
||||
else {
|
||||
$this->assertFalse(isset($options['prefix']));
|
||||
}
|
||||
$this->assertEquals($expected_cacheability, $cacheability);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for the path prefix test.
|
||||
*
|
||||
* @return array
|
||||
* An array of data for checking path prefix negotiation.
|
||||
*/
|
||||
public function providerTestPathPrefix() {
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'de',
|
||||
'prefixes' => [
|
||||
'de' => 'de',
|
||||
'en-uk' => 'en',
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
];
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'en-uk',
|
||||
'prefixes' => [
|
||||
'de' => 'de',
|
||||
'en' => 'en-uk',
|
||||
],
|
||||
'expected_langcode' => 'en',
|
||||
];
|
||||
// No configuration.
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'de',
|
||||
'prefixes' => array(),
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
// Non-matching prefix.
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'de',
|
||||
'prefixes' => [
|
||||
'en-uk' => 'en',
|
||||
],
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
// Non-existing language.
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'it',
|
||||
'prefixes' => [
|
||||
'it' => 'it',
|
||||
'en-uk' => 'en',
|
||||
],
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
return $path_prefix_configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test domain language negotiation and outbound path processing.
|
||||
*
|
||||
* @dataProvider providerTestDomain
|
||||
*/
|
||||
public function testDomain($http_host, $domains, $expected_langcode) {
|
||||
$this->languageManager->expects($this->any())
|
||||
->method('getCurrentLanguage')
|
||||
->will($this->returnValue($this->languages['en']));
|
||||
|
||||
$config = $this->getConfigFactoryStub([
|
||||
'language.negotiation' => [
|
||||
'url' => [
|
||||
'source' => LanguageNegotiationUrl::CONFIG_DOMAIN,
|
||||
'domains' => $domains,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$request = Request::create('', 'GET', array(), array(), array(), array('HTTP_HOST' => $http_host));
|
||||
$method = new LanguageNegotiationUrl();
|
||||
$method->setLanguageManager($this->languageManager);
|
||||
$method->setConfig($config);
|
||||
$method->setCurrentUser($this->user);
|
||||
$this->assertEquals($expected_langcode, $method->getLangcode($request));
|
||||
|
||||
$cacheability = new CacheableMetadata();
|
||||
$options = [];
|
||||
$this->assertSame('foo', $method->processOutbound('foo', $options, $request, $cacheability));
|
||||
$expected_cacheability = new CacheableMetadata();
|
||||
if ($expected_langcode !== FALSE && count($domains) > 1) {
|
||||
$expected_cacheability->setCacheMaxAge(Cache::PERMANENT)->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL, 'url.site']);
|
||||
}
|
||||
$this->assertEquals($expected_cacheability, $cacheability);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for the domain test.
|
||||
*
|
||||
* @return array
|
||||
* An array of data for checking domain negotiation.
|
||||
*/
|
||||
public function providerTestDomain() {
|
||||
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.de',
|
||||
'domains' => array(
|
||||
'de' => 'http://example.de',
|
||||
),
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
// No configuration.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.de',
|
||||
'domains' => array(),
|
||||
'expected_langcode' => FALSE,
|
||||
);
|
||||
// HTTP host with a port.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.de:8080',
|
||||
'domains' => array(
|
||||
'de' => 'http://example.de',
|
||||
),
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
// Domain configuration with https://.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.de',
|
||||
'domains' => array(
|
||||
'de' => 'https://example.de',
|
||||
),
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
// Non-matching HTTP host.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.com',
|
||||
'domains' => array(
|
||||
'de' => 'http://example.com',
|
||||
),
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
// Testing a non-existing language.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.com',
|
||||
'domains' => array(
|
||||
'it' => 'http://example.it',
|
||||
),
|
||||
'expected_langcode' => FALSE,
|
||||
);
|
||||
// Multiple domain configurations.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.com',
|
||||
'domains' => array(
|
||||
'de' => 'http://example.de',
|
||||
'en' => 'http://example.com',
|
||||
),
|
||||
'expected_langcode' => 'en',
|
||||
);
|
||||
return $domain_configuration;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @todo Remove as part of https://www.drupal.org/node/2481833.
|
||||
namespace {
|
||||
if (!function_exists('base_path')) {
|
||||
function base_path() {
|
||||
return '/';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\Unit\Menu\LanguageLocalTasksTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language\Unit\Menu;
|
||||
|
||||
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
|
||||
|
||||
/**
|
||||
* Tests existence of language local tasks.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageLocalTasksTest extends LocalTaskIntegrationTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
$this->directoryList = array(
|
||||
'language' => 'core/modules/language',
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language admin overview local tasks existence.
|
||||
*
|
||||
* @dataProvider getLanguageAdminOverviewRoutes
|
||||
*/
|
||||
public function testLanguageAdminLocalTasks($route, $expected) {
|
||||
$this->assertLocalTasks($route, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a list of routes to test.
|
||||
*/
|
||||
public function getLanguageAdminOverviewRoutes() {
|
||||
return array(
|
||||
array('entity.configurable_language.collection', array(array('entity.configurable_language.collection', 'language.negotiation'))),
|
||||
array('language.negotiation', array(array('entity.configurable_language.collection', 'language.negotiation'))),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language edit local tasks existence.
|
||||
*/
|
||||
public function testLanguageEditLocalTasks() {
|
||||
$this->assertLocalTasks('entity.configurable_language.edit_form', array(
|
||||
0 => array('entity.configurable_language.edit_form'),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue