/**
  * Tests changing the published status on a node without fields.
  */
 public function testPublishedStatusNoFields()
 {
     // Test changing the published status of an article without fields.
     $this->drupalLogin($this->administrator);
     // Delete all fields.
     $this->drupalGet('admin/structure/types/manage/article/fields');
     $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete', array(), t('Delete'));
     $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_tags/delete', array(), t('Delete'));
     $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image/delete', array(), t('Delete'));
     // Add a node.
     $default_langcode = $this->langcodes[0];
     $values[$default_langcode] = array('title' => array(array('value' => $this->randomMachineName())));
     $entity_id = $this->createEntity($values[$default_langcode], $default_langcode);
     $entity = entity_load($this->entityTypeId, $entity_id, TRUE);
     // Add a content translation.
     $langcode = 'fr';
     $language = ConfigurableLanguage::load($langcode);
     $values[$langcode] = array('title' => array(array('value' => $this->randomMachineName())));
     $entity_type_id = $entity->getEntityTypeId();
     $add_url = Url::fromRoute("entity.{$entity_type_id}.content_translation_add", [$entity->getEntityTypeId() => $entity->id(), 'source' => $default_langcode, 'target' => $langcode], array('language' => $language));
     $this->drupalPostForm($add_url, $this->getEditValues($values, $langcode), t('Save and unpublish (this translation)'));
     $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
     $translation = $entity->getTranslation($langcode);
     // Make sure we unpublished the node correctly.
     $this->assertFalse($this->manager->getTranslationMetadata($translation)->isPublished(), 'The translation has been correctly unpublished.');
 }
 /**
  * Tests translating the site name.
  */
 function testSiteNameTranslation()
 {
     $adminUser = $this->drupalCreateUser(array('administer site configuration', 'administer languages'));
     $this->drupalLogin($adminUser);
     // Add a custom language.
     $langcode = 'xx';
     $name = $this->randomMachineName(16);
     $edit = array('predefined_langcode' => 'custom', 'langcode' => $langcode, 'label' => $name, 'direction' => LanguageInterface::DIRECTION_LTR);
     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
     \Drupal::languageManager()->getLanguageConfigOverride($langcode, 'system.site')->set('name', 'XX site name')->save();
     $this->drupalLogout();
     // The home page in English should not have the override.
     $this->drupalGet('');
     $this->assertNoText('XX site name');
     // During path resolution the system.site configuration object is used to
     // determine the front page. This occurs before language negotiation causing
     // the configuration factory to cache an object without the correct
     // overrides. We are testing that the configuration factory is
     // re-initialised after language negotiation. Ensure that it applies when
     // we access the XX front page.
     // @see \Drupal\Core\PathProcessor::processInbound()
     $this->drupalGet('xx');
     $this->assertText('XX site name');
     // Set the xx language to be the default language and delete the English
     // language so the site is no longer multilingual and confirm configuration
     // overrides still work.
     $language_manager = \Drupal::languageManager()->reset();
     $this->assertTrue($language_manager->isMultilingual(), 'The test site is multilingual.');
     $this->config('system.site')->set('default_langcode', 'xx')->save();
     ConfigurableLanguage::load('en')->delete();
     $this->assertFalse($language_manager->isMultilingual(), 'The test site is monolingual.');
     $this->drupalGet('xx');
     $this->assertText('XX site name');
 }
 /**
  * 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);
     }
 }
Ejemplo n.º 4
0
 /**
  * Asserts various properties of a configurable language entity.
  *
  * @param string $id
  *   The language ID.
  * @param string $label
  *   The language name.
  * @param string $direction
  *   (optional) The language's direction (one of the DIRECTION_* constants in
  *   ConfigurableLanguageInterface). Defaults to LTR.
  * @param int $weight
  *   (optional) The weight of the language. Defaults to 0.
  */
 protected function assertLanguage($id, $label, $direction = ConfigurableLanguageInterface::DIRECTION_LTR, $weight = 0)
 {
     /** @var \Drupal\language\ConfigurableLanguageInterface $language */
     $language = ConfigurableLanguage::load($id);
     $this->assertTrue($language instanceof ConfigurableLanguageInterface);
     $this->assertIdentical($label, $language->label());
     $this->assertIdentical($direction, $language->getDirection());
     $this->assertIdentical(0, $language->getWeight());
     $this->assertFalse($language->isLocked());
 }
