Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -0,0 +1,38 @@
<?php
/**
* @file
* Contains \Drupal\language\Tests\ConfigurableLanguageTest.
*/
namespace Drupal\language\Tests;
use Drupal\simpletest\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
/**
* Tests the ConfigurableLanguage entity.
*
* @group language
* @see \Drupal\language\Entity\ConfigurableLanguage.
*/
class ConfigurableLanguageTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('language');
/**
* Tests configurable language name methods.
*/
public function testName() {
$name = $this->randomMachineName();
$language_code = $this->randomMachineName(2);
$configurableLanguage = new ConfigurableLanguage(array('label' => $name, 'id' => $language_code), 'configurable_language');
$this->assertEqual($configurableLanguage->getName(), $name);
$this->assertEqual($configurableLanguage->setName('Test language')->getName(), 'Test language');
}
}

View file

@ -29,9 +29,9 @@ class LanguageConfigOverrideImportTest extends WebTestBase {
*/
public function testConfigOverrideImport() {
ConfigurableLanguage::createFromLangcode('fr')->save();
/* @var \Drupal\Core\Config\StorageInterface $staging */
$staging = \Drupal::service('config.storage.staging');
$this->copyConfig(\Drupal::service('config.storage'), $staging);
/* @var \Drupal\Core\Config\StorageInterface $sync */
$sync = \Drupal::service('config.storage.sync');
$this->copyConfig(\Drupal::service('config.storage'), $sync);
// Uninstall the language module and its dependencies so we can test
// enabling the language module and creating overrides at the same time
@ -41,11 +41,11 @@ class LanguageConfigOverrideImportTest extends WebTestBase {
// ConfigFactory.
$this->rebuildContainer();
/* @var \Drupal\Core\Config\StorageInterface $override_staging */
$override_staging = $staging->createCollection('language.fr');
// Create some overrides in staging.
$override_staging->write('system.site', array('name' => 'FR default site name'));
$override_staging->write('system.maintenance', array('message' => 'FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience'));
/* @var \Drupal\Core\Config\StorageInterface $override_sync */
$override_sync = $sync->createCollection('language.fr');
// Create some overrides in sync.
$override_sync->write('system.site', array('name' => 'FR default site name'));
$override_sync->write('system.maintenance', array('message' => 'FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience'));
$this->configImporter()->import();
$this->rebuildContainer();
@ -71,14 +71,14 @@ class LanguageConfigOverrideImportTest extends WebTestBase {
ConfigurableLanguage::createFromLangcode('fr')->save();
/* @var \Drupal\Core\Config\StorageInterface $staging */
$staging = \Drupal::service('config.storage.staging');
$this->copyConfig(\Drupal::service('config.storage'), $staging);
/* @var \Drupal\Core\Config\StorageInterface $sync */
$sync = \Drupal::service('config.storage.sync');
$this->copyConfig(\Drupal::service('config.storage'), $sync);
/* @var \Drupal\Core\Config\StorageInterface $override_staging */
$override_staging = $staging->createCollection('language.fr');
// Create some overrides in staging.
$override_staging->write('system.site', array('name' => 'FR default site name'));
/* @var \Drupal\Core\Config\StorageInterface $override_sync */
$override_sync = $sync->createCollection('language.fr');
// Create some overrides in sync.
$override_sync->write('system.site', array('name' => 'FR default site name'));
\Drupal::state()->set('config_events_test.event', FALSE);
$this->configImporter()->import();

View file

@ -152,7 +152,7 @@ class LanguageConfigurationElementTest extends WebTestBase {
}
/**
* Tests that the configuration is updated when the node type is changed.
* Tests that the configuration is retained when the node type is updated.
*/
public function testNodeTypeUpdate() {
// Create the article content type first if the profile used is not the
@ -172,16 +172,16 @@ class LanguageConfigurationElementTest extends WebTestBase {
$uuid = $configuration->uuid();
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been saved on the Article content type.');
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been saved on the Article content type.');
// Rename the article content type.
// Update the article content type by changing the title label.
$edit = array(
'type' => 'article_2'
'title_label' => 'Name'
);
$this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
// Check that we still have the settings for the new node type.
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article_2');
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been kept on the new Article content type.');
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been kept on the new Article content type.');
$this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the new Article content type.');
// Check that we still have the settings for the updated node type.
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article');
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been kept on the updated Article content type.');
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been kept on the updated Article content type.');
$this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the updated Article content type.');
}
/**
@ -220,7 +220,7 @@ class LanguageConfigurationElementTest extends WebTestBase {
}
/**
* Tests that the configuration is updated when a vocabulary is changed.
* Tests that the configuration is retained when a vocabulary is updated.
*/
public function testTaxonomyVocabularyUpdate() {
$vocabulary = entity_create('taxonomy_vocabulary', array(
@ -242,16 +242,16 @@ class LanguageConfigurationElementTest extends WebTestBase {
$uuid = $configuration->uuid();
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been saved on the Country vocabulary.');
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been saved on the Country vocabulary.');
// Rename the vocabulary.
// Update the vocabulary.
$edit = array(
'vid' => 'nation'
'name' => 'Nation'
);
$this->drupalPostForm('admin/structure/taxonomy/manage/country', $edit, t('Save'));
// Check that we still have the settings for the new vocabulary.
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'nation');
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been kept on the new Country vocabulary.');
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been kept on the new Country vocabulary.');
$this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the new Country vocabulary.');
// Check that we still have the settings for the updated vocabulary.
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'country');
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been kept on the updated Country vocabulary.');
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been kept on the updated Country vocabulary.');
$this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the updated Country vocabulary.');
}
}

View file

@ -40,8 +40,8 @@ class LanguageCustomLanguageConfigurationTest extends WebTestBase {
);
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
// Test validation on missing values.
$this->assertText(t('!name field is required.', array('!name' => t('Language code'))));
$this->assertText(t('!name field is required.', array('!name' => t('Language name'))));
$this->assertText(t('@name field is required.', array('@name' => t('Language code'))));
$this->assertText(t('@name field is required.', array('@name' => t('Language name'))));
$empty_language = new Language();
$this->assertFieldChecked('edit-direction-' . $empty_language->getDirection(), 'Consistent usage of language direction.');
$this->assertUrl(\Drupal::url('language.add', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
@ -55,9 +55,9 @@ class LanguageCustomLanguageConfigurationTest extends WebTestBase {
);
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
$this->assertRaw(t('%field must be a valid language tag as <a href="@url">defined by the W3C</a>.', array(
$this->assertRaw(t('%field must be a valid language tag as <a href=":url">defined by the W3C</a>.', array(
'%field' => t('Language code'),
'@url' => 'http://www.w3.org/International/articles/language-tags/',
':url' => 'http://www.w3.org/International/articles/language-tags/',
)));
$this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name'))));

View file

@ -9,6 +9,7 @@ namespace Drupal\language\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\Core\Language\LanguageInterface;
use Drupal\simpletest\WebTestBase;
@ -24,7 +25,7 @@ class LanguageSwitchingTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('locale', 'language', 'block', 'language_test');
public static $modules = array('locale', 'locale_test', 'language', 'block', 'language_test', 'menu_ui');
protected function setUp() {
parent::setUp();
@ -205,20 +206,20 @@ class LanguageSwitchingTest extends WebTestBase {
/** @var \Drupal\Core\Routing\UrlGenerator $generator */
$generator = $this->container->get('url_generator');
// Verfify the English URL is correct
// Verify the English URL is correct
list($english_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', array(
':id' => 'block-test-language-block',
':hreflang' => 'en',
));
$english_url = $generator->generateFromPath('user/2', array('language' => $languages['en']));
$english_url = $generator->generateFromRoute('entity.user.canonical', array('user' => 2), array('language' => $languages['en']));
$this->assertEqual($english_url, (string) $english_link['href']);
// Verfify the Italian URL is correct
// Verify the Italian URL is correct
list($italian_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', array(
':id' => 'block-test-language-block',
':hreflang' => 'it',
));
$italian_url = $generator->generateFromPath('user/2', array('language' => $languages['it']));
$italian_url = $generator->generateFromRoute('entity.user.canonical', array('user' => 2), array('language' => $languages['it']));
$this->assertEqual($italian_url, (string) $italian_link['href']);
}
@ -292,7 +293,7 @@ class LanguageSwitchingTest extends WebTestBase {
$function_name = '#type link';
$path = 'language_test/type-link-active-class';
// Test links generated by _l() on an English page.
// Test links generated by the link generator on an English page.
$current_language = 'English';
$this->drupalGet($path);
@ -317,7 +318,7 @@ class LanguageSwitchingTest extends WebTestBase {
$this->assertIdentical($settings['path']['isFront'], FALSE, 'drupalSettings.path.isFront is set correctly to allow drupal.active-link to mark the correct links as active.');
$this->assertIdentical($settings['path']['currentLanguage'], 'en', 'drupalSettings.path.currentLanguage is set correctly to allow drupal.active-link to mark the correct links as active.');
// Test links generated by _l() on a French page.
// Test links generated by the link generator on a French page.
$current_language = 'French';
$this->drupalGet('fr/language_test/type-link-active-class');
@ -353,7 +354,7 @@ class LanguageSwitchingTest extends WebTestBase {
$this->drupalLogout();
// Test links generated by _l() on an English page.
// Test links generated by the link generator on an English page.
$current_language = 'English';
$this->drupalGet('language_test/type-link-active-class');
@ -372,7 +373,7 @@ class LanguageSwitchingTest extends WebTestBase {
$links = $this->xpath('//a[@id = :id and not(contains(@class, :class))]', array(':id' => 'fr_link', ':class' => 'is-active'));
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is NOT marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
// Test links generated by _l() on a French page.
// Test links generated by the link generator on a French page.
$current_language = 'French';
$this->drupalGet('fr/language_test/type-link-active-class');
@ -392,6 +393,58 @@ class LanguageSwitchingTest extends WebTestBase {
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
}
/**
* Test language switcher links for session based negotiation.
*/
function testLanguageSessionSwitchLinks() {
// Add language.
$edit = array(
'predefined_langcode' => 'fr',
);
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
// Enable session language detection and selection.
$edit = array(
'language_interface[enabled][language-url]' => FALSE,
'language_interface[enabled][language-session]' => TRUE,
);
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
// Enable the language switching block.
$this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, array(
'id' => 'test_language_block',
));
// Enable the main menu block.
$this->drupalPlaceBlock('system_menu_block:main', array(
'id' => 'test_menu',
));
// Add a link to the homepage.
$link = MenuLinkContent::create([
'title' => 'Home',
'menu_name' => 'main',
'bundle' => 'menu_link_content',
'link' => [['uri' => 'entity:user/2']],
]);
$link->save();
// Go to the homepage.
$this->drupalGet('');
// Click on the French link.
$this->clickLink(t('French'));
// There should be a query parameter to set the session language.
$this->assertUrl('user/2', ['query' => ['language' => 'fr']]);
// Click on the 'Home' Link.
$this->clickLink(t('Home'));
// There should be no query parameter.
$this->assertUrl('user/2');
// Click on the French link.
$this->clickLink(t('French'));
// There should be no query parameter.
$this->assertUrl('user/2');
}
/**
* Saves the native name of a language entity in configuration as a label.
*

View file

@ -393,6 +393,9 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
// it is set by JavaScript.
$this->drupalLogout();
// Place a site branding block in the header region.
$this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
// Access the front page without specifying any valid URL language prefix
// and having as browser language preference a non-default language.
$http_header = array("Accept-Language: $langcode_browser_fallback;q=1");
@ -406,7 +409,7 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
$this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->getName(), 'The browser language is the URL active language');
// Check that URLs are rewritten using the given browser language.
$fields = $this->xpath('//strong[@class="site-name"]/a[@rel="home" and @href=:url]', $args);
$fields = $this->xpath('//div[@class="site-name"]/a[@rel="home" and @href=:url]', $args);
$this->assertTrue($fields[0] == 'Drupal', 'URLs are rewritten using the browser language.');
}