/** * Set up an administrative user account and testing keys. */ public function setUp() { // Call parent::setUp() allowing test cases to pass further modules. parent::setUp(); $this->admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration', 'administer xmlsitemap', 'access content')); $this->drupalLogin($this->admin_user); if (!$this->languageManager->getLanguage('fr')) { // Add a new language. $language = new Language(array('id' => 'fr', 'name' => 'French')); language_save($language); } if (!$this->languageManager->getLanguage('en')) { // Add a new language. $language = new Language(array('id' => 'en', 'name' => 'English')); language_save($language); } // Create the two different language-context sitemaps. $previous_sitemaps = entity_load_multiple('xmlsitemap'); foreach ($previous_sitemaps as $previous_sitemap) { $previous_sitemap->delete(); } $sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array()); $sitemap->context = array('language' => 'en'); xmlsitemap_sitemap_save($sitemap); $sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array()); $sitemap->context = array('language' => 'fr'); xmlsitemap_sitemap_save($sitemap); }
function testDefaultTermLanguage() { // Configure the vocabulary to not hide the language selector, and make the // default language of the terms fixed. $edit = array('default_language[langcode]' => 'bb', 'default_language[language_show]' => TRUE); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); $this->assertOptionSelected('edit-langcode', 'bb', 'The expected langcode was selected.'); // Make the default language of the terms to be the current interface. $edit = array('default_language[langcode]' => 'current_interface', 'default_language[language_show]' => TRUE); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); $this->drupalGet('aa/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); $this->assertOptionSelected('edit-langcode', 'aa', "The expected langcode, 'aa', was selected."); $this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); $this->assertOptionSelected('edit-langcode', 'bb', "The expected langcode, 'bb', was selected."); // Change the default language of the site and check if the default terms // language is still correctly selected. $old_default = \Drupal::languageManager()->getDefaultLanguage(); $old_default->default = FALSE; language_save($old_default); $new_default = \Drupal::languageManager()->getLanguage('cc'); $new_default->default = TRUE; language_save($new_default); $edit = array('default_language[langcode]' => 'site_default', 'default_language[language_show]' => TRUE); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); $this->assertOptionSelected('edit-langcode', 'cc', "The expected langcode, 'cc', was selected."); }
/** * {@inheritdoc} */ function setUp() { parent::setUp(); // Create Page content type. if ($this->profile != 'standard') { $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); } // Add two new languages. $language = new Language(array('id' => 'fr', 'name' => 'French')); language_save($language); $language = new Language(array('id' => 'es', 'name' => 'Spanish')); language_save($language); // Make the body field translatable. The title is already translatable by // definition. $field = FieldStorageConfig::loadByName('node', 'body'); $field->translatable = TRUE; $field->save(); // Set up node titles. They should not include the words "French", // "English", or "Spanish", as there is a language field in the view // that prints out those words. $this->node_titles = array('es' => array('Primero nodo es', 'Segundo nodo es', 'Tercera nodo es'), 'en' => array('First node en', 'Second node en'), 'fr' => array('Premier nœud fr')); // Create nodes with translations. foreach ($this->node_titles['es'] as $index => $title) { $node = $this->drupalCreateNode(array('title' => $title, 'langcode' => 'es', 'type' => 'page', 'promote' => 1)); foreach (array('en', 'fr') as $langcode) { if (isset($this->node_titles[$langcode][$index])) { $translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode][$index])); $translation->body->value = $this->randomMachineName(32); } } $node->save(); } $user = $this->drupalCreateUser(array('access content overview', 'access content')); $this->drupalLogin($user); }
function setUp() { parent::setUp(); // Create and login user. $test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration')); $this->drupalLogin($test_user); // Add a new language. $language = new Language(array('id' => 'es', 'name' => 'Spanish')); language_save($language); // Make the body field translatable. The title is already translatable by // definition. The parent class has already created the article and page // content types. $field_storage = FieldStorageConfig::loadByName('node', 'body'); $field_storage->translatable = TRUE; $field_storage->save(); // Create a few page nodes with multilingual body values. $default_format = filter_default_format(); $nodes = array(array('title' => 'First node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en'), array('title' => 'Second node this is the Spanish title', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'es'), array('title' => 'Third node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en')); $this->searchable_nodes = array(); foreach ($nodes as $setting) { $this->searchable_nodes[] = $this->drupalCreateNode($setting); } // Add English translation to the second node. $translation = $this->searchable_nodes[1]->addTranslation('en', array('title' => 'Second node en')); $translation->body->value = $this->randomMachineName(32); $this->searchable_nodes[1]->save(); // Add Spanish translation to the third node. $translation = $this->searchable_nodes[2]->addTranslation('es', array('title' => 'Third node es')); $translation->body->value = $this->randomMachineName(32); $this->searchable_nodes[2]->save(); // Update the index and then run the shutdown method. $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); $plugin->updateIndex(); search_update_totals(); }
/** * {@inheritdoc} */ function setUp() { parent::setUp(); $this->installSchema('system', array('url_alias', 'router')); $this->installEntitySchema('user'); $this->installEntitySchema('entity_test'); $this->installConfig(array('field', 'language')); // Add English as a language. $english = new Language(array('id' => 'en', 'name' => 'English')); language_save($english); // Add German as a language. $german = new Language(array('id' => 'de', 'name' => 'Deutsch', 'weight' => -1)); language_save($german); // Create the test text field. entity_create('field_storage_config', array('name' => 'field_test_text', 'entity_type' => 'entity_test', 'type' => 'text'))->save(); entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test_text', 'bundle' => 'entity_test', 'translatable' => FALSE))->save(); // Create the test translatable field. entity_create('field_storage_config', array('name' => 'field_test_translatable_text', 'entity_type' => 'entity_test', 'type' => 'text'))->save(); entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test_translatable_text', 'bundle' => 'entity_test', 'translatable' => TRUE))->save(); // Create the test entity reference field. entity_create('field_storage_config', array('name' => 'field_test_entity_reference', 'entity_type' => 'entity_test', 'type' => 'entity_reference', 'settings' => array('target_type' => 'entity_test')))->save(); entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test_entity_reference', 'bundle' => 'entity_test', 'translatable' => TRUE))->save(); $entity_manager = \Drupal::entityManager(); $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend('default')), new RelationLinkManager(new MemoryBackend('default'), $entity_manager)); $chain_resolver = new ChainEntityResolver(array(new UuidResolver($entity_manager), new TargetIdResolver())); // Set up the mock serializer. $normalizers = array(new ContentEntityNormalizer($link_manager, $entity_manager, \Drupal::moduleHandler()), new EntityReferenceItemNormalizer($link_manager, $chain_resolver), new FieldItemNormalizer(), new FieldNormalizer()); $encoders = array(new JsonEncoder()); $this->serializer = new Serializer($normalizers, $encoders); }
/** * Tests search with multilingual nodes. */ public function testMultilingualSearchFilter() { // Create a user with admin for languages, content, and content types, plus // the ability to access content and searches. $user = $this->drupalCreateUser(array('administer nodes', 'administer content types', 'administer languages', 'administer content translation', 'access content', 'search content')); $this->drupalLogin($user); // Add Spanish language programmatically. language_save(new Language(array('id' => 'es'))); // Create a content type and make it translatable. $type = $this->drupalCreateContentType(); $edit = array('language_configuration[language_show]' => TRUE); $this->drupalPostForm('admin/structure/types/manage/' . $type->type, $edit, t('Save content type')); $edit = array('entity_types[node]' => TRUE, 'settings[node][' . $type->type . '][translatable]' => TRUE, 'settings[node][' . $type->type . '][fields][title]' => TRUE, 'settings[node][' . $type->type . '][fields][body]' => TRUE); $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save')); // Add a node in English, with title "sandwich". $values = array('title' => 'sandwich', 'type' => $type->type); $node = $this->drupalCreateNode($values); // "Translate" this node into Spanish, with title "pizza". $node->addTranslation('es', array('title' => 'pizza', 'status' => NODE_PUBLISHED)); $node->save(); // Run cron so that the search index tables are updated. $this->cronRun(); // Test the keyword filter by visiting the page. // The views are in the test view 'test_search', and they just display the // titles of the nodes in the result, as links. // Page with a keyword filter of 'pizza'. This should find the Spanish // translated node, which has 'pizza' in the title, but not the English // one, which does not have the word 'pizza' in it. $this->drupalGet('test-filter'); $this->assertLink('pizza', 0, 'Found translation with matching title'); $this->assertNoLink('sandwich', 'Did not find translation with non-matching title'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $i = 0; foreach (array('af', 'am', 'ar') as $langcode) { $language = new Language(array('id' => $langcode, 'weight' => $i--)); language_save($language); } }
/** * Tests hasTranslation(). */ public function testHasTranslation() { $this->installConfig(array('locale_test')); $locale_config_manager = \Drupal::service('locale.config.typed'); $language = language_save(new Language(array('id' => 'de'))); $result = $locale_config_manager->hasTranslation('locale_test.no_translation', $language); $this->assertFalse($result, 'There is no translation for locale_test.no_translation configuration.'); $result = $locale_config_manager->hasTranslation('locale_test.translation', $language); $this->assertTrue($result, 'There is a translation for locale_test.translation configuration.'); }
/** * Tests hasTranslation(). */ public function testCircularDependency() { // Change the language default object to different values. $new_language_default = new Language(array('id' => 'fr', 'name' => 'French', 'direction' => LANGUAGE::DIRECTION_LTR, 'weight' => 0, 'method_id' => 'language-default', 'default' => TRUE)); language_save($new_language_default); $this->drupalLogin($this->root_user); // Ensure that we can enable early_translation_test on a non-english site. $this->drupalPostForm('admin/modules', array('modules[Testing][early_translation_test][enable]' => TRUE), t('Save configuration')); $this->assertResponse(200); }
protected function setUp() { parent::setUp(); $this->installConfig(array('language')); // Create English and another language beside English. $language = new Language(array('id' => 'en')); language_save($language); $language = new Language(array('id' => 'xx-lolspeak', 'name' => 'Lolspeak')); language_save($language); }
public function setUp() { parent::setUp(); $definitions = \Drupal::service('plugin.manager.config_translation.mapper')->getDefinitions(); $this->pluginId = key($definitions); $this->langcode = 'xx'; $language = new Language(array('id' => $this->langcode, 'name' => 'XX')); language_save($language); \Drupal::state()->set('config_translation_test_alter_form_alter', TRUE); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // Prepare a language object for saving. $languages = language_list(); $langcode = $form_state['values']['langcode']; $language = $languages[$langcode]; $language->name = $form_state['values']['name']; $language->direction = $form_state['values']['direction']; language_save($language); $form_state->setRedirect('language.admin_overview'); }
protected function setUp() { parent::setUp(); $this->installConfig(array('language')); // Setup English. language_save(\Drupal::languageManager()->getDefaultLanguage()); // Setup Italian. $language = new Language(array('id' => 'it', 'name' => 'Italian', 'direction' => Language::DIRECTION_LTR)); language_save($language); $this->manager = $this->container->get('plugin.manager.condition'); }
public function setUp() { parent::setUp(); // Create test languages. $this->langcodes = array(language_load('en')); for ($i = 1; $i < 3; ++$i) { $language = new Language(array('id' => 'l' . $i, 'name' => $this->randomString())); language_save($language); $this->langcodes[$i] = $language; } }
/** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { // Prepare a language object for saving. $languages = language_list(); $langcode = $form_state['values']['langcode']; $language = $languages[$langcode]; $language->name = $form_state['values']['name']; $language->direction = $form_state['values']['direction']; language_save($language); $form_state['redirect_route']['route_name'] = 'language.admin_overview'; }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); // Add a default locale storage for all these tests. $this->storage = $this->container->get('locale.storage'); // Create two languages: Spanish and German. foreach (array('es', 'de') as $langcode) { $language = new Language(array('id' => $langcode)); $languages[$langcode] = language_save($language); } }
public function setUp() { parent::setUp(); $admin_permissions = array('administer themes', 'administer languages', 'administer site configuration', 'translate configuration'); // Create and login user. $this->admin_user = $this->drupalCreateUser($admin_permissions); // Add languages. foreach ($this->langcodes as $langcode) { $language = new Language(array('id' => $langcode)); language_save($language); } }
/** * Tests the language extra field display. */ public function testViewLanguage() { // Add Spanish language. $language = new Language(array('id' => 'es')); language_save($language); // Set language field visible. entity_get_display('node', 'page', 'full')->setComponent('langcode')->save(); // Create a node in Spanish. $node = $this->drupalCreateNode(array('langcode' => 'es')); $this->drupalGet($node->getSystemPath()); $this->assertText('Spanish', 'The language field is displayed properly.'); }
function setUp() { parent::setUp(); // Create an administrative user. $this->admin_user = $this->drupalCreateUser(array('administer taxonomy')); $this->drupalLogin($this->admin_user); // Add some custom languages. $language = new Language(array('id' => 'aa', 'name' => $this->randomMachineName())); language_save($language); $language = new Language(array('id' => 'bb', 'name' => $this->randomMachineName())); language_save($language); }
function setUp() { parent::setUp(); // Enable translations for the test entity type. \Drupal::state()->set('entity_test.translation', TRUE); // Create test languages. $this->langcodes = array(); for ($i = 0; $i < 2; ++$i) { $language = new Language(array('id' => 'l' . $i, 'name' => $this->randomString())); $this->langcodes[$i] = $language->id; language_save($language); } }
public function setUp() { parent::setUp(); $permissions = array('translate configuration', 'administer languages', 'administer site configuration', 'administer contact forms', 'access site-wide contact form', 'access contextual links', 'administer views'); // Create and login user. $this->drupalLogin($this->drupalCreateUser($permissions)); // Add languages. foreach ($this->langcodes as $langcode) { $language = new Language(array('id' => $langcode)); language_save($language); } $this->localeStorage = $this->container->get('locale.storage'); }
/** * Tests changing label, description and tag. * * @see views_ui_edit_details_form */ public function testDetails() { $view_name = 'test_view'; $language = new Language(array('name' => 'French', 'id' => 'fr')); language_save($language); $edit = array('label' => $this->randomName(), 'tag' => $this->randomName(), 'description' => $this->randomName(30), 'langcode' => 'fr'); $this->drupalPostForm("admin/structure/views/nojs/edit-details/{$view_name}/default", $edit, t('Apply')); $this->drupalPostForm(NULL, array(), t('Save')); $view = Views::getView($view_name); foreach (array('label', 'tag', 'description', 'langcode') as $property) { $this->assertEqual($view->storage->get($property), $edit[$property], format_string('Make sure the property @property got probably saved.', array('@property' => $property))); } }
/** * Tests the configuration events are not fired during install of overrides. */ public function testLanguageConfigOverrideInstall() { language_save(new Language(array('id' => 'de'))); // 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'); }
function setUp() { parent::setUp('language'); \Drupal::config('system.date')->set('timezone.user.configurable', 1)->save(); $formats = $this->container->get('entity.manager')->getStorage('date_format')->loadMultiple(array('long', 'medium', 'short')); $formats['long']->setPattern('l, j. F Y - G:i')->save(); $formats['medium']->setPattern('j. F Y - G:i')->save(); $formats['short']->setPattern('Y M j - g:ia')->save(); $this->refreshVariables(); $this->settingsSet('locale_custom_strings_' . self::LANGCODE, array('' => array('Sunday' => 'domingo'), 'Long month name' => array('March' => 'marzo'))); $language = new Language(array('id' => static::LANGCODE)); language_save($language); $this->resetAll(); }
/** * Ensures entity access for entity translations is properly working. */ function testEntityTranslationAccess() { // Set up a non-admin user that is allowed to view test entity translations. \Drupal::currentUser()->setAccount($this->createUser(array('uid' => 2), array('view test entity translations'))); // Create two test languages. foreach (array('foo', 'bar') as $langcode) { $language = new Language(array('id' => $langcode, 'name' => $this->randomString())); language_save($language); } $entity = entity_create('entity_test', array('name' => 'test', 'langcode' => 'foo')); $entity->save(); $translation = $entity->getTranslation('bar'); $this->assertEntityAccess(array('view' => TRUE), $translation); }
public function setUp() { parent::setUp(); // Create the 'private' field, which allows the node to be marked as private // (restricted access) in a given translation. $field_storage = entity_create('field_storage_config', array('name' => 'field_private', 'entity_type' => 'node', 'type' => 'boolean', 'cardinality' => 1, 'translatable' => TRUE, 'settings' => array('on_label' => 'Private', 'off_label' => 'Not private'))); $field_storage->save(); entity_create('field_instance_config', array('field_storage' => $field_storage, 'bundle' => 'page', 'widget' => array('type' => 'options_buttons')))->save(); // After enabling a node access module, the access table has to be rebuild. node_access_rebuild(); // Create a normal authenticated user. $this->web_user = $this->drupalCreateUser(array('access content')); // Load the user 1 user for later use as an admin user with permission to // see everything. $this->admin_user = user_load(1); // Add Hungarian and Catalan. $language = new Language(array('id' => 'hu')); language_save($language); $language = new Language(array('id' => 'ca')); language_save($language); // The node_access_test_language module allows individual translations of a // node to be marked private (not viewable by normal users). // Create six nodes: // 1. Four Hungarian nodes with Catalan translations // - One with neither language marked as private. // - One with only the Hungarian translation private. // - One with only the Catalan translation private. // - One with both the Hungarian and Catalan translations private. // 2. Two nodes with no language specified. // - One public. // - One private. $this->nodes['both_public'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 0)))); $translation = $node->getTranslation('ca'); $translation->field_private[0]->value = 0; $node->save(); $this->nodes['ca_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 0)))); $translation = $node->getTranslation('ca'); $translation->field_private[0]->value = 1; $node->save(); $this->nodes['hu_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 1)))); $translation = $node->getTranslation('ca'); $translation->field_private[0]->value = 0; $node->save(); $this->nodes['both_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 1)))); $translation = $node->getTranslation('ca'); $translation->field_private[0]->value = 1; $node->save(); $this->nodes['no_language_public'] = $this->drupalCreateNode(array('field_private' => array(array('value' => 0)))); $this->nodes['no_language_private'] = $this->drupalCreateNode(array('field_private' => array(array('value' => 1)))); }
/** * Functional test for language handling during user creation. */ function testLocalUserCreation() { // User to add and remove language and create new users. $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer users')); $this->drupalLogin($admin_user); // Add predefined language. $langcode = 'fr'; $language = new Language(array('id' => $langcode)); language_save($language); // Set language negotiation. $edit = array('language_interface[enabled][language-url]' => TRUE); $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); $this->assertText(t('Language negotiation configuration saved.'), 'Set language negotiation.'); // Check if the language selector is available on admin/people/create and // set to the currently active language. $this->drupalGet($langcode . '/admin/people/create'); $this->assertOptionSelected("edit-preferred-langcode", $langcode, 'Global language set in the language selector.'); // Create a user with the admin/people/create form and check if the correct // language is set. $username = $this->randomName(10); $edit = array('name' => $username, 'mail' => $this->randomName(4) . '@example.com', 'pass[pass1]' => $username, 'pass[pass2]' => $username); $this->drupalPostForm($langcode . '/admin/people/create', $edit, t('Create new account')); $user = user_load_by_name($username); $this->assertEqual($user->getPreferredLangcode(), $langcode, 'New user has correct preferred language set.'); $this->assertEqual($user->language()->id, $langcode, 'New user has correct profile language set.'); // Register a new user and check if the language selector is hidden. $this->drupalLogout(); $this->drupalGet($langcode . '/user/register'); $this->assertNoFieldByName('language[fr]', 'Language selector is not accessible.'); $username = $this->randomName(10); $edit = array('name' => $username, 'mail' => $this->randomName(4) . '@example.com'); $this->drupalPostForm($langcode . '/user/register', $edit, t('Create new account')); $user = user_load_by_name($username); $this->assertEqual($user->getPreferredLangcode(), $langcode, 'New user has correct preferred language set.'); $this->assertEqual($user->language()->id, $langcode, 'New user has correct profile language set.'); // Test if the admin can use the language selector and if the // correct language is was saved. $user_edit = $langcode . '/user/' . $user->id() . '/edit'; $this->drupalLogin($admin_user); $this->drupalGet($user_edit); $this->assertOptionSelected("edit-preferred-langcode", $langcode, 'Language selector is accessible and correct language is selected.'); // Set pass_raw so we can login the new user. $user->pass_raw = $this->randomName(10); $edit = array('pass[pass1]' => $user->pass_raw, 'pass[pass2]' => $user->pass_raw); $this->drupalPostForm($user_edit, $edit, t('Save')); $this->drupalLogin($user); $this->drupalGet($user_edit); $this->assertOptionSelected("edit-preferred-langcode", $langcode, 'Language selector is accessible and correct language is selected.'); }
function setUp() { parent::setUp(); node_access_test_add_field(entity_load('node_type', 'page')); // After enabling a node access module, the access table has to be rebuild. node_access_rebuild(); // Enable the private node feature of the node_access_test module. \Drupal::state()->set('node_access_test.private', TRUE); // Add Hungarian and Catalan. $language = new Language(array('id' => 'hu')); language_save($language); $language = new Language(array('id' => 'ca')); language_save($language); $language = new Language(array('id' => 'hr')); language_save($language); }
function setUp() { parent::setUp(); $this->field_name = drupal_strtolower($this->randomName() . '_field_name'); $field = array('name' => $this->field_name, 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 4, 'translatable' => TRUE); entity_create('field_storage_config', $field)->save(); $this->fieldStorage = entity_load('field_storage_config', $this->entity_type . '.' . $this->field_name); $instance = array('field_storage' => $this->fieldStorage, 'bundle' => $this->entity_type); entity_create('field_instance_config', $instance)->save(); $this->instance = entity_load('field_instance_config', $this->entity_type . '.' . $instance['bundle'] . '.' . $this->field_name); entity_get_form_display($this->entity_type, $this->entity_type, 'default')->setComponent($this->field_name)->save(); for ($i = 0; $i < 3; ++$i) { $language = new Language(array('id' => 'l' . $i, 'name' => $this->randomString())); language_save($language); } }
/** * Tests that the language_get_default_langcode() returns the correct values. */ public function testDefaultLangcode() { // Add some custom languages. foreach (array('aa', 'bb', 'cc') as $language_code) { $language = new Language(array('id' => $language_code, 'name' => $this->randomName())); language_save($language); } // Fixed language. language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'bb', 'language_show' => TRUE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); $this->assertEqual($langcode, 'bb'); // Current interface. language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'current_interface', 'language_show' => TRUE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); $language_interface = \Drupal::languageManager()->getCurrentLanguage(); $this->assertEqual($langcode, $language_interface->id); // Site's default. $old_default = \Drupal::languageManager()->getDefaultLanguage(); // Ensure the language entity default value is correct. $language_entity = entity_load('language_entity', $old_default->getId()); $this->assertTrue($language_entity->get('default'), 'The en language entity is flagged as the default language.'); $old_default->default = FALSE; language_save($old_default); $new_default = \Drupal::languageManager()->getLanguage('cc'); $new_default->default = TRUE; language_save($new_default); language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'site_default', 'language_show' => TRUE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); $this->assertEqual($langcode, 'cc'); // Ensure the language entity default value is correct. $language_entity = entity_load('language_entity', $old_default->getId()); $this->assertFalse($language_entity->get('default'), 'The en language entity is not flagged as the default language.'); $language_entity = entity_load('language_entity', 'cc'); // Check calling the Drupal\language\Entity\Language::isDefault() method // directly. $this->assertTrue($language_entity->isDefault(), 'The cc language entity is flagged as the default language.'); // Check the default value of a language field when authors preferred option // is selected. // Create first an user and assign a preferred langcode to him. $some_user = $this->drupalCreateUser(); $some_user->preferred_langcode = 'bb'; $some_user->save(); $this->drupalLogin($some_user); language_save_default_configuration('custom_type', 'some_bundle', array('langcode' => 'authors_default', 'language_show' => TRUE)); $this->drupalGet('language-tests/language_configuration_element_test'); $this->assertOptionSelected('edit-langcode', 'bb'); }