Ejemplo n.º 5
0
 protected function setUp()
 {
     parent::setUp();
     // Create test languages.
     $this->langcodes = array(ConfigurableLanguage::load('en'));
     for ($i = 1; $i < 3; ++$i) {
         $language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()));
         $language->save();
         $this->langcodes[$i] = $language;
     }
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $destination = $row->getDestination();
     $langcode = $destination['default_langcode'];
     // Check if the language exists.
     if (ConfigurableLanguage::load($langcode) === NULL) {
         throw new MigrateException("The language '{$langcode}' does not exist on this site.");
     }
     $this->config->set('default_langcode', $destination['default_langcode']);
     $this->config->save();
     return [$this->config->getName()];
 }
 /**
  * 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());
 }
 /**
  * Tests translation deletion.
  */
 protected function doTestTranslationDeletion()
 {
     // Confirm and delete a translation.
     $this->drupalLogin($this->translator);
     $langcode = 'fr';
     $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
     $language = ConfigurableLanguage::load($langcode);
     $url = $entity->urlInfo('edit-form', array('language' => $language));
     $this->drupalPostForm($url, array(), t('Delete translation'));
     $this->drupalPostForm(NULL, array(), t('Delete @language translation', array('@language' => $language->getName())));
     $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
     if ($this->assertTrue(is_object($entity), 'Entity found')) {
         $translations = $entity->getTranslationLanguages();
         $this->assertTrue(count($translations) == 2 && empty($translations[$langcode]), 'Translation successfully deleted.');
     }
     // Check that the translator cannot delete the original translation.
     $args = [$this->entityTypeId => $entity->id(), 'language' => 'en'];
     $this->drupalGet(Url::fromRoute('content_translation.translation_delete_' . $this->entityTypeId, $args));
     $this->assertResponse(403);
 }
 /**
  * Functional tests for adding, editing and deleting languages.
  */
 function testLanguageConfiguration()
 {
     // Ensure the after installing the language module the weight of the English
     // language is still 0.
     $this->assertEqual(ConfigurableLanguage::load('en')->getWeight(), 0, 'The English language has a weight of 0.');
     // User to add and remove language.
     $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
     $this->drupalLogin($admin_user);
     // Check if the Default English language has no path prefix.
     $this->drupalGet('admin/config/regional/language/detection/url');
     $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.');
     // Check that Add language is a primary button.
     $this->drupalGet('admin/config/regional/language/add');
     $this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Add language', 'Add language is a primary button');
     // Add predefined language.
     $edit = array('predefined_langcode' => 'fr');
     $this->drupalPostForm(NULL, $edit, 'Add language');
     $this->assertText('French');
     $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
     // Langcode for Languages is always 'en'.
     $language = $this->config('language.entity.fr')->get();
     $this->assertEqual($language['langcode'], 'en');
     // Check if the Default English language has no path prefix.
     $this->drupalGet('admin/config/regional/language/detection/url');
     $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.');
     // Check if French has a path prefix.
     $this->drupalGet('admin/config/regional/language/detection/url');
     $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French has a path prefix.');
     // Check if we can change the default language.
     $this->drupalGet('admin/config/regional/language');
     $this->assertFieldChecked('edit-site-default-language-en', 'English is the default language.');
     // Change the default language.
     $edit = array('site_default_language' => 'fr');
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->rebuildContainer();
     $this->assertFieldChecked('edit-site-default-language-fr', 'Default language updated.');
     $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'langcode' => 'fr']), [], 'Correct page redirection.');
     // Check if a valid language prefix is added after changing the default
     // language.
     $this->drupalGet('admin/config/regional/language/detection/url');
     $this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', 'A valid path prefix has been added to the previous default language.');
     // Check if French still has a path prefix.
     $this->drupalGet('admin/config/regional/language/detection/url');
     $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French still has a path prefix.');
     // Check that prefix can be changed.
     $edit = array('prefix[fr]' => 'french');
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'french', 'French path prefix has changed.');
     // Check that the prefix can be removed.
     $edit = array('prefix[fr]' => '');
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->assertNoText(t('The prefix may only be left blank for the selected detection fallback language.'), 'The path prefix can be removed for the default language');
     // Change default negotiation language.
     $this->config('language.negotiation')->set('selected_langcode', 'fr')->save();
     // Check that the prefix of a language that is not the negotiation one
     // cannot be changed to empty string.
     $edit = array('prefix[en]' => '');
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->assertText(t('The prefix may only be left blank for the selected detection fallback language.'));
     //  Check that prefix cannot be changed to contain a slash.
     $edit = array('prefix[en]' => 'foo/bar');
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->assertText(t('The prefix may not contain a slash.'), 'English prefix cannot be changed to contain a slash.');
     // Remove English language and add a new Language to check if langcode of
     // Language entity is 'en'.
     $this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete'));
     $this->rebuildContainer();
     $this->assertRaw(t('The %language (%langcode) language has been removed.', array('%language' => 'English', '%langcode' => 'en')));
     // Ensure that French language has a weight of 1 after being created through
     // the UI.
     $french = ConfigurableLanguage::load('fr');
     $this->assertEqual($french->getWeight(), 1, 'The French language has a weight of 1.');
     // Ensure that French language can now have a weight of 0.
     $french->setWeight(0)->save();
     $this->assertEqual($french->getWeight(), 0, 'The French language has a weight of 0.');
     // Ensure that new languages created through the API get a weight of 0.
     $afrikaans = ConfigurableLanguage::createFromLangcode('af');
     $afrikaans->save();
     $this->assertEqual($afrikaans->getWeight(), 0, 'The Afrikaans language has a weight of 0.');
     // Ensure that a new language can be created with any weight.
     $arabic = ConfigurableLanguage::createFromLangcode('ar');
     $arabic->setWeight(4)->save();
     $this->assertEqual($arabic->getWeight(), 4, 'The Arabic language has a weight of 0.');
     $edit = array('predefined_langcode' => 'de');
     $this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language');
     $language = $this->config('language.entity.de')->get();
     $this->assertEqual($language['langcode'], 'fr');
     // Ensure that German language has a weight of 5 after being created through
     // the UI.
     $french = ConfigurableLanguage::load('de');
     $this->assertEqual($french->getWeight(), 5, 'The German language has a weight of 5.');
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 protected function doTestPublishedStatus()
 {
     $entity_manager = \Drupal::entityManager();
     $storage = $entity_manager->getStorage($this->entityTypeId);
     $storage->resetCache();
     $entity = $storage->load($this->entityId);
     // Unpublish translations.
     foreach ($this->langcodes as $index => $langcode) {
         if ($index > 0) {
             $edit = array('status' => 0);
             $url = $entity->urlInfo('edit-form', array('language' => ConfigurableLanguage::load($langcode)));
             $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode));
             $storage->resetCache();
             $entity = $storage->load($this->entityId);
             $this->assertFalse($this->manager->getTranslationMetadata($entity->getTranslation($langcode))->isPublished(), 'The translation has been correctly unpublished.');
         }
     }
 }
 /**
  * Tests if the translated entity is displayed in an entity reference field.
  */
 public function testTranslatedEntityReferenceDisplay()
 {
     $url = $this->referrerEntity->urlInfo();
     $translation_url = $this->referrerEntity->urlInfo('canonical', ['language' => ConfigurableLanguage::load($this->translateToLangcode)]);
     $this->drupalGet($url);
     $this->assertText($this->labelOfNotTranslatedReference, 'The label of not translated reference is displayed.');
     $this->assertText($this->originalLabel, 'The default label of translated reference is displayed.');
     $this->assertNoText($this->translatedLabel, 'The translated label of translated reference is not displayed.');
     $this->drupalGet($translation_url);
     $this->assertText($this->labelOfNotTranslatedReference, 'The label of not translated reference is displayed.');
     $this->assertNoText($this->originalLabel, 'The default label of translated reference is not displayed.');
     $this->assertText($this->translatedLabel, 'The translated label of translated reference is displayed.');
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function updateLockedLanguageWeights()
 {
     // Get the weight of the last configurable language.
     $configurable_languages = $this->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
     $max_weight = end($configurable_languages)->getWeight();
     $locked_languages = $this->getLanguages(LanguageInterface::STATE_LOCKED);
     // Update locked language weights to maintain the existing order, if
     // necessary.
     if (reset($locked_languages)->getWeight() <= $max_weight) {
         foreach ($locked_languages as $language) {
             // Update system languages weight.
             $max_weight++;
             ConfigurableLanguage::load($language->getId())->setWeight($max_weight)->save();
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * Executes the language fallback test for the given entity type.
  *
  * @param string $entity_type
  *   The entity type to run the tests with.
  */
 protected function doTestLanguageFallback($entity_type)
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     $current_langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
     $this->langcodes[] = $current_langcode;
     $values = array();
     foreach ($this->langcodes as $langcode) {
         $values[$langcode]['name'] = $this->randomMachineName();
         $values[$langcode]['user_id'] = mt_rand(0, 127);
     }
     $default_langcode = $this->langcodes[0];
     $langcode = $this->langcodes[1];
     $langcode2 = $this->langcodes[2];
     $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
     $languages = $this->languageManager->getLanguages();
     $language = ConfigurableLanguage::load($languages[$langcode]->getId());
     $language->set('weight', 1);
     $language->save();
     $this->languageManager->reset();
     $controller = $this->entityManager->getStorage($entity_type);
     $entity = $controller->create(array($langcode_key => $default_langcode) + $values[$default_langcode]);
     $entity->save();
     $entity->addTranslation($langcode, $values[$langcode]);
     $entity->save();
     // Check that retrieving the current translation works as expected.
     $entity = $this->reloadEntity($entity);
     $translation = $this->entityManager->getTranslationFromContext($entity, $langcode2);
     $this->assertEqual($translation->language()->getId(), $default_langcode, 'The current translation language matches the expected one.');
     // Check that language fallback respects language weight by default.
     $language = ConfigurableLanguage::load($languages[$langcode]->getId());
     $language->set('weight', -1);
     $language->save();
     $translation = $this->entityManager->getTranslationFromContext($entity, $langcode2);
     $this->assertEqual($translation->language()->getId(), $langcode, 'The current translation language matches the expected one.');
     // Check that the current translation is properly returned.
     $translation = $this->entityManager->getTranslationFromContext($entity);
     $this->assertEqual($langcode, $translation->language()->getId(), 'The current translation language matches the topmost language fallback candidate.');
     $entity->addTranslation($current_langcode, $values[$current_langcode]);
     $translation = $this->entityManager->getTranslationFromContext($entity);
     $this->assertEqual($current_langcode, $translation->language()->getId(), 'The current translation language matches the current language.');
     // Check that if the entity has no translation no fallback is applied.
     $entity2 = $controller->create(array($langcode_key => $default_langcode));
     // Get an view builder.
     $controller = $this->entityManager->getViewBuilder($entity_type);
     $entity2_build = $controller->view($entity2);
     $entity2_output = (string) $renderer->renderRoot($entity2_build);
     $translation = $this->entityManager->getTranslationFromContext($entity2, $default_langcode);
     $translation_build = $controller->view($translation);
     $translation_output = (string) $renderer->renderRoot($translation_build);
     $this->assertIdentical($entity2_output, $translation_output, 'When the entity has no translation no fallback is applied.');
     // Checks that entity translations are rendered properly.
     $controller = $this->entityManager->getViewBuilder($entity_type);
     $build = $controller->view($entity);
     $renderer->renderRoot($build);
     $this->assertEqual($build['label']['#markup'], $values[$current_langcode]['name'], 'By default the entity is rendered in the current language.');
     $langcodes = array_combine($this->langcodes, $this->langcodes);
     // We have no translation for the $langcode2 language, hence the expected
     // result is the topmost existing translation, that is $langcode.
     $langcodes[$langcode2] = $langcode;
     foreach ($langcodes as $desired => $expected) {
         $build = $controller->view($entity, 'full', $desired);
         // Unset the #cache key so that a fresh render is produced with each pass,
         // making the renderable array keys available to compare.
         unset($build['#cache']);
         $renderer->renderRoot($build);
         $this->assertEqual($build['label']['#markup'], $values[$expected]['name'], 'The entity is rendered in the expected language.');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getNativeLanguages()
 {
     $languages = $this->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
     $natives = array();
     $original_language = $this->getConfigOverrideLanguage();
     foreach ($languages as $langcode => $language) {
         $this->setConfigOverrideLanguage($language);
         $natives[$langcode] = ConfigurableLanguage::load($langcode);
     }
     $this->setConfigOverrideLanguage($original_language);
     Language::sort($natives);
     return $natives;
 }
Ejemplo n.º 15
0
 /**
  * Testing correct loading and saving of menu links via node form widget in a multilingual environment.
  */
 function testMultilingualMenuNodeFormWidget()
 {
     // Setup languages.
     $langcodes = array('de');
     foreach ($langcodes as $langcode) {
         ConfigurableLanguage::createFromLangcode($langcode)->save();
     }
     array_unshift($langcodes, \Drupal::languageManager()->getDefaultLanguage()->getId());
     $config = \Drupal::service('config.factory')->getEditable('language.negotiation');
     // Ensure path prefix is used to determine the language.
     $config->set('url.source', 'path_prefix');
     // Ensure that there's a path prefix set for english as well.
     $config->set('url.prefixes.' . $langcodes[0], $langcodes[0]);
     $config->save();
     $this->rebuildContainer();
     $languages = array();
     foreach ($langcodes as $langcode) {
         $languages[$langcode] = ConfigurableLanguage::load($langcode);
     }
     // Use a UI form submission to make the node type and menu link content entity translatable.
     $this->drupalLogout();
     $this->drupalLogin($this->rootUser);
     $edit = array('entity_types[node]' => TRUE, 'entity_types[menu_link_content]' => TRUE, 'settings[node][page][settings][language][language_alterable]' => TRUE, 'settings[node][page][translatable]' => TRUE, 'settings[node][page][fields][title]' => TRUE, 'settings[menu_link_content][menu_link_content][translatable]' => TRUE);
     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
     // Log out and back in as normal user.
     $this->drupalLogout();
     $this->drupalLogin($this->editor);
     // Create a node.
     $node_title = $this->randomMachineName(8);
     $node = Node::create(['type' => 'page', 'title' => $node_title, 'body' => $this->randomMachineName(16), 'uid' => $this->editor->id(), 'status' => 1, 'langcode' => $langcodes[0]]);
     $node->save();
     // Create translation.
     $translated_node_title = $this->randomMachineName(8);
     $node->addTranslation($langcodes[1], ['title' => $translated_node_title, 'body' => $this->randomMachineName(16), 'status' => 1]);
     $node->save();
     // Edit the node and create a menu link.
     $edit = array('menu[enabled]' => 1, 'menu[title]' => $node_title, 'menu[weight]' => 17);
     $options = array('language' => $languages[$langcodes[0]]);
     $url = $node->toUrl('edit-form', $options);
     $this->drupalPostForm($url, $edit, t('Save') . ' ' . t('(this translation)'));
     // Edit the node in a different language and translate the menu link.
     $edit = array('menu[enabled]' => 1, 'menu[title]' => $translated_node_title, 'menu[weight]' => 17);
     $options = array('language' => $languages[$langcodes[1]]);
     $url = $node->toUrl('edit-form', $options);
     $this->drupalPostForm($url, $edit, t('Save') . ' ' . t('(this translation)'));
     // Assert that the original link exists in the frontend.
     $this->drupalGet('node/' . $node->id(), array('language' => $languages[$langcodes[0]]));
     $this->assertLink($node_title);
     // Assert that the translated link exists in the frontend.
     $this->drupalGet('node/' . $node->id(), array('language' => $languages[$langcodes[1]]));
     $this->assertLink($translated_node_title);
     // Revisit the edit page in original language, check the loaded menu item title and save.
     $options = array('language' => $languages[$langcodes[0]]);
     $url = $node->toUrl('edit-form', $options);
     $this->drupalGet($url);
     $this->assertFieldById('edit-menu-title', $node_title);
     $this->drupalPostForm(NULL, [], t('Save') . ' ' . t('(this translation)'));
     // Revisit the edit page of the translation and check the loaded menu item title.
     $options = array('language' => $languages[$langcodes[1]]);
     $url = $node->toUrl('edit-form', $options);
     $this->drupalGet($url);
     $this->assertFieldById('edit-menu-title', $translated_node_title);
 }
Ejemplo n.º 16
0
<?php

// Load 'adminisztator' user role.
$role = \Drupal\user\Entity\Role::load('adminisztrator');
$permissions = ['administer advanced forum', 'administer advanced forum', 'administer blocks', 'use PHP for settings', 'administer CAPTCHA settings', 'administer comments', 'administer contact forms', 'administer filters', 'administer forums', 'delete any forum content', 'delete own forum content', 'edit any forum content', 'edit own forum content', 'create images', 'delete any images', 'delete own images', 'edit any images', 'edit own images', 'view original images', 'attach images', 'administer languages', 'translate interface', 'administer login destination', 'administer mass contact', 'choose whether to archive mass contact messages', 'send mass contact attachments', 'send mass contact e-mails', 'send to users in the Wesnoth felhasználók category', 'administer menu', 'access content', 'administer content types', 'administer nodes', 'access content overview', 'create mass_contact content', 'create page content', 'delete any mass_contact content', 'delete any page content', 'delete any profile content', 'delete any story content', 'delete own mass_contact content', 'delete own page content', 'delete own profile content', 'delete own story content', 'delete revisions', 'edit any mass_contact content', 'edit any page content', 'edit any profile content', 'edit any story content', 'edit own mass_contact content', 'edit own page content', 'revert revisions', 'view revisions', 'administer url aliases', 'create url aliases', 'administer pathauto', 'notify of path changes', 'cancel own vote', 'create poll content', 'delete any poll content', 'delete own poll content', 'edit any poll content', 'edit own poll content', 'inspect all votes', 'administer privatemsg settings', 'read all private messages', 'administer search', 'administer smileys', 'access administration pages', 'access site reports', 'administer actions', 'administer files', 'administer site configuration', 'select different theme', 'administer taxonomy', 'administer taxonomy images', 'can disable taxonomy images', 'administer permissions', 'administer users', 'change own username', 'access all views', 'administer views', 'administer voting api', 'access mwb', 'access wesnoth admin', 'access wesnoth replays', 'administer mwb', 'administer wesnoth replays', 'edit any wesnoth replays', 'edit jelentkezesek', 'edit own wesnoth replays', 'use text format alakhu', 'administer comment types', 'administer display modes', 'administer comment display', 'administer comment fields', 'administer comment form display', 'administer node display', 'administer node fields', 'administer node form display', 'administer block_content display', 'administer block_content fields', 'administer block_content form display', 'administer poll display', 'administer poll fields', 'administer poll form display', 'administer taxonomy_term display', 'administer taxonomy_term fields', 'administer taxonomy_term form display', 'administer user display', 'administer user fields', 'administer user form display', 'administer polls', 'access polls', 'administer modules', 'administer software updates', 'administer themes', 'link to any page', 'access site in maintenance mode', 'view the administration theme', 'administer account settings'];
foreach ($permissions as $p) {
    $role->grantPermission($p);
}
$role->setIsAdmin(true);
$role->save();
// Set 'hu' as the default language
$langcode = 'hu';
$language = \Drupal\language\Entity\ConfigurableLanguage::load($langcode);
// From install.core.inc
\Drupal::configFactory()->getEditable('system.site')->set('langcode', $langcode)->set('default_langcode', $langcode)->save();
\Drupal::service('language.default')->set($language);
// Load 'alakhu' format and remove null filter.
$format = \Drupal\filter\Entity\FilterFormat::load('alakhu');
$filters = $format->filters();
$filters->removeInstanceID('filter_null');
// $filters->removeFilter('filter_null');
$format->save();
// Create 'alakhu' editor.
/*
$ePM = \Drupal::service('plugin.manager.editor');
$plugin = $ePM->createInstance('ckeditor');
// $plugin = $this->ckeditorPluginManager->createInstance($plugin_id);

// $editor = \Drupal\editor\Entity\Editor::create(['id'=>'alakhu', 'plugin_id'=>'ckeditor']);
// From Entity.php
$values=['id'=>'alakhu'];
 /**
  * Sets up a configuration string with a translation.
  *
  * The actual configuration is already available by installing locale_test
  * module, as it is done in LocaleConfigSubscriberTest::setUp(). This sets up
  * the necessary source and translation strings and verifies that everything
  * is as expected to avoid false positives.
  *
  * @param string $config_name
  *   The configuration name.
  * @param string $key
  *   The configuration key.
  * @param string $source
  *   The source string.
  * @param string $translation
  *   The translation string.
  */
 protected function setUpTranslation($config_name, $key, $source, $translation)
 {
     // Create source and translation strings for the configuration value and add
     // the configuration name as a location. This would be performed by
     // locale_translate_batch_import() and locale_config_update_multiple()
     // normally.
     $source_object = $this->stringStorage->createString(['source' => $source, 'context' => ''])->save();
     $this->stringStorage->createTranslation(['lid' => $source_object->getId(), 'language' => $this->langcode, 'translation' => $translation])->save();
     $this->localeConfigManager->translateString($config_name, $this->langcode, $source, '');
     $this->languageManager->setConfigOverrideLanguage(ConfigurableLanguage::load($this->langcode));
     $this->assertConfigValue($config_name, $key, $translation);
     $this->assertTranslation($config_name, $translation, FALSE);
 }
Ejemplo n.º 18
0
 /**
  * Tests translation deletion.
  */
 protected function doTestTranslationDeletion()
 {
     // Confirm and delete a translation.
     $langcode = 'fr';
     $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
     $url = $entity->urlInfo('edit-form', array('language' => ConfigurableLanguage::load($langcode)));
     $this->drupalPostForm($url, array(), t('Delete translation'));
     $this->drupalPostForm(NULL, array(), t('Delete'));
     $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
     if ($this->assertTrue(is_object($entity), 'Entity found')) {
         $translations = $entity->getTranslationLanguages();
         $this->assertTrue(count($translations) == 2 && empty($translations[$langcode]), 'Translation successfully deleted.');
     }
 }
Ejemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 public function languageDelete(\stdClass $language)
 {
     $configurable_language = ConfigurableLanguage::load($language->langcode);
     $configurable_language->delete();
 }
 /**
  * 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) {
         ConfigurableLanguage::create(array('id' => $language_code, 'label' => $this->randomMachineName()))->save();
     }
     // Fixed language.
     ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'custom_bundle')->setLanguageAlterable(TRUE)->setDefaultLangcode('bb')->save();
     $langcode = language_get_default_langcode('entity_test', 'custom_bundle');
     $this->assertEqual($langcode, 'bb');
     // Current interface.
     ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'custom_bundle')->setLanguageAlterable(TRUE)->setDefaultLangcode('current_interface')->save();
     $langcode = language_get_default_langcode('entity_test', 'custom_bundle');
     $language_interface = \Drupal::languageManager()->getCurrentLanguage();
     $this->assertEqual($langcode, $language_interface->getId());
     // Site's default.
     $old_default = \Drupal::languageManager()->getDefaultLanguage();
     // Ensure the language entity default value is correct.
     $configurable_language = ConfigurableLanguage::load($old_default->getId());
     $this->assertTrue($configurable_language->isDefault(), 'The en language entity is flagged as the default language.');
     $this->config('system.site')->set('default_langcode', 'cc')->save();
     ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'custom_bundle')->setLanguageAlterable(TRUE)->setDefaultLangcode(LanguageInterface::LANGCODE_SITE_DEFAULT)->save();
     $langcode = language_get_default_langcode('entity_test', 'custom_bundle');
     $this->assertEqual($langcode, 'cc');
     // Ensure the language entity default value is correct.
     $configurable_language = ConfigurableLanguage::load($old_default->getId());
     $this->assertFalse($configurable_language->isDefault(), 'The en language entity is not flagged as the default language.');
     $configurable_language = ConfigurableLanguage::load('cc');
     // Check calling the
     // \Drupal\language\ConfigurableLanguageInterface::isDefault() method
     // directly.
     $this->assertTrue($configurable_language->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);
     ContentLanguageSettings::create(['target_entity_type_id' => 'entity_test', 'target_bundle' => 'some_bundle'])->setLanguageAlterable(TRUE)->setDefaultLangcode('authors_default')->save();
     $this->drupalGet('language-tests/language_configuration_element_test');
     $this->assertOptionSelected('edit-langcode', 'bb');
 }