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,97 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Condition;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the language condition, provided by the language module, is
|
||||
* working properly.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConditionTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* The condition plugin manager.
|
||||
*
|
||||
* @var \Drupal\Core\Condition\ConditionManager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system', 'language');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(array('language'));
|
||||
// Setup Italian.
|
||||
ConfigurableLanguage::createFromLangcode('it')->save();
|
||||
|
||||
$this->manager = $this->container->get('plugin.manager.condition');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the language condition.
|
||||
*/
|
||||
public function testConditions() {
|
||||
// Grab the language condition and configure it to check the content
|
||||
// language.
|
||||
$language = \Drupal::languageManager()->getLanguage('en');
|
||||
$condition = $this->manager->createInstance('language')
|
||||
->setConfig('langcodes', array('en' => 'en', 'it' => 'it'))
|
||||
->setContextValue('language', $language);
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is English, Italian.');
|
||||
|
||||
// Change to Italian only.
|
||||
$condition->setConfig('langcodes', array('it' => 'it'));
|
||||
$this->assertFalse($condition->execute(), 'Language condition fails as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is Italian.');
|
||||
|
||||
// Negate the condition
|
||||
$condition->setConfig('negate', TRUE);
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is not Italian.');
|
||||
|
||||
// Change the default language to Italian.
|
||||
$language = \Drupal::languageManager()->getLanguage('it');
|
||||
|
||||
$condition = $this->manager->createInstance('language')
|
||||
->setConfig('langcodes', array('en' => 'en', 'it' => 'it'))
|
||||
->setContextValue('language', $language);
|
||||
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is English, Italian.');
|
||||
|
||||
// Change to Italian only.
|
||||
$condition->setConfig('langcodes', array('it' => 'it'));
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is Italian.');
|
||||
|
||||
// Negate the condition
|
||||
$condition->setConfig('negate', TRUE);
|
||||
$this->assertFalse($condition->execute(), 'Language condition fails as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is not Italian.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\KernelTests\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,141 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests default language code is properly generated for entities.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class EntityDefaultLanguageTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'node', 'field', 'text', 'user', 'system');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('user');
|
||||
|
||||
// Activate Spanish language, so there are two languages activated.
|
||||
$language = $this->container->get('entity.manager')->getStorage('configurable_language')->create(array(
|
||||
'id' => 'es',
|
||||
));
|
||||
$language->save();
|
||||
|
||||
// Create a new content type which has Undefined language by default.
|
||||
$this->createContentType('ctund', LanguageInterface::LANGCODE_NOT_SPECIFIED);
|
||||
// Create a new content type which has Spanish language by default.
|
||||
$this->createContentType('ctes', 'es');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that default language code is properly set for new nodes.
|
||||
*/
|
||||
public function testEntityTranslationDefaultLanguageViaCode() {
|
||||
// With language module activated, and a content type that is configured to
|
||||
// have no language by default, a new node of this content type will have
|
||||
// "und" language code when language is not specified.
|
||||
$node = $this->createNode('ctund');
|
||||
$this->assertEqual($node->langcode->value, LanguageInterface::LANGCODE_NOT_SPECIFIED);
|
||||
// With language module activated, and a content type that is configured to
|
||||
// have no language by default, a new node of this content type will have
|
||||
// "es" language code when language is specified as "es".
|
||||
$node = $this->createNode('ctund', 'es');
|
||||
$this->assertEqual($node->langcode->value, 'es');
|
||||
|
||||
// With language module activated, and a content type that is configured to
|
||||
// have language "es" by default, a new node of this content type will have
|
||||
// "es" language code when language is not specified.
|
||||
$node = $this->createNode('ctes');
|
||||
$this->assertEqual($node->langcode->value, 'es');
|
||||
// With language module activated, and a content type that is configured to
|
||||
// have language "es" by default, a new node of this content type will have
|
||||
// "en" language code when language "en" is specified.
|
||||
$node = $this->createNode('ctes', 'en');
|
||||
$this->assertEqual($node->langcode->value, 'en');
|
||||
|
||||
// Disable language module.
|
||||
$this->disableModules(array('language'));
|
||||
|
||||
// With language module disabled, and a content type that is configured to
|
||||
// have no language specified by default, a new node of this content type
|
||||
// will have site's default language code when language is not specified.
|
||||
$node = $this->createNode('ctund');
|
||||
$this->assertEqual($node->langcode->value, 'en');
|
||||
// With language module disabled, and a content type that is configured to
|
||||
// have no language specified by default, a new node of this type will have
|
||||
// "es" language code when language "es" is specified.
|
||||
$node = $this->createNode('ctund', 'es');
|
||||
$this->assertEqual($node->langcode->value, 'es');
|
||||
|
||||
// With language module disabled, and a content type that is configured to
|
||||
// have language "es" by default, a new node of this type will have site's
|
||||
// default language code when language is not specified.
|
||||
$node = $this->createNode('ctes');
|
||||
$this->assertEqual($node->langcode->value, 'en');
|
||||
// With language module disabled, and a content type that is configured to
|
||||
// have language "es" by default, a new node of this type will have "en"
|
||||
// language code when language "en" is specified.
|
||||
$node = $this->createNode('ctes', 'en');
|
||||
$this->assertEqual($node->langcode->value, 'en');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new node content type.
|
||||
*
|
||||
* @param string $name
|
||||
* The content type name.
|
||||
* @param string $langcode
|
||||
* Default language code of the nodes of this type.
|
||||
*/
|
||||
protected function createContentType($name, $langcode) {
|
||||
$content_type = $this->container->get('entity.manager')->getStorage('node_type')->create(array(
|
||||
'name' => 'Test ' . $name,
|
||||
'title_label' => 'Title',
|
||||
'type' => $name,
|
||||
'create_body' => FALSE,
|
||||
));
|
||||
$content_type->save();
|
||||
ContentLanguageSettings::loadByEntityTypeBundle('node', $name)
|
||||
->setLanguageAlterable(FALSE)
|
||||
->setDefaultLangcode($langcode)
|
||||
->save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new node of given type and language using Entity API.
|
||||
*
|
||||
* @param string $type
|
||||
* The node content type.
|
||||
* @param string $langcode
|
||||
* (optional) Language code to pass to entity create.
|
||||
*
|
||||
* @return \Drupal\node\NodeInterface
|
||||
* The node created.
|
||||
*/
|
||||
protected function createNode($type, $langcode = NULL) {
|
||||
$values = array(
|
||||
'type' => $type,
|
||||
'title' => $this->randomString(),
|
||||
);
|
||||
if (!empty($langcode)) {
|
||||
$values['langcode'] = $langcode;
|
||||
}
|
||||
$node = $this->container->get('entity.manager')->getStorage('node')->create($values);
|
||||
return $node;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Tests the language of entity URLs.
|
||||
* @group language
|
||||
*/
|
||||
class EntityUrlLanguageTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['entity_test', 'user'];
|
||||
|
||||
/**
|
||||
* The entity being used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\ContentEntityInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test');
|
||||
$this->installEntitySchema('configurable_language');
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
ConfigurableLanguage::create(['id' => 'es'])->save();
|
||||
ConfigurableLanguage::create(['id' => 'fr'])->save();
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$config->set('url.prefixes', ['en' => 'en', 'es' => 'es', 'fr' => 'fr'])
|
||||
->save();
|
||||
|
||||
\Drupal::service('kernel')->rebuildContainer();
|
||||
|
||||
$this->createTranslatableEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that entity URLs in a language have the right language prefix.
|
||||
*/
|
||||
public function testEntityUrlLanguage() {
|
||||
$this->assertTrue(strpos($this->entity->urlInfo()->toString(), '/en/entity_test/' . $this->entity->id()) !== FALSE);
|
||||
$this->assertTrue(strpos($this->entity->getTranslation('es')->urlInfo()->toString(), '/es/entity_test/' . $this->entity->id()) !== FALSE);
|
||||
$this->assertTrue(strpos($this->entity->getTranslation('fr')->urlInfo()->toString(), '/fr/entity_test/' . $this->entity->id()) !== FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures correct entity URLs with the method language-content-entity enabled.
|
||||
*
|
||||
* Test case with the method language-content-entity enabled and configured
|
||||
* with higher and also with lower priority than the method language-url.
|
||||
*/
|
||||
public function testEntityUrlLanguageWithLanguageContentEnabled() {
|
||||
// Define the method language-content-entity with a higher priority than
|
||||
// language-url.
|
||||
$config = $this->config('language.types');
|
||||
$config->set('configurable', [LanguageInterface::TYPE_INTERFACE, LanguageInterface::TYPE_CONTENT]);
|
||||
$config->set('negotiation.language_content.enabled', [
|
||||
LanguageNegotiationContentEntity::METHOD_ID => 0,
|
||||
LanguageNegotiationUrl::METHOD_ID => 1
|
||||
]);
|
||||
$config->save();
|
||||
|
||||
// Without being on an content entity route the default entity URL tests
|
||||
// should still pass.
|
||||
$this->testEntityUrlLanguage();
|
||||
|
||||
// Now switching to an entity route, so that the URL links are generated
|
||||
// while being on an entity route.
|
||||
$this->setCurrentRequestForRoute('/entity_test/{entity_test}', 'entity.entity_test.canonical');
|
||||
|
||||
// The method language-content-entity should run before language-url and
|
||||
// append query parameter for the content language and prevent language-url
|
||||
// from overwriting the url.
|
||||
$this->assertTrue(strpos($this->entity->urlInfo('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=en') !== FALSE);
|
||||
$this->assertTrue(strpos($this->entity->getTranslation('es')->urlInfo('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=es') !== FALSE);
|
||||
$this->assertTrue(strpos($this->entity->getTranslation('fr')->urlInfo('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=fr') !== FALSE);
|
||||
|
||||
// Define the method language-url with a higher priority than
|
||||
// language-content-entity. This configuration should match the default one,
|
||||
// where the language-content-entity is turned off.
|
||||
$config->set('negotiation.language_content.enabled', [
|
||||
LanguageNegotiationUrl::METHOD_ID => 0,
|
||||
LanguageNegotiationContentEntity::METHOD_ID => 1
|
||||
]);
|
||||
$config->save();
|
||||
|
||||
// The default entity URL tests should pass again with the current
|
||||
// configuration.
|
||||
$this->testEntityUrlLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a translated entity.
|
||||
*/
|
||||
protected function createTranslatableEntity() {
|
||||
$this->entity = EntityTest::create();
|
||||
$this->entity->addTranslation('es', ['name' => 'name spanish']);
|
||||
$this->entity->addTranslation('fr', ['name' => 'name french']);
|
||||
$this->entity->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current request to a specific path with the corresponding route.
|
||||
*
|
||||
* @param string $path
|
||||
* The path for which the current request should be created.
|
||||
* @param string $route_name
|
||||
* The route name for which the route object for the request should be
|
||||
* created.
|
||||
*/
|
||||
protected function setCurrentRequestForRoute($path, $route_name) {
|
||||
$request = Request::create($path);
|
||||
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, $route_name);
|
||||
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route($path));
|
||||
$this->container->get('request_stack')->push($request);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Ensures the language config overrides can be installed.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigOverrideInstallTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'config_events_test');
|
||||
|
||||
/**
|
||||
* Tests the configuration events are not fired during install of overrides.
|
||||
*/
|
||||
public function testLanguageConfigOverrideInstall() {
|
||||
ConfigurableLanguage::createFromLangcode('de')->save();
|
||||
// Need to enable test module after creating the language otherwise saving
|
||||
// the language will install the configuration.
|
||||
$this->enableModules(array('language_config_override_test'));
|
||||
\Drupal::state()->set('config_events_test.event', FALSE);
|
||||
$this->installConfig(array('language_config_override_test'));
|
||||
$event_recorder = \Drupal::state()->get('config_events_test.event', FALSE);
|
||||
$this->assertFalse($event_recorder);
|
||||
$config = \Drupal::service('language.config_factory_override')->getOverride('de', 'language_config_override_test.settings');
|
||||
$this->assertEqual($config->get('name'), 'Deutsch');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language\Exception\DeleteDefaultLanguageException;
|
||||
|
||||
/**
|
||||
* Compares the default language from $GLOBALS against the dependency injected
|
||||
* language object.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageDependencyInjectionTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* Test dependency injected languages against a new Language object.
|
||||
*
|
||||
* @see \Drupal\Core\Language\LanguageInterface
|
||||
*/
|
||||
function testDependencyInjectedNewLanguage() {
|
||||
$expected = $this->languageManager->getDefaultLanguage();
|
||||
$result = $this->languageManager->getCurrentLanguage();
|
||||
foreach ($expected as $property => $value) {
|
||||
$this->assertEqual($expected->$property, $result->$property, format_string('The dependency injected language object %prop property equals the new Language object %prop property.', array('%prop' => $property)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dependency injected Language object against a new default language
|
||||
* object.
|
||||
*
|
||||
* @see \Drupal\Core\Language\Language
|
||||
*/
|
||||
function testDependencyInjectedNewDefaultLanguage() {
|
||||
$default_language = ConfigurableLanguage::load(\Drupal::languageManager()->getDefaultLanguage()->getId());
|
||||
// Change the language default object to different values.
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
$this->config('system.site')->set('default_langcode', 'fr')->save();
|
||||
|
||||
// The language system creates a Language object which contains the
|
||||
// same properties as the new default language object.
|
||||
$result = \Drupal::languageManager()->getCurrentLanguage();
|
||||
$this->assertIdentical($result->getId(), 'fr');
|
||||
|
||||
// Delete the language to check that we fallback to the default.
|
||||
try {
|
||||
entity_delete_multiple('configurable_language', array('fr'));
|
||||
$this->fail('Expected DeleteDefaultLanguageException thrown.');
|
||||
}
|
||||
catch (DeleteDefaultLanguageException $e) {
|
||||
$this->pass('Expected DeleteDefaultLanguageException thrown.');
|
||||
}
|
||||
|
||||
// Re-save the previous default language and the delete should work.
|
||||
$this->config('system.site')->set('default_langcode', $default_language->getId())->save();
|
||||
|
||||
entity_delete_multiple('configurable_language', array('fr'));
|
||||
$result = \Drupal::languageManager()->getCurrentLanguage();
|
||||
$this->assertIdentical($result->getId(), $default_language->getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests the language fallback behavior.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageFallbackTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$i = 0;
|
||||
foreach (array('af', 'am', 'ar') as $langcode) {
|
||||
$language = ConfigurableLanguage::createFromLangcode($langcode);
|
||||
$language->set('weight', $i--);
|
||||
$language->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language fallback candidates.
|
||||
*/
|
||||
public function testCandidates() {
|
||||
$language_list = $this->languageManager->getLanguages();
|
||||
$expected = array_keys($language_list + array(LanguageInterface::LANGCODE_NOT_SPECIFIED => NULL));
|
||||
|
||||
// Check that language fallback candidates by default are all the available
|
||||
// languages sorted by weight.
|
||||
$candidates = $this->languageManager->getFallbackCandidates();
|
||||
$this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are properly returned.');
|
||||
|
||||
// Check that candidates are alterable.
|
||||
$this->state->set('language_test.fallback_alter.candidates', TRUE);
|
||||
$expected = array_slice($expected, 0, count($expected) - 1);
|
||||
$candidates = $this->languageManager->getFallbackCandidates();
|
||||
$this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable.');
|
||||
|
||||
// Check that candidates are alterable for specific operations.
|
||||
$this->state->set('language_test.fallback_alter.candidates', FALSE);
|
||||
$this->state->set('language_test.fallback_operation_alter.candidates', TRUE);
|
||||
$expected[] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
|
||||
$expected[] = LanguageInterface::LANGCODE_NOT_APPLICABLE;
|
||||
$candidates = $this->languageManager->getFallbackCandidates(array('operation' => 'test'));
|
||||
$this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable for specific operations.');
|
||||
|
||||
// Check that when the site is monolingual no language fallback is applied.
|
||||
$langcodes_to_delete = array();
|
||||
foreach ($language_list as $langcode => $language) {
|
||||
if (!$language->isDefault()) {
|
||||
$langcodes_to_delete[] = $langcode;
|
||||
}
|
||||
}
|
||||
entity_delete_multiple('configurable_language', $langcodes_to_delete);
|
||||
$candidates = $this->languageManager->getFallbackCandidates();
|
||||
$this->assertEqual(array_values($candidates), array(LanguageInterface::LANGCODE_DEFAULT), 'Language fallback is not applied when the Language module is not enabled.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Test for dependency injected language object.
|
||||
*/
|
||||
abstract class LanguageTestBase extends KernelTestBase {
|
||||
|
||||
public static $modules = array('system', 'language', 'language_test');
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The state storage service.
|
||||
*
|
||||
* @var \Drupal\Core\State\StateInterface
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(array('language'));
|
||||
|
||||
$this->state = $this->container->get('state');
|
||||
|
||||
// Ensure we are building a new Language object for each test.
|
||||
$this->languageManager = $this->container->get('language_manager');
|
||||
$this->languageManager->reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Tests the default language variable migration.
|
||||
*/
|
||||
trait MigrateDefaultLanguageTrait {
|
||||
|
||||
/**
|
||||
* Helper method to test the migration.
|
||||
*
|
||||
* @param string $langcode
|
||||
* The langcode of the default language.
|
||||
* @param bool $existing
|
||||
* Whether the default language exists on the destination.
|
||||
*/
|
||||
protected function doTestMigration($langcode, $existing = TRUE) {
|
||||
// The default language of the test fixture is English. Change it to
|
||||
// something else before migrating, to be sure that the source site
|
||||
// default language is migrated.
|
||||
$value = 'O:8:"stdClass":11:{s:8:"language";s:2:"' . $langcode . '";s:4:"name";s:6:"French";s:6:"native";s:6:"French";s:9:"direction";s:1:"0";s:7:"enabled";i:1;s:7:"plurals";s:1:"0";s:7:"formula";s:0:"";s:6:"domain";s:0:"";s:6:"prefix";s:0:"";s:6:"weight";s:1:"0";s:10:"javascript";s:0:"";}';
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array(
|
||||
'value' => $value
|
||||
))
|
||||
->condition('name', 'language_default' )
|
||||
->execute();
|
||||
|
||||
$this->startCollectingMessages();
|
||||
$this->executeMigrations(['language', 'default_language']);
|
||||
|
||||
if ($existing) {
|
||||
// If the default language exists, we should be able to load it and the
|
||||
// default_langcode config should be set.
|
||||
$default_language = ConfigurableLanguage::load($langcode);
|
||||
$this->assertNotNull($default_language);
|
||||
$this->assertSame($langcode, $this->config('system.site')->get('default_langcode'));
|
||||
}
|
||||
else {
|
||||
// Otherwise, the migration log should contain an error message.
|
||||
$messages = $this->migration->getIdMap()->getMessageIterator();
|
||||
$count = 0;
|
||||
foreach ($messages as $message) {
|
||||
$count++;
|
||||
$this->assertSame($message->message, "The language '$langcode' does not exist on this site.");
|
||||
$this->assertSame((int) $message->level, MigrationInterface::MESSAGE_ERROR);
|
||||
}
|
||||
$this->assertSame($count, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to test migrating the default language when no default language is set.
|
||||
*/
|
||||
protected function doTestMigrationWithUnsetVariable() {
|
||||
// Delete the language_default variable.
|
||||
$this->sourceDatabase->delete('variable')
|
||||
->condition('name', 'language_default' )
|
||||
->execute();
|
||||
|
||||
$this->startCollectingMessages();
|
||||
$this->executeMigrations(['language', 'default_language']);
|
||||
$messages = $this->migration->getIdMap()->getMessageIterator()->fetchAll();
|
||||
|
||||
// Make sure there's no migration exceptions.
|
||||
$this->assertEmpty($messages);
|
||||
|
||||
// Make sure the default langcode is 'en', since it was the default on D6 & D7.
|
||||
$this->assertSame('en', $this->config('system.site')->get('default_langcode'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\language\Kernel\Migrate\MigrateDefaultLanguageTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests the default language variable migration.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateDefaultLanguageTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use MigrateDefaultLanguageTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests language_default migration with an existing language.
|
||||
*/
|
||||
public function testMigrationWithExistingLanguage() {
|
||||
$this->doTestMigration('fr');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language_default migration with a non-existing language.
|
||||
*/
|
||||
public function testMigrationWithNonExistentLanguage() {
|
||||
$this->doTestMigration('tv', FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language_default migration with unset variable.
|
||||
*/
|
||||
public function testMigrationWithUnsetVariable() {
|
||||
$this->doTestMigrationWithUnsetVariable();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of language content setting variables,
|
||||
* language_content_type_$type, i18n_node_options_* and i18n_lock_node_*.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateLanguageContentSettingsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'text', 'language', 'content_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(['node']);
|
||||
$this->executeMigrations(['d6_node_type', 'd6_language_content_settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of content language settings.
|
||||
*/
|
||||
public function testLanguageContent() {
|
||||
// Assert that a translatable content is still translatable.
|
||||
$config = $this->config('language.content_settings.node.article');
|
||||
$this->assertSame($config->get('target_entity_type_id'), 'node');
|
||||
$this->assertSame($config->get('target_bundle'), 'article');
|
||||
$this->assertSame($config->get('default_langcode'), 'current_interface');
|
||||
$this->assertTrue($config->get('third_party_settings.content_translation.enabled'));
|
||||
|
||||
// Assert that a non-translatable content is not translatable.
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'company');
|
||||
$this->assertTrue($config->isDefaultConfiguration());
|
||||
$this->assertFalse($config->isLanguageAlterable());
|
||||
$this->assertSame($config->getDefaultLangcode(), 'site_default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of content language settings when there is no language lock.
|
||||
*/
|
||||
public function testLanguageContentWithNoLanguageLock() {
|
||||
// Assert that a we can assign a language.
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'employee');
|
||||
$this->assertSame($config->getDefaultLangcode(), 'current_interface');
|
||||
$this->assertTrue($config->isLanguageAlterable());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests the migration of language negotiation and language types.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests the migration with LANGUAGE_NEGOTIATION_PATH_DEFAULT.
|
||||
*/
|
||||
public function testLanguageNegotiationWithDefaultPathPrefix() {
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
'd6_language_types',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_PATH_PREFIX);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_prefixes = [
|
||||
'en' => '',
|
||||
'fr' => 'fr',
|
||||
'zu' => 'zu',
|
||||
];
|
||||
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
|
||||
|
||||
$config = $this->config('language.types');
|
||||
$this->assertSame($config->get('all'), ['language_interface', 'language_content', 'language_url']);
|
||||
$this->assertSame($config->get('configurable'), ['language_interface']);
|
||||
$this->assertSame($config->get('negotiation.language_content.enabled'), ['language-interface' => 0]);
|
||||
$this->assertSame($config->get('negotiation.language_url.enabled'), ['language-url' => 0, 'language-url-fallback' => 1]);
|
||||
$expected_language_interface = [
|
||||
'language-url' => 0,
|
||||
'language-selected' => 1,
|
||||
];
|
||||
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with LANGUAGE_NEGOTIATION_NONE.
|
||||
*/
|
||||
public function testLanguageNegotiationWithNoNegotiation() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(0)))
|
||||
->condition('name', 'language_negotiation')
|
||||
->execute();
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
'd6_language_types',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_PATH_PREFIX);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
|
||||
$config = $this->config('language.types');
|
||||
$this->assertSame($config->get('all'), ['language_interface', 'language_content', 'language_url']);
|
||||
$this->assertSame($config->get('configurable'), ['language_interface']);
|
||||
$this->assertSame($config->get('negotiation.language_content.enabled'), ['language-interface' => 0]);
|
||||
$this->assertSame($config->get('negotiation.language_url.enabled'), ['language-url' => 0, 'language-url-fallback' => 1]);
|
||||
$expected_language_interface = [
|
||||
'language-selected' => 0,
|
||||
];
|
||||
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with LANGUAGE_NEGOTIATION_PATH.
|
||||
*/
|
||||
public function testLanguageNegotiationWithPathPrefix() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(2)))
|
||||
->condition('name', 'language_negotiation')
|
||||
->execute();
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
'd6_language_types',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_PATH_PREFIX);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_prefixes = [
|
||||
'en' => '',
|
||||
'fr' => 'fr',
|
||||
'zu' => 'zu',
|
||||
];
|
||||
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
|
||||
|
||||
$config = $this->config('language.types');
|
||||
$this->assertSame($config->get('all'), ['language_interface', 'language_content', 'language_url']);
|
||||
$this->assertSame($config->get('configurable'), ['language_interface']);
|
||||
$this->assertSame($config->get('negotiation.language_content.enabled'), ['language-interface' => 0]);
|
||||
$this->assertSame($config->get('negotiation.language_url.enabled'), ['language-url' => 0, 'language-url-fallback' => 1]);
|
||||
$expected_language_interface = [
|
||||
'language-url' => 0,
|
||||
'language-user' => 1,
|
||||
'language-browser' => 2,
|
||||
'language-selected' => 3,
|
||||
];
|
||||
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with LANGUAGE_NEGOTIATION_DOMAIN.
|
||||
*/
|
||||
public function testLanguageNegotiationWithDomain() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(3)))
|
||||
->condition('name', 'language_negotiation')
|
||||
->execute();
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
'd6_language_types',
|
||||
]);
|
||||
|
||||
global $base_url;
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_DOMAIN);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_domains = [
|
||||
'en' => parse_url($base_url, PHP_URL_HOST),
|
||||
'fr' => 'fr.drupal.org',
|
||||
'zu' => 'zu.drupal.org',
|
||||
];
|
||||
$this->assertSame($config->get('url.domains'), $expected_domains);
|
||||
|
||||
$config = $this->config('language.types');
|
||||
$this->assertSame($config->get('all'), ['language_interface', 'language_content', 'language_url']);
|
||||
$this->assertSame($config->get('configurable'), ['language_interface']);
|
||||
$this->assertSame($config->get('negotiation.language_content.enabled'), ['language-interface' => 0]);
|
||||
$this->assertSame($config->get('negotiation.language_url.enabled'), ['language-url' => 0, 'language-url-fallback' => 1]);
|
||||
$expected_language_interface = [
|
||||
'language-url' => 0,
|
||||
'language-selected' => 1,
|
||||
];
|
||||
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\language\Kernel\Migrate\MigrateDefaultLanguageTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests the default language variable migration.
|
||||
*
|
||||
* @group migrate_drupal_7
|
||||
*/
|
||||
class MigrateDefaultLanguageTest extends MigrateDrupal7TestBase {
|
||||
|
||||
use MigrateDefaultLanguageTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests language_default migration with a non-existing language.
|
||||
*/
|
||||
public function testMigrationWithExistingLanguage() {
|
||||
$this->doTestMigration('is');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language_default migration with a non-existing language.
|
||||
*/
|
||||
public function testMigrationWithNonExistentLanguage() {
|
||||
$this->doTestMigration('tv', FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language_default migration with unset variable.
|
||||
*/
|
||||
public function testMigrationWithUnsetVariable() {
|
||||
$this->doTestMigrationWithUnsetVariable();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of language content setting variables,
|
||||
* language_content_type_$type, i18n_node_options_* and i18n_lock_node_*.
|
||||
*
|
||||
* @group migrate_drupal_7
|
||||
*/
|
||||
class MigrateLanguageContentSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'text', 'language', 'content_translation'];
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(['node']);
|
||||
$this->executeMigrations(['d7_node_type', 'd7_language_content_settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of content language settings.
|
||||
*/
|
||||
public function testLanguageContent() {
|
||||
// Assert that a translatable content is still translatable.
|
||||
$config = $this->config('language.content_settings.node.blog');
|
||||
$this->assertIdentical($config->get('target_entity_type_id'), 'node');
|
||||
$this->assertIdentical($config->get('target_bundle'), 'blog');
|
||||
$this->assertIdentical($config->get('default_langcode'), 'current_interface');
|
||||
$this->assertFalse($config->get('language_alterable'));
|
||||
$this->assertTrue($config->get('third_party_settings.content_translation.enabled'));
|
||||
|
||||
// Assert that a non-translatable content is not translatable.
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'page');
|
||||
$this->assertTrue($config->isDefaultConfiguration());
|
||||
$this->assertFalse($config->isLanguageAlterable());
|
||||
$this->assertSame($config->getDefaultLangcode(), 'site_default');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests the migration of language negotiation.
|
||||
*
|
||||
* @group migrate_drupal_7
|
||||
*/
|
||||
class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests migration of language types variables to language.types.yml.
|
||||
*/
|
||||
public function testLanguageTypes() {
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_language_negotiation_settings',
|
||||
'd7_language_types',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.types');
|
||||
$this->assertSame($config->get('all'), ['language_content', 'language_url', 'language_interface']);
|
||||
$this->assertSame($config->get('configurable'), ['language_interface']);
|
||||
$this->assertSame($config->get('negotiation.language_content'), ['enabled' => ['language-interface' => 0]]);
|
||||
$this->assertSame($config->get('negotiation.language_url'), ['enabled' => ['language-url' => 0, 'language-url-fallback' => 1]]);
|
||||
$expected_language_interface = [
|
||||
'enabled' => [
|
||||
'language-url' => -9,
|
||||
'language-user' => -10,
|
||||
'language-selected' => -6,
|
||||
],
|
||||
'method_weights' => [
|
||||
'language-url' => -9,
|
||||
'language-session' => -8,
|
||||
'language-user' => -10,
|
||||
'language-browser' => -7,
|
||||
'language-selected' => -6,
|
||||
],
|
||||
];
|
||||
$this->assertSame($config->get('negotiation.language_interface'), $expected_language_interface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with prefix negotiation.
|
||||
*/
|
||||
public function testLanguageNegotiationWithPrefix() {
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_PATH_PREFIX);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_prefixes = [
|
||||
'en' => '',
|
||||
'is' => 'is',
|
||||
];
|
||||
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with domain negotiation.
|
||||
*/
|
||||
public function testLanguageNegotiationWithDomain() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(1)))
|
||||
->condition('name', 'locale_language_negotiation_url_part')
|
||||
->execute();
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
]);
|
||||
|
||||
global $base_url;
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_DOMAIN);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_domains = [
|
||||
'en' => parse_url($base_url, PHP_URL_HOST),
|
||||
'is' => 'is.drupal.org',
|
||||
];
|
||||
$this->assertSame($config->get('url.domains'), $expected_domains);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with non-existent variables.
|
||||
*/
|
||||
public function testLanguageNegotiationWithNonExistentVariables() {
|
||||
$this->sourceDatabase->delete('variable')
|
||||
->condition('name', ['local_language_negotiation_url_part', 'local_language_negotiation_session_param'], 'IN')
|
||||
->execute();
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_PATH_PREFIX);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_prefixes = [
|
||||
'en' => '',
|
||||
'is' => 'is',
|
||||
];
|
||||
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the argument language handler.
|
||||
*
|
||||
* @group language
|
||||
* @see \Drupal\language\Plugin\views\argument\Language.php
|
||||
*/
|
||||
class ArgumentLanguageTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view');
|
||||
|
||||
/**
|
||||
* Tests the language argument.
|
||||
*/
|
||||
public function testArgument() {
|
||||
$view = Views::getView('test_view');
|
||||
foreach (array('en' => 'John', 'xx-lolspeak' => 'George') as $langcode => $name) {
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->overrideOption('arguments', array(
|
||||
'langcode' => array(
|
||||
'id' => 'langcode',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'langcode',
|
||||
),
|
||||
));
|
||||
$this->executeView($view, array($langcode));
|
||||
|
||||
$expected = array(array(
|
||||
'name' => $name,
|
||||
));
|
||||
$this->assertIdenticalResultset($view, $expected, array('views_test_data_name' => 'name'));
|
||||
$view->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the field language handler.
|
||||
*
|
||||
* @group language
|
||||
* @see \Drupal\language\Plugin\views\field\Language
|
||||
*/
|
||||
class FieldLanguageTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view');
|
||||
|
||||
/**
|
||||
* Tests the language field.
|
||||
*/
|
||||
public function testField() {
|
||||
$view = Views::getView('test_view');
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->overrideOption('fields', array(
|
||||
'langcode' => array(
|
||||
'id' => 'langcode',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'langcode',
|
||||
),
|
||||
));
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual($view->field['langcode']->advancedRender($view->result[0]), 'English');
|
||||
$this->assertEqual($view->field['langcode']->advancedRender($view->result[1]), 'Lolspeak');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the filter language handler.
|
||||
*
|
||||
* @group language
|
||||
* @see \Drupal\language\Plugin\views\filter\Language
|
||||
*/
|
||||
class FilterLanguageTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view');
|
||||
|
||||
/**
|
||||
* Tests the language filter.
|
||||
*/
|
||||
public function testFilter() {
|
||||
$view = Views::getView('test_view');
|
||||
foreach (array('en' => 'John', 'xx-lolspeak' => 'George') as $langcode => $name) {
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->overrideOption('filters', array(
|
||||
'langcode' => array(
|
||||
'id' => 'langcode',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'langcode',
|
||||
'value' => array($langcode),
|
||||
),
|
||||
));
|
||||
$this->executeView($view);
|
||||
|
||||
$expected = array(array(
|
||||
'name' => $name,
|
||||
));
|
||||
$this->assertIdenticalResultset($view, $expected, array('views_test_data_name' => 'name'));
|
||||
|
||||
$expected = [
|
||||
'***LANGUAGE_site_default***',
|
||||
'***LANGUAGE_language_interface***',
|
||||
'***LANGUAGE_language_content***',
|
||||
'en',
|
||||
'xx-lolspeak',
|
||||
'und',
|
||||
'zxx'
|
||||
];
|
||||
$this->assertIdentical(array_keys($view->filter['langcode']->getValueOptions()), $expected);
|
||||
|
||||
$view->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Views;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
|
||||
/**
|
||||
* Defines the base class for all Language handler tests.
|
||||
*/
|
||||
abstract class LanguageTestBase extends ViewsKernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system', 'language');
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp();
|
||||
$this->installConfig(array('language'));
|
||||
|
||||
// Create another language beside English.
|
||||
ConfigurableLanguage::create(array('id' => 'xx-lolspeak', 'label' => 'Lolspeak'))->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function schemaDefinition() {
|
||||
$schema = parent::schemaDefinition();
|
||||
$schema['views_test_data']['fields']['langcode'] = array(
|
||||
'description' => 'The {language}.langcode of this beatle.',
|
||||
'type' => 'varchar',
|
||||
'length' => 12,
|
||||
'default' => '',
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test_data']['langcode'] = array(
|
||||
'title' => t('Langcode'),
|
||||
'help' => t('Langcode'),
|
||||
'field' => array(
|
||||
'id' => 'language',
|
||||
),
|
||||
'argument' => array(
|
||||
'id' => 'language',
|
||||
),
|
||||
'filter' => array(
|
||||
'id' => 'language',
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function dataSet() {
|
||||
$data = parent::dataSet();
|
||||
$data[0]['langcode'] = 'en';
|
||||
$data[1]['langcode'] = 'xx-lolspeak';
|
||||
$data[2]['langcode'] = '';
|
||||
$data[3]['langcode'] = '';
|
||||
$data[4]['langcode'] = '';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
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}
|
||||
*/
|
||||
protected 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,44 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit;
|
||||
|
||||
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,300 @@
|
|||
<?php
|
||||
|
||||
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.
|
||||
$target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
$target_entity_type->expects($this->any())
|
||||
->method('getBundleConfigDependency')
|
||||
->will($this->returnValue(array('type' => 'config', 'name' => 'test.test_entity_type.id')));
|
||||
|
||||
$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()->getDependencies();
|
||||
$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,262 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
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();
|
||||
$cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);
|
||||
$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 BubbleableMetadata();
|
||||
$options = [];
|
||||
$method->processOutbound('foo', $options, $request, $cacheability);
|
||||
$expected_cacheability = new BubbleableMetadata();
|
||||
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 BubbleableMetadata();
|
||||
$options = [];
|
||||
$this->assertSame('foo', $method->processOutbound('foo', $options, $request, $cacheability));
|
||||
$expected_cacheability = new BubbleableMetadata();
|
||||
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 Drupal\language\Plugin\LanguageNegotiation;
|
||||
|
||||
if (!function_exists('base_path')) {
|
||||
function base_path() {
|
||||
return '/';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
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'),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\Migrate;
|
||||
|
||||
use Drupal\language\Plugin\migrate\source\Language;
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\migrate\source\Language
|
||||
* @group language
|
||||
*/
|
||||
class LanguageTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = Language::class;
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'language',
|
||||
),
|
||||
);
|
||||
|
||||
protected $databaseContents = array(
|
||||
'languages' => array(
|
||||
array(
|
||||
'language' => 'en',
|
||||
'name' => 'English',
|
||||
'native' => 'English',
|
||||
'direction' => '0',
|
||||
'enabled' => '1',
|
||||
'plurals' => '0',
|
||||
'formula' => '',
|
||||
'domain' => '',
|
||||
'prefix' => '',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
),
|
||||
array(
|
||||
'language' => 'fr',
|
||||
'name' => 'French',
|
||||
'native' => 'Français',
|
||||
'direction' => '0',
|
||||
'enabled' => '0',
|
||||
'plurals' => '2',
|
||||
'formula' => '($n>1)',
|
||||
'domain' => '',
|
||||
'prefix' => 'fr',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'language' => 'en',
|
||||
'name' => 'English',
|
||||
'native' => 'English',
|
||||
'direction' => '0',
|
||||
'enabled' => '1',
|
||||
'plurals' => '0',
|
||||
'formula' => '',
|
||||
'domain' => '',
|
||||
'prefix' => '',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
),
|
||||
array(
|
||||
'language' => 'fr',
|
||||
'name' => 'French',
|
||||
'native' => 'Français',
|
||||
'direction' => '0',
|
||||
'enabled' => '0',
|
||||
'plurals' => '2',
|
||||
'formula' => '($n>1)',
|
||||
'domain' => '',
|
||||
'prefix' => 'fr',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
),
|
||||
);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\process;
|
||||
|
||||
use Drupal\language\Plugin\migrate\process\LanguageDomains;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageDomains
|
||||
* @group language
|
||||
*/
|
||||
class LanguageDomainsTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $backupGlobalsBlacklist = ['base_url'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$configuration = [
|
||||
'key' => 'language',
|
||||
'value' => 'domain',
|
||||
];
|
||||
$this->plugin = new LanguageDomains($configuration, 'map', []);
|
||||
parent::setUp();
|
||||
|
||||
// The language_domains plugin calls getSourceProperty() to check if domain
|
||||
// negotiation is used. If it is the values will be processed so we need it
|
||||
// to return TRUE to be able to test the process.
|
||||
$this->row->expects($this->once())
|
||||
->method('getSourceProperty')
|
||||
->will($this->returnValue(TRUE));
|
||||
|
||||
// The language_domains plugin use $base_url to fill empty domains.
|
||||
global $base_url;
|
||||
$base_url = 'http://example.com';
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::transform
|
||||
*/
|
||||
public function testTransform() {
|
||||
$source = [
|
||||
['language' => 'en', 'domain' => ''],
|
||||
['language' => 'fr', 'domain' => 'fr.example.com'],
|
||||
['language' => 'es', 'domain' => 'http://es.example.com'],
|
||||
['language' => 'hu', 'domain' => 'https://hu.example.com'],
|
||||
];
|
||||
$expected = [
|
||||
'en' => 'example.com',
|
||||
'fr' => 'fr.example.com',
|
||||
'es' => 'es.example.com',
|
||||
'hu' => 'hu.example.com',
|
||||
];
|
||||
$value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, $expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\process;
|
||||
|
||||
use Drupal\language\Plugin\migrate\process\LanguageNegotiation;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageNegotiation
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new LanguageNegotiation([], 'map', []);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests successful transformation without weights.
|
||||
*/
|
||||
public function testTransformWithWeights() {
|
||||
$source = [
|
||||
[
|
||||
'locale-url' => [],
|
||||
'language-default' => [],
|
||||
],
|
||||
[
|
||||
'locale-url' => -10,
|
||||
'locale-session' => -9,
|
||||
'locale-user' => -8,
|
||||
'locale-browser' => -7,
|
||||
'language-default' => -6,
|
||||
],
|
||||
];
|
||||
$expected = [
|
||||
'enabled' => [
|
||||
'language-url' => -10,
|
||||
'language-selected' => -6,
|
||||
],
|
||||
'method_weights' => [
|
||||
'language-url' => -10,
|
||||
'language-session' => -9,
|
||||
'language-user' => -8,
|
||||
'language-browser' => -7,
|
||||
'language-selected' => -6,
|
||||
],
|
||||
];
|
||||
$value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests successful transformation without weights.
|
||||
*/
|
||||
public function testTransformWithoutWeights() {
|
||||
$source = [
|
||||
[
|
||||
'locale-url' => [],
|
||||
'locale-url-fallback' => [],
|
||||
],
|
||||
];
|
||||
$expected = [
|
||||
'enabled' => [
|
||||
'language-url' => 0,
|
||||
'language-url-fallback' => 1,
|
||||
],
|
||||
];
|
||||
$value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests string input.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage The input should be an array
|
||||
*/
|
||||
public function testStringInput() {
|
||||
$this->plugin = new LanguageNegotiation([], 'map', []);
|
||||
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\process;
|
||||
|
||||
use Drupal\language\Plugin\migrate\process\LanguageTypes;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageTypes
|
||||
* @group language
|
||||
*/
|
||||
class LanguageTypesTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* Tests successful transformation of all language types.
|
||||
*/
|
||||
public function testTransformAll() {
|
||||
$this->plugin = new LanguageTypes([], 'map', []);
|
||||
$source = [
|
||||
'language' => TRUE,
|
||||
'language_url' => FALSE,
|
||||
'language_content' => FALSE,
|
||||
];
|
||||
$expected = [
|
||||
0 => 'language_url',
|
||||
1 => 'language_content',
|
||||
2 => 'language_interface',
|
||||
];
|
||||
$value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests successful transformation of configurable language types.
|
||||
*/
|
||||
public function testTransformConfigurable() {
|
||||
$this->plugin = new LanguageTypes(['filter_configurable' => TRUE], 'map', []);
|
||||
$source = [
|
||||
'language' => TRUE,
|
||||
'language_url' => FALSE,
|
||||
'language_content' => FALSE,
|
||||
];
|
||||
$expected = [
|
||||
0 => 'language_interface',
|
||||
];
|
||||
$value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests string input.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage The input should be an array
|
||||
*/
|
||||
public function testStringInput() {
|
||||
$this->plugin = new LanguageTypes([], 'map', []);
|
||||
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in a new issue