/** * @covers ::getWeight * @covers ::setWeight */ public function testWeight() { // The weight, an integer. Used to order languages with larger positive // weights sinking items toward the bottom of lists. $configurableLanguage = new ConfigurableLanguage(array('weight' => -5), 'configurable_language'); $this->assertEquals($configurableLanguage->getWeight(), -5); $this->assertEquals($configurableLanguage->setWeight(13)->getWeight(), 13); }
/** * 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'); }
/** * Tests content translation form translatability constraints messages. */ public function testContentTranslationForm() { $this->loginAsAdmin(['administer languages', 'administer content translation', 'create content translations', 'translate any entity']); // Check warning message is displayed. $this->drupalGet('admin/config/regional/content-language'); $this->assertText('(* unsupported) Paragraphs fields do not support translation.'); $this->addParagraphedContentType('paragraphed_test', 'paragraphs_field'); // Check error message is displayed. $this->drupalGet('admin/config/regional/content-language'); $this->assertText('(* unsupported) Paragraphs fields do not support translation.'); $this->assertRaw('<div class="messages messages--error'); // Add a second language. ConfigurableLanguage::create(['id' => 'de'])->save(); // Enable translation for paragraphed content type. $edit = ['entity_types[node]' => TRUE, 'settings[node][paragraphed_test][translatable]' => TRUE, 'settings[node][paragraphed_test][fields][paragraphs_field]' => FALSE]; $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration')); // Check content type field management warning. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs_field'); $this->assertText('Paragraphs fields do not support translation.'); // Make the paragraphs field translatable. $edit = ['entity_types[node]' => TRUE, 'settings[node][paragraphed_test][translatable]' => TRUE, 'settings[node][paragraphed_test][fields][paragraphs_field]' => TRUE]; $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration')); // Check content type field management error. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs_field'); $this->assertText('Paragraphs fields do not support translation.'); $this->assertRaw('<div class="messages messages--error'); }
function setUp() { parent::setUp(); // Add two new languages. ConfigurableLanguage::createFromLangcode('fr')->save(); ConfigurableLanguage::createFromLangcode('es')->save(); // Set up term names. $this->termNames = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris'); // Create a vocabulary. $this->vocabulary = Vocabulary::create(['name' => 'Views testing tags', 'vid' => 'views_testing_tags']); $this->vocabulary->save(); // Add a translatable field to the vocabulary. $field = FieldStorageConfig::create(array('field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'type' => 'text')); $field->save(); FieldConfig::create(['field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'label' => 'Foo', 'bundle' => 'views_testing_tags'])->save(); // Create term with translations. $taxonomy = $this->createTermWithProperties(array('name' => $this->termNames['en'], 'langcode' => 'en', 'description' => $this->termNames['en'], 'field_foo' => $this->termNames['en'])); foreach (array('es', 'fr') as $langcode) { $translation = $taxonomy->addTranslation($langcode, array('name' => $this->termNames[$langcode])); $translation->description->value = $this->termNames[$langcode]; $translation->field_foo->value = $this->termNames[$langcode]; } $taxonomy->save(); Views::viewsData()->clear(); ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views')); $this->container->get('router.builder')->rebuild(); }
protected function setUp() { parent::setUp(); $this->installConfig(array('language')); // Create another language beside English. ConfigurableLanguage::create(array('id' => 'xx-lolspeak', 'label' => 'Lolspeak'))->save(); }
/** * Test update changes configuration translations if enabled after language. */ public function testConfigTranslationImport() { $admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions')); $this->drupalLogin($admin_user); // Add a language. The Afrikaans translation file of locale_test_translate // (test.af.po) has been prepared with a configuration translation. ConfigurableLanguage::createFromLangcode('af')->save(); // Enable locale module. $this->container->get('module_installer')->install(array('locale')); $this->resetAll(); // Enable import of translations. By default this is disabled for automated // tests. $this->config('locale.settings')->set('translation.import_enabled', TRUE)->save(); // Add translation permissions now that the locale module has been enabled. $edit = array('authenticated[translate interface]' => 'translate interface'); $this->drupalPostForm('admin/people/permissions', $edit, t('Save permissions')); // Check and update the translation status. This will import the Afrikaans // translations of locale_test_translate module. $this->drupalGet('admin/reports/translations/check'); // Override the Drupal core translation status to be up to date. // Drupal core should not be a subject in this test. $status = locale_translation_get_status(); $status['drupal']['af']->type = 'current'; \Drupal::state()->set('locale.translation_status', $status); $this->drupalPostForm('admin/reports/translations', array(), t('Update translations')); // Check if configuration translations have been imported. $override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'system.maintenance'); $this->assertEqual($override->get('message'), 'Ons is tans besig met onderhoud op @site. Wees asseblief geduldig, ons sal binnekort weer terug wees.'); }
/** * 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'); }
protected function setUp() { parent::setUp(); // Create and log in user. $test_user = $this->drupalCreateUser(['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. ConfigurableLanguage::createFromLangcode('es')->save(); // Set up times to be applied to the English and Spanish translations of the // node create time, so that they are filtered in/out in the // search_date_query_alter test module. $created_time_en = new \DateTime('February 10 2016 10PM'); $created_time_es = new \DateTime('March 19 2016 10PM'); $default_format = filter_default_format(); $node = $this->drupalCreateNode(['title' => 'Node EN', 'type' => 'page', 'body' => ['value' => $this->randomMachineName(32), 'format' => $default_format], 'langcode' => 'en', 'created' => $created_time_en->format('U')]); // Add Spanish translation to the node. $translation = $node->addTranslation('es', ['title' => 'Node ES']); $translation->body->value = $this->randomMachineName(32); $translation->created->value = $created_time_es->format('U'); $node->save(); // Update the index. $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); $plugin->updateIndex(); search_update_totals(); }
protected function setUp() { parent::setUp(); $permissions = array('access administration pages', 'administer site configuration'); $this->drupalLogin($this->drupalCreateUser($permissions)); ConfigurableLanguage::createFromLangcode('es')->save(); }
protected function setUp() { parent::setUp(); // Set up an additional language. $this->langcodes = array(language_default()->getId(), 'es'); ConfigurableLanguage::createFromLangcode('es')->save(); // Create a content type. $this->bundle = $this->randomMachineName(); $this->contentType = $this->drupalCreateContentType(array('type' => $this->bundle)); // Enable translation for the current entity type and ensure the change is // picked up. content_translation_set_config('node', $this->bundle, 'enabled', TRUE); drupal_static_reset(); \Drupal::entityManager()->clearCachedBundles(); \Drupal::service('router.builder')->rebuild(); // Add a translatable field to the content type. entity_create('field_storage_config', array('field_name' => 'field_test_text', 'entity_type' => 'node', 'type' => 'text', 'cardinality' => 1, 'translatable' => TRUE))->save(); entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_text', 'bundle' => $this->bundle, 'label' => 'Test text-field'))->save(); entity_get_form_display('node', $this->bundle, 'default')->setComponent('field_test_text', array('type' => 'text_textfield', 'weight' => 0))->save(); // Enable content translation. $configuration = array('langcode' => language_default()->getId(), 'language_show' => TRUE); language_save_default_configuration('node', $this->bundle, $configuration); // Create a translator user. $permissions = array('access contextual links', 'administer nodes', "edit any {$this->bundle} content", 'translate any entity'); $this->translator = $this->drupalCreateUser($permissions); }
protected function setUp() { parent::setUp(); $this->languageManager = $this->container->get('language_manager'); $this->installEntitySchema('entity_test_rev'); $this->installEntitySchema('entity_test_mul'); $this->installEntitySchema('entity_test_mulrev'); $this->installConfig(array('language')); // Create the test field. entity_test_install(); // Enable translations for the test entity type. $this->state->set('entity_test.translation', TRUE); // Create a translatable test field. $this->field_name = drupal_strtolower($this->randomMachineName() . '_field_name'); // Create an untranslatable test field. $this->untranslatable_field_name = drupal_strtolower($this->randomMachineName() . '_field_name'); // Create field fields in all entity variations. foreach (entity_test_entity_types() as $entity_type) { entity_create('field_storage_config', array('field_name' => $this->field_name, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save(); entity_create('field_config', array('field_name' => $this->field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => TRUE))->save(); $this->field[$entity_type] = entity_load('field_config', $entity_type . '.' . $entity_type . '.' . $this->field_name); entity_create('field_storage_config', array('field_name' => $this->untranslatable_field_name, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save(); entity_create('field_config', array('field_name' => $this->untranslatable_field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => FALSE))->save(); } // Create the default languages. $this->installConfig(array('language')); // Create test languages. $this->langcodes = array(); for ($i = 0; $i < 3; ++$i) { $language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString(), 'weight' => $i)); $this->langcodes[$i] = $language->getId(); $language->save(); } }
protected function setUp() { parent::setUp(); $this->installEntitySchema('entity_test_mulrev'); $this->installEntitySchema('configurable_language'); ConfigurableLanguage::createFromLangcode('es')->save(); }
function setUp() { parent::setUp(); // Create Page content type. if ($this->profile != 'standard') { $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); } // Add two new languages. ConfigurableLanguage::createFromLangcode('fr')->save(); ConfigurableLanguage::createFromLangcode('es')->save(); // Make the body field translatable. The title is already translatable by // definition. $field_storage = FieldStorageConfig::loadByName('node', 'body'); $field_storage->translatable = TRUE; $field_storage->save(); // Set up node titles. $this->node_titles = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris'); // Create node with translations. $node = $this->drupalCreateNode(array('title' => $this->node_titles['en'], 'langcode' => 'en', 'type' => 'page', 'body' => array(array('value' => $this->node_titles['en'])))); foreach (array('es', 'fr') as $langcode) { $translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode])); $translation->body->value = $this->node_titles[$langcode]; } $node->save(); }
public function setUp() { parent::setup(); $this->installConfig(array('pathauto', 'taxonomy', 'system', 'node')); $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installEntitySchema('taxonomy_term'); ConfigurableLanguage::createFromLangcode('fr')->save(); $this->installSchema('node', array('node_access')); $this->installSchema('system', array('url_alias', 'sequences', 'router')); $type = NodeType::create(['type' => 'page']); $type->save(); node_add_body_field($type); $this->nodePattern = $this->createPattern('node', '/content/[node:title]'); $this->userPattern = $this->createPattern('user', '/users/[user:name]'); \Drupal::service('router.builder')->rebuild(); $this->currentUser = entity_create('user', array('name' => $this->randomMachineName())); $this->currentUser->save(); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); // Enable translation for the entity_test module. \Drupal::state()->set('entity_test.translation', TRUE); $this->installSchema('search_api', array('search_api_item', 'search_api_task')); $this->installEntitySchema('entity_test_mul'); // Create the default languages. $this->installConfig(array('language')); $this->langcodes = array(); for ($i = 0; $i < 3; ++$i) { /** @var \Drupal\language\Entity\ConfigurableLanguage $language */ $language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => 'language - ' . $i, 'weight' => $i)); $this->langcodes[$i] = $language->getId(); $language->save(); } // Do not use a batch for tracking the initial items after creating an // index when running the tests via the GUI. Otherwise, it seems Drupal's // Batch API gets confused and the test fails. \Drupal::state()->set('search_api_use_tracking_batch', FALSE); // Create a test server. $this->server = Server::create(array('name' => 'Test Server', 'id' => 'test_server', 'status' => 1, 'backend' => 'search_api_test_backend')); $this->server->save(); // Create a test index. $this->index = Index::create(array('name' => 'Test Index', 'id' => 'test_index', 'status' => 1, 'datasource_settings' => array('entity:' . $this->testEntityTypeId => array('plugin_id' => 'entity:' . $this->testEntityTypeId, 'settings' => array())), 'tracker_settings' => array('default' => array('plugin_id' => 'default', 'settings' => array())), 'server' => $this->server->id(), 'options' => array('index_directly' => FALSE))); $this->index->save(); }
/** * Test that when an English node is updated, its old English alias is * updated and its newer French alias is left intact. */ function testLanguageAliases() { // Add predefined French language. ConfigurableLanguage::createFromLangcode('fr')->save(); $node = array('title' => 'English node', 'langcode' => 'en', 'path' => array(array('alias' => '/english-node', 'pathauto' => FALSE))); $node = $this->drupalCreateNode($node); $english_alias = \Drupal::service('path.alias_storage')->load(array('alias' => '/english-node', 'langcode' => 'en')); $this->assertTrue($english_alias, 'Alias created with proper language.'); // Also save a French alias that should not be left alone, even though // it is the newer alias. $this->saveEntityAlias($node, '/french-node', 'fr'); // Add an alias with the soon-to-be generated alias, causing the upcoming // alias update to generate a unique alias with the '-0' suffix. $this->saveAlias('/node/invalid', '/content/english-node', Language::LANGCODE_NOT_SPECIFIED); // Update the node, triggering a change in the English alias. $node->path->pathauto = PathautoState::CREATE; $node->save(); // Check that the new English alias replaced the old one. $this->assertEntityAlias($node, '/content/english-node-0', 'en'); $this->assertEntityAlias($node, '/french-node', 'fr'); $this->assertAliasExists(array('pid' => $english_alias['pid'], 'alias' => '/content/english-node-0')); // Create a new node with the same title as before but without // specifying a language. $node = $this->drupalCreateNode(array('title' => 'English node', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED)); // Check that the new node had a unique alias generated with the '-1' // suffix. $this->assertEntityAlias($node, '/content/english-node-1', LanguageInterface::LANGCODE_NOT_SPECIFIED); }
/** * 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.'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); ConfigurableLanguage::createFromLangcode('it')->save(); /** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */ $manager = \Drupal::service('content_translation.manager'); $manager->setEnabled('node', 'article', TRUE); // Create and log in user. $web_user = $this->drupalCreateUser(array('view page revisions', 'revert page revisions', 'delete page revisions', 'edit any page content', 'delete any page content', 'translate any entity')); $this->drupalLogin($web_user); // Create initial node. $node = $this->drupalCreateNode(); $settings = get_object_vars($node); $settings['revision'] = 1; $settings['isDefaultRevision'] = TRUE; $nodes = array(); $logs = array(); // Get original node. $nodes[] = clone $node; // Create three revisions. $revision_count = 3; for ($i = 0; $i < $revision_count; $i++) { $logs[] = $node->revision_log = $this->randomMachineName(32); // Create revision with a random title and body and update variables. $node->title = $this->randomMachineName(); $node->body = array('value' => $this->randomMachineName(32), 'format' => filter_default_format()); $node->setNewRevision(); $node->save(); $node = Node::load($node->id()); // Make sure we get revision information. $nodes[] = clone $node; } $this->nodes = $nodes; $this->revisionLogs = $logs; }
protected 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. ConfigurableLanguage::createFromLangcode('es')->save(); // 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->setTranslatable(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->searchableNodes = []; foreach ($nodes as $setting) { $this->searchableNodes[] = $this->drupalCreateNode($setting); } // Add English translation to the second node. $translation = $this->searchableNodes[1]->addTranslation('en', array('title' => 'Second node en')); $translation->body->value = $this->randomMachineName(32); $this->searchableNodes[1]->save(); // Add Spanish translation to the third node. $translation = $this->searchableNodes[2]->addTranslation('es', array('title' => 'Third node es')); $translation->body->value = $this->randomMachineName(32); $this->searchableNodes[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} */ protected function setUp() { parent::setUp(); ConfigurableLanguage::createFromLangcode('de')->save(); $this->drupalLogin($this->drupalCreateUser(['administer site configuration', 'translate configuration'])); PageVariant::create(['variant' => 'http_status_code', 'label' => 'HTTP status code', 'id' => 'http_status_code', 'page' => 'node_view'])->save(); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $moduleHandler = $this->moduleHandler; $moduleHandler->loadInclude('locale', 'inc', 'locale.translation'); $moduleHandler->loadInclude('locale', 'module'); $language = $input->getArgument('language'); $languages = $this->site->getStandardLanguages(); if (isset($languages[$language])) { $langcode = $language; } elseif (array_search($language, $languages)) { $langcode = array_search($language, $languages); } else { $io->error(sprintf($this->trans('commands.locale.language.add.messages.invalid-language'), $language)); return 1; } try { $language = ConfigurableLanguage::createFromLangcode($langcode); $language->type = LOCALE_TRANSLATION_REMOTE; $language->save(); $io->info(sprintf($this->trans('commands.locale.language.add.messages.language-add-successfully'), $language->getName())); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } return 0; }
/** * 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. ConfigurableLanguage::createFromLangcode('es')->save(); // 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 configuration')); // 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'); }
function setUp() { parent::setUp(); $this->drupalLogin($this->drupalCreateUser(['access comments'])); // Add two new languages. ConfigurableLanguage::createFromLangcode('fr')->save(); ConfigurableLanguage::createFromLangcode('es')->save(); // Set up comment titles. $this->commentTitles = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris'); // Create a new comment. Using the one created earlier will not work, // as it predates the language set-up. $comment = array('uid' => $this->loggedInUser->id(), 'entity_id' => $this->nodeUserCommented->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'cid' => '', 'pid' => '', 'node_type' => ''); $this->comment = Comment::create($comment); // Add field values and translate the comment. $this->comment->subject->value = $this->commentTitles['en']; $this->comment->comment_body->value = $this->commentTitles['en']; $this->comment->langcode = 'en'; $this->comment->save(); foreach (array('es', 'fr') as $langcode) { $translation = $this->comment->addTranslation($langcode, array()); $translation->comment_body->value = $this->commentTitles[$langcode]; $translation->subject->value = $this->commentTitles[$langcode]; } $this->comment->save(); }
/** * 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); } }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Create Page content type. if ($this->profile != 'standard') { $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); } // Add two new languages. ConfigurableLanguage::createFromLangcode('fr')->save(); ConfigurableLanguage::createFromLangcode('es')->save(); // Make the body field translatable. The title is already translatable by // definition. $field_storage = FieldStorageConfig::loadByName('node', 'body'); $field_storage->translatable = TRUE; $field_storage->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); }
/** * Tests views_ui tour tip availability in a different language. */ public function testViewsUiTourTipsTranslated() { $langcode = 'nl'; // Add a default locale storage for this test. $this->localeStorage = $this->container->get('locale.storage'); // Add Dutch language programmatically. ConfigurableLanguage::createFromLangcode($langcode)->save(); // Handler titles that need translations. $handler_titles = array('Format', 'Fields', 'Sort criteria', 'Filter criteria'); foreach ($handler_titles as $handler_title) { // Create source string. $source = $this->localeStorage->createString(array('source' => $handler_title)); $source->save(); $this->createTranslation($source, $langcode); } // Create a basic view that shows all content, with a page and a block // display. $view['label'] = $this->randomMachineName(16); $view['id'] = strtolower($this->randomMachineName(16)); $view['page[create]'] = 1; $view['page[path]'] = $this->randomMachineName(16); // Load the page in dutch. $this->drupalPostForm($langcode . '/admin/structure/views/add', $view, t('Save and edit')); $this->assertTourTips(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Enable an additional language. ConfigurableLanguage::createFromLangcode('de')->save(); $this->installEntitySchema('entity_test_mul'); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); // Create content types. $this->drupalCreateContentType(['type' => 'page']); $this->drupalCreateContentType(['type' => 'article']); // Add a new language. ConfigurableLanguage::createFromLangcode('es')->save(); // 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->setTranslatable(TRUE); $field_storage->save(); // Add 9 nodes of the type page. for ($i = 1; $i <= 9; $i++) { // Adding a different created time per language to avoid to have exactly // the same value per nid and langcode. $created_time_en = new \DateTime('February ' . $i . ' 2016 ' . str_pad($i, 2, STR_PAD_LEFT, 0) . 'PM'); $created_time_es = new \DateTime('March ' . $i . ' 2016 ' . str_pad($i, 2, STR_PAD_LEFT, 0) . 'PM'); $node = $this->drupalCreateNode(array('title' => 'test page' . $i . ' EN', 'body' => 'test page' . $i, 'type' => 'page', 'created' => $created_time_en->format('U'), 'langcode' => 'en')); // Add Spanish translation to the node. $node->addTranslation('es', ['title' => 'test page' . $i . ' ES', 'created' => $created_time_es->format('U')]); $node->save(); } $created_time = new \DateTime('March 9 2016 11PM'); $this->drupalCreateNode(array('title' => 'test page 10 EN', 'body' => 'test page10', 'type' => 'page', 'created' => $created_time->format('U'), 'langcode' => 'en')); // Add 10 nodes of the type article. for ($i = 1; $i <= 10; $i++) { $created_time = new \DateTime('April ' . $i . ' 2016 ' . str_pad($i, 2, STR_PAD_LEFT, 0) . 'PM'); $this->drupalCreateNode(array('title' => 'test article' . $i . ' EN', 'body' => 'test article' . $i, 'type' => 'article', 'created' => $created_time->format('U'), 'langcode' => 'en')); } // Create the users used for the tests. $this->adminUser = $this->drupalCreateUser(['administer search', 'use advanced search', 'administer facets', 'access administration pages', 'administer nodes', 'access content overview', 'administer content types', 'administer blocks', 'search content', 'administer languages', 'administer site configuration', 'access content']); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->installConfig(['system']); $this->installConfig(['field']); $this->installConfig(['text']); $this->installConfig(['address']); $this->installEntitySchema('entity_test'); ConfigurableLanguage::createFromLangcode('zh-hant')->save(); // The address module is never installed, so the importer doesn't run // automatically. Instead, we manually import the address formats we need. $country_codes = ['AD', 'SV', 'TW', 'US', 'ZZ']; $importer = \Drupal::service('address.address_format_importer'); $importer->importEntities($country_codes); $importer->importTranslations(['zh-hant']); $this->entityType = 'entity_test'; $this->bundle = $this->entityType; $this->fieldName = Unicode::strtolower($this->randomMachineName()); $field_storage = FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'address']); $field_storage->save(); $field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->bundle, 'label' => $this->randomMachineName()]); $field->save(); $values = ['targetEntityType' => $this->entityType, 'bundle' => $this->bundle, 'mode' => 'default', 'status' => TRUE]; $this->display = \Drupal::entityTypeManager()->getStorage('entity_view_display')->create($values); $this->display->setComponent($this->fieldName, ['type' => 'address_default', 'settings' => []]); $this->display->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->installSchema('system', array('url_alias', 'router')); $this->installEntitySchema('user'); $this->installEntitySchema('entity_test'); $this->installConfig(array('field', 'language')); // Add German as a language. ConfigurableLanguage::create(array('id' => 'de', 'label' => 'Deutsch', 'weight' => -1))->save(); // Create the test text field. entity_create('field_storage_config', array('field_name' => 'field_test_text', 'entity_type' => 'entity_test', 'type' => 'text'))->save(); entity_create('field_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('field_name' => 'field_test_translatable_text', 'entity_type' => 'entity_test', 'type' => 'text'))->save(); entity_create('field_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('field_name' => 'field_test_entity_reference', 'entity_type' => 'entity_test', 'type' => 'entity_reference', 'settings' => array('target_type' => 'entity_test')))->save(); entity_create('field_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); }