Update to Drupal 8.1.1. For more information, see https://www.drupal.org/node/2718713

This commit is contained in:
Pantheon Automation 2016-05-04 14:35:41 -07:00 committed by Greg Anderson
parent c0a0d5a94c
commit 9eae24d844
669 changed files with 3873 additions and 1553 deletions

View file

@ -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.');
}
}

View file

@ -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');
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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');
}
}

View file

@ -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());
}
}

View file

@ -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.');
}
}

View file

@ -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();
}
}

View file

@ -178,13 +178,13 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
'target_entity_type_id' => 'test_entity_type',
'target_bundle' => 'test_bundle',
), 'language_content_settings');
$alterableConfig->setLanguageAlterable(true);
$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);
$nonAlterableConfig->setLanguageAlterable(FALSE);
$defaultConfig = new ContentLanguageSettings(array(
'target_entity_type_id' => 'test_entity_type',
@ -192,9 +192,9 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
), 'language_content_settings');
return [
[$alterableConfig, true],
[$nonAlterableConfig, false],
[$defaultConfig, false],
[$alterableConfig, TRUE],
[$nonAlterableConfig, FALSE],
[$defaultConfig, FALSE],
];
}
@ -208,11 +208,11 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
}
public function providerIsDefaultConfiguration() {
$alteredLanguage= new ContentLanguageSettings(array(
$alteredLanguage = new ContentLanguageSettings(array(
'target_entity_type_id' => 'test_entity_type',
'target_bundle' => 'test_bundle',
), 'language_content_settings');
$alteredLanguage->setLanguageAlterable(true);
$alteredLanguage->setLanguageAlterable(TRUE);
$alteredDefaultLangcode = new ContentLanguageSettings(array(
'target_entity_type_id' => 'test_entity_type',
@ -226,9 +226,9 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
), 'language_content_settings');
return [
[$alteredLanguage, false],
[$alteredDefaultLangcode, false],
[$defaultConfig, true],
[$alteredLanguage, FALSE],
[$alteredDefaultLangcode, FALSE],
[$defaultConfig, TRUE],
];
}
@ -271,11 +271,11 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
}
public function providerLoadByEntityTypeBundle() {
$alteredLanguage= new ContentLanguageSettings(array(
$alteredLanguage = new ContentLanguageSettings(array(
'target_entity_type_id' => 'test_entity_type',
'target_bundle' => 'test_bundle',
), 'language_content_settings');
$alteredLanguage->setLanguageAlterable(true);
$alteredLanguage->setLanguageAlterable(TRUE);
$langcode = $this->randomMachineName();
$alteredDefaultLangcode = new ContentLanguageSettings(array(
@ -290,10 +290,10 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
), '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],
['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],
];
}