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->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(); }
/** * {@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 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(); }
/** * {@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(); }
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(); // 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 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'); }
/** * 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.'); }
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; }
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(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Enable an additional language. ConfigurableLanguage::createFromLangcode('de')->save(); $this->installEntitySchema('entity_test_mul'); }
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(); }
/** * 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); }
/** * {@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']); }
/** * 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(); }
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(); }
/** * {@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 setUp() { parent::setUp(); $web_user = $this->drupalCreateUser(array('administer entity_test content')); $this->drupalLogin($web_user); // Add a language. ConfigurableLanguage::createFromLangcode('ro')->save(); }
protected function setUp() { parent::setUp(); $this->installConfig(array('language')); // Setup Italian. ConfigurableLanguage::createFromLangcode('it')->save(); $this->manager = $this->container->get('plugin.manager.condition'); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); // Change the language default object to different values. ConfigurableLanguage::createFromLangcode('fr')->save(); $this->config('system.site')->set('default_langcode', 'fr')->save(); $this->drupalLogin($this->rootUser); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $language = ConfigurableLanguage::createFromLangcode('de'); $language->save(); $language = ConfigurableLanguage::createFromLangcode('es'); $language->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Delete the override config_test entity. It is not required by this test. \Drupal::entityManager()->getStorage('config_test')->load('override')->delete(); ConfigurableLanguage::createFromLangcode('hu')->save(); $this->drupalPlaceBlock('local_actions_block'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->installEntitySchema('entity_test_mul'); ConfigurableLanguage::createFromLangcode('en')->save(); ConfigurableLanguage::createFromLangcode('fr')->save(); $this->storage = $this->container->get('entity.manager')->getStorage('entity_test_mul'); }
protected function setUp() { parent::setUp(); // Create and log in user. $this->webUser = $this->drupalCreateUser(array('administer entity_test content', 'view test entity')); $this->drupalLogin($this->webUser); // Enable an additional language. ConfigurableLanguage::createFromLangcode('de')->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Enable an additional language. ConfigurableLanguage::createFromLangcode('de')->save(); ConfigurableLanguage::createFromLangcode('fr')->save(); $this->installEntitySchema('entity_test_field_methods'); $this->entityTestFieldMethodsStorage = $this->entityManager->getStorage('entity_test_field_methods'); }
protected function setUp() { parent::setUp(); $this->installEntitySchema('entity_test_mulrev'); $this->installConfig(array('language')); $figures = Unicode::strtolower($this->randomMachineName()); $greetings = Unicode::strtolower($this->randomMachineName()); foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) { $field_storage = entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'entity_test_mulrev', 'type' => $field_type, 'cardinality' => 2)); $field_storage->save(); $field_storages[] = $field_storage; } $bundles = array(); for ($i = 0; $i < 2; $i++) { // For the sake of tablesort, make sure the second bundle is higher than // the first one. Beware: MySQL is not case sensitive. do { $bundle = $this->randomMachineName(); } while ($bundles && strtolower($bundles[0]) >= strtolower($bundle)); entity_test_create_bundle($bundle); foreach ($field_storages as $field_storage) { entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => $bundle))->save(); } $bundles[] = $bundle; } // Each unit is a list of field name, langcode and a column-value array. $units[] = array($figures, 'en', array('color' => 'red', 'shape' => 'triangle')); $units[] = array($figures, 'en', array('color' => 'blue', 'shape' => 'circle')); // To make it easier to test sorting, the greetings get formats according // to their langcode. $units[] = array($greetings, 'tr', array('value' => 'merhaba', 'format' => 'format-tr')); $units[] = array($greetings, 'pl', array('value' => 'siema', 'format' => 'format-pl')); // Make these languages available to the greetings field. ConfigurableLanguage::createFromLangcode('tr')->save(); ConfigurableLanguage::createFromLangcode('pl')->save(); // Calculate the cartesian product of the unit array by looking at the // bits of $i and add the unit at the bits that are 1. For example, // decimal 13 is binary 1101 so unit 3,2 and 0 will be added to the // entity. for ($i = 1; $i <= 15; $i++) { $entity = entity_create('entity_test_mulrev', array('type' => $bundles[$i & 1], 'name' => $this->randomMachineName(), 'langcode' => 'en')); // Make sure the name is set for every language that we might create. foreach (array('tr', 'pl') as $langcode) { $entity->getTranslation($langcode)->name = $this->randomMachineName(); } foreach (array_reverse(str_split(decbin($i))) as $key => $bit) { if ($bit) { list($field_name, $langcode, $values) = $units[$key]; $entity->getTranslation($langcode)->{$field_name}[] = $values; } } $entity->save(); } $this->figures = $figures; $this->greetings = $greetings; $this->factory = \Drupal::service('entity.query'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $i = 0; foreach (array('af', 'am', 'ar') as $langcode) { $language = ConfigurableLanguage::createFromLangcode($langcode); $language->set('weight', $i--); $language->save(); } }