Ejemplo n.º 1
0
 /**
  * {@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();
 }
 /**
  * {@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);
 }
 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();
     }
 }
 /**
  * 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');
 }
Ejemplo n.º 5
0
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(array('language'));
     // Create another language beside English.
     ConfigurableLanguage::create(array('id' => 'xx-lolspeak', 'label' => 'Lolspeak'))->save();
 }
Ejemplo n.º 6
0
 protected function setUp()
 {
     parent::setUp();
     $this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer menu')));
     // Add some custom languages.
     foreach (array('aa', 'bb', 'cc', 'cs') as $language_code) {
         ConfigurableLanguage::create(array('id' => $language_code, 'label' => $this->randomMachineName()))->save();
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $definitions = \Drupal::service('plugin.manager.config_translation.mapper')->getDefinitions();
     $this->pluginId = key($definitions);
     $this->langcode = 'xx';
     ConfigurableLanguage::create(array('id' => $this->langcode, 'label' => 'XX'))->save();
     \Drupal::state()->set('config_translation_test_alter_form_alter', TRUE);
 }
Ejemplo n.º 8
0
 protected function setUp()
 {
     parent::setUp();
     // Create an administrative user.
     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
     // Add some custom languages.
     ConfigurableLanguage::create(array('id' => 'aa', 'label' => $this->randomMachineName()))->save();
     ConfigurableLanguage::create(array('id' => 'bb', 'label' => $this->randomMachineName()))->save();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test');
     $this->installEntitySchema('entity_test_mul');
     \Drupal::service('router.builder')->rebuild();
     // Adding german language.
     ConfigurableLanguage::create(['id' => 'de'])->save();
     $this->config('language.types')->setData(['configurable' => ['language_interface'], 'negotiation' => ['language_interface' => ['enabled' => ['language-url' => 0]]]])->save();
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('user');
     $this->installEntitySchema('simplenews_subscriber');
     $this->installSchema('system', array('sequences', 'sessions'));
     $this->config('system.mail')->set('interface.default', 'test_mail_collector')->save();
     $this->config('simplenews.settings')->set('subscriber.sync_fields', TRUE)->save();
     ConfigurableLanguage::create(array('id' => 'fr'))->save();
 }
Ejemplo n.º 11
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;
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     ConfigurableLanguage::create(['id' => 'es'])->save();
     ConfigurableLanguage::create(['id' => 'fr'])->save();
     // In order to reflect the changes for a multilingual site in the container
     // we have to rebuild it.
     $this->rebuildContainer();
     $this->createTranslatableEntity();
     $user = $this->drupalCreateUser(array('view test entity'));
     $this->drupalLogin($user);
 }
Ejemplo n.º 13
0
 protected function setUp()
 {
     parent::setUp();
     // Create an administrative user.
     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
     // Create a vocabulary to which the terms will be assigned.
     $this->vocabulary = $this->createVocabulary();
     // Add some custom languages.
     foreach (array('aa', 'bb', 'cc') as $language_code) {
         ConfigurableLanguage::create(array('id' => $language_code, 'label' => $this->randomMachineName()))->save();
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp($import_test_views = TRUE)
 {
     parent::setUp($import_test_views);
     $node_type = NodeType::create(['type' => 'article', 'label' => 'Article']);
     $node_type->save();
     /** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
     $content_translation_manager = \Drupal::service('content_translation.manager');
     $content_translation_manager->setEnabled('node', 'article', TRUE);
     $language = ConfigurableLanguage::create(['id' => 'es', 'label' => 'Spanish']);
     $language->save();
     // Rebuild the container to setup the language path processors.
     $this->rebuildContainer();
 }
 protected function setUp()
 {
     parent::setUp();
     // Enable translations for the test entity type.
     \Drupal::state()->set('entity_test.translation', TRUE);
     // Create test languages.
     $this->langcodes = array();
     for ($i = 0; $i < 2; ++$i) {
         $language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()));
         $this->langcodes[$i] = $language->id();
         $language->save();
     }
 }
 /**
  * Ensures entity access for entity translations is properly working.
  */
 function testEntityTranslationAccess()
 {
     // Set up a non-admin user that is allowed to view test entity translations.
     \Drupal::currentUser()->setAccount($this->createUser(array('uid' => 2), array('view test entity translations')));
     // Create two test languages.
     foreach (array('foo', 'bar') as $langcode) {
         ConfigurableLanguage::create(array('id' => $langcode, 'label' => $this->randomString()))->save();
     }
     $entity = entity_create('entity_test', array('name' => 'test', 'langcode' => 'foo'));
     $entity->save();
     $translation = $entity->getTranslation('bar');
     $this->assertEntityAccess(array('view' => TRUE), $translation);
 }
Ejemplo n.º 17
0
 protected function setUp()
 {
     parent::setUp();
     $this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
     $field_storage = array('field_name' => $this->fieldName, 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 4);
     entity_create('field_storage_config', $field_storage)->save();
     $this->fieldStorage = FieldStorageConfig::load($this->entityTypeId . '.' . $this->fieldName);
     $field = array('field_storage' => $this->fieldStorage, 'bundle' => $this->entityTypeId);
     entity_create('field_config', $field)->save();
     $this->field = FieldConfig::load($this->entityTypeId . '.' . $field['bundle'] . '.' . $this->fieldName);
     entity_get_form_display($this->entityTypeId, $this->entityTypeId, 'default')->setComponent($this->fieldName)->save();
     for ($i = 0; $i < 3; ++$i) {
         ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()))->save();
     }
 }
Ejemplo n.º 18
0
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test');
     $this->installEntitySchema('configurable_language');
     \Drupal::service('router.builder')->rebuild();
     // In order to reflect the changes for a multilingual site in the container
     // we have to rebuild it.
     ConfigurableLanguage::create(['id' => 'es'])->save();
     ConfigurableLanguage::create(['id' => 'fr'])->save();
     $config = $this->config('language.negotiation');
     $config->set('url.prefixes', ['en' => 'en', 'es' => 'es', 'fr' => 'fr'])->save();
     \Drupal::service('kernel')->rebuildContainer();
     $this->createTranslatableEntity();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(array('language'));
     $this->field_name = drupal_strtolower($this->randomMachineName());
     $this->entity_type = 'entity_test';
     $this->field_storage_definition = array('field_name' => $this->field_name, 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 4, 'translatable' => TRUE);
     $this->fieldStorage = entity_create('field_storage_config', $this->field_storage_definition);
     $this->fieldStorage->save();
     $this->field_definition = array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test');
     $this->field = entity_create('field_config', $this->field_definition);
     $this->field->save();
     for ($i = 0; $i < 3; ++$i) {
         ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()))->save();
     }
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(array('language'));
     $this->fieldName = Unicode::strtolower($this->randomMachineName());
     $this->entityType = 'entity_test';
     $this->fieldStorageDefinition = array('field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'test_field', 'cardinality' => 4);
     $this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition);
     $this->fieldStorage->save();
     $this->fieldDefinition = array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test');
     $this->field = FieldConfig::create($this->fieldDefinition);
     $this->field->save();
     for ($i = 0; $i < 3; ++$i) {
         ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()))->save();
     }
 }
Ejemplo n.º 21
0
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test');
     $this->installEntitySchema('configurable_language');
     $this->installSchema('system', 'router');
     \Drupal::service('router.builder')->rebuild();
     // In order to reflect the changes for a multilingual site in the container
     // we have to rebuild it.
     ConfigurableLanguage::create(['id' => 'es'])->save();
     ConfigurableLanguage::create(['id' => 'fr'])->save();
     $this->config('language.types')->setData(['configurable' => ['language_interface'], 'negotiation' => ['language_interface' => ['enabled' => ['language-url' => 0]]]])->save();
     $this->config('language.negotiation')->setData(['url' => ['source' => 'path_prefix', 'prefixes' => ['en' => 'en', 'es' => 'es', 'fr' => 'fr']]])->save();
     $this->kernel->rebuildContainer();
     $this->container = $this->kernel->getContainer();
     \Drupal::setContainer($this->container);
 }
Ejemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('system', array('url_alias', 'router'));
     $this->installEntitySchema('user');
     $this->installEntitySchema('entity_test');
     // If the concrete test sub-class installs the Node or Comment modules,
     // ensure that the node and comment entity schema are created before the
     // field configurations are installed. This is because the entity tables
     // need to be created before the body field storage tables. This prevents
     // trying to create the body field tables twice.
     $class = get_class($this);
     while ($class) {
         if (property_exists($class, 'modules')) {
             // Only check the modules, if the $modules property was not inherited.
             $rp = new \ReflectionProperty($class, 'modules');
             if ($rp->class == $class) {
                 foreach (array_intersect(array('node', 'comment'), $class::$modules) as $module) {
                     $this->installEntitySchema($module);
                 }
             }
         }
         $class = get_parent_class($class);
     }
     $this->installConfig(array('field', 'language'));
     \Drupal::service('router.builder')->rebuild();
     // 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'), \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack')), new RelationLinkManager(new MemoryBackend('default'), $entity_manager, \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack')));
     $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);
 }
Ejemplo n.º 23
0
 /**
  * Tests that a facet works on a page with language prefix.
  *
  * @see https://www.drupal.org/node/2712557
  */
 public function testLanguageIntegration()
 {
     $facet_id = 'owl';
     $facet_name = 'Owl';
     $this->createFacet($facet_name, $facet_id);
     ConfigurableLanguage::create(['id' => 'xx-lolspeak'])->save();
     // Go to the search view with a language prefix and click on one of the
     // facets.
     $this->drupalGet('xx-lolspeak/search-api-test-fulltext');
     $this->assertText('item');
     $this->assertText('article');
     $this->clickLink('item');
     // Check that the language code is still in the url.
     $this->assertTrue(strpos($this->getUrl(), 'xx-lolspeak/'), 'Found the language code in the url');
     $this->assertResponse(200);
     $this->assertText('item');
     $this->assertText('article');
 }
Ejemplo n.º 24
0
 public function testUserFields()
 {
     ConfigurableLanguage::create(['id' => 'es', 'name' => 'Spanish'])->save();
     ConfigurableLanguage::create(['id' => 'fr', 'name' => 'French'])->save();
     $user = User::create(['name' => 'test user', 'mail' => '*****@*****.**', 'status' => 1, 'preferred_langcode' => 'es', 'preferred_admin_langcode' => 'fr', 'timezone' => 'ut1', 'created' => 123456]);
     $user->save();
     // @todo Expand the test coverage in https://www.drupal.org/node/2464635
     $this->assertFieldAccess('user', 'uid', $user->id());
     $this->assertFieldAccess('user', 'uuid', $user->uuid());
     $this->assertFieldAccess('user', 'langcode', $user->language()->getName());
     $this->assertFieldAccess('user', 'preferred_langcode', 'Spanish');
     $this->assertFieldAccess('user', 'preferred_admin_langcode', 'French');
     $this->assertFieldAccess('user', 'name', 'test user');
     // $this->assertFieldAccess('user', 'mail', '*****@*****.**');
     $this->assertFieldAccess('user', 'timezone', 'ut1');
     $this->assertFieldAccess('user', 'status', 'On');
     // $this->assertFieldAccess('user', 'created', \Drupal::service('date.formatter')->format(123456));
     // $this->assertFieldAccess('user', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));
 }
 /**
  * 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 = entity_load('configurable_language', $old_default->getId());
     $this->assertTrue($configurable_language->isDefault(), 'The en language entity is flagged as the default language.');
     $this->config('system.site')->set('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 = entity_load('configurable_language', $old_default->getId());
     $this->assertFalse($configurable_language->isDefault(), 'The en language entity is not flagged as the default language.');
     $configurable_language = entity_load('configurable_language', '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');
 }
 /**
  * Tests that the options printed by the language select element are correct.
  */
 function testLanguageSelectElementOptions()
 {
     // Add some languages.
     ConfigurableLanguage::create(array('id' => 'aaa', 'label' => $this->randomMachineName()))->save();
     ConfigurableLanguage::create(array('id' => 'bbb', 'label' => $this->randomMachineName()))->save();
     \Drupal::languageManager()->reset();
     $this->drupalGet('form-test/language_select');
     // Check that the language fields were rendered on the page.
     $ids = array('edit-languages-all' => LanguageInterface::STATE_ALL, 'edit-languages-configurable' => LanguageInterface::STATE_CONFIGURABLE, 'edit-languages-locked' => LanguageInterface::STATE_LOCKED, 'edit-languages-config-and-locked' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED);
     foreach ($ids as $id => $flags) {
         $this->assertField($id, format_string('The @id field was found on the page.', array('@id' => $id)));
         $options = array();
         foreach ($this->container->get('language_manager')->getLanguages($flags) as $langcode => $language) {
             $options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->name;
         }
         $this->_testLanguageSelectElementOptions($id, $options);
     }
     // Test that the #options were not altered by #languages.
     $this->assertField('edit-language-custom-options', format_string('The @id field was found on the page.', array('@id' => 'edit-language-custom-options')));
     $this->_testLanguageSelectElementOptions('edit-language-custom-options', array('opt1' => 'First option', 'opt2' => 'Second option', 'opt3' => 'Third option'));
 }
 /**
  * Check access for file fields.
  */
 public function testFileFields()
 {
     ConfigurableLanguage::create(['id' => 'fr', 'name' => 'French'])->save();
     $user = User::create(['name' => 'test user']);
     $user->save();
     file_put_contents('public://test.txt', 'test');
     $file = File::create(['filename' => 'test.txt', 'uri' => 'public://test.txt', 'status' => TRUE, 'langcode' => 'fr', 'uid' => $user->id()]);
     $file->save();
     // @todo Expand the test coverage in https://www.drupal.org/node/2464635
     $this->assertFieldAccess('file', 'fid', $file->id());
     $this->assertFieldAccess('file', 'uuid', $file->uuid());
     $this->assertFieldAccess('file', 'langcode', $file->language()->getName());
     $this->assertFieldAccess('file', 'uid', 'test user');
     $this->assertFieldAccess('file', 'filename', $file->getFilename());
     $this->assertFieldAccess('file', 'uri', $file->getFileUri());
     $this->assertFieldAccess('file', 'filemime', $file->filemime->value);
     $this->assertFieldAccess('file', 'filesize', '4 bytes');
     $this->assertFieldAccess('file', 'status', t('Permanent'));
     // $this->assertFieldAccess('file', 'created', \Drupal::service('date.formatter')->format(123456));
     // $this->assertFieldAccess('file', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));
 }
Ejemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('user');
     $this->installEntitySchema('node');
     $this->installEntitySchema('taxonomy_term');
     // Create the article content type with a text field.
     $node_type = NodeType::create(['type' => 'article']);
     $node_type->save();
     $field_storage = FieldStorageConfig::create(['field_name' => 'test_field', 'entity_type' => 'node', 'type' => 'text']);
     $field_storage->save();
     $field = FieldConfig::create(['field_name' => 'test_field', 'entity_type' => 'node', 'bundle' => 'article', 'label' => 'Test field']);
     $field->save();
     // Create a reference field with the same name on user.
     $field_storage = FieldStorageConfig::create(['field_name' => 'test_field', 'entity_type' => 'user', 'type' => 'entity_reference']);
     $field_storage->save();
     $field = FieldConfig::create(['field_name' => 'test_field', 'entity_type' => 'user', 'bundle' => 'user', 'label' => 'Test field']);
     $field->save();
     $this->testFormat = FilterFormat::create(['format' => 'test', 'weight' => 1, 'filters' => ['filter_html_escape' => ['status' => TRUE]]]);
     $this->testFormat->save();
     // Create a multi-value list_string field.
     $field_storage = FieldStorageConfig::create(['field_name' => 'test_list', 'entity_type' => 'node', 'type' => 'list_string', 'cardinality' => 2, 'settings' => ['allowed_values' => ['key1' => 'value1', 'key2' => 'value2']]]);
     $field_storage->save();
     $this->field = FieldConfig::create(['field_name' => 'test_list', 'entity_type' => 'node', 'bundle' => 'article'])->save();
     // Add an untranslatable node reference field.
     FieldStorageConfig::create(['field_name' => 'test_reference', 'type' => 'entity_reference', 'entity_type' => 'node', 'settings' => ['target_type' => 'node'], 'translatable' => FALSE])->save();
     FieldConfig::create(['field_name' => 'test_reference', 'entity_type' => 'node', 'bundle' => 'article', 'label' => 'Test reference'])->save();
     // Add an untranslatable taxonomy term reference field.
     $this->vocabulary = $this->createVocabulary();
     FieldStorageConfig::create(['field_name' => 'test_term_reference', 'type' => 'entity_reference', 'entity_type' => 'node', 'settings' => ['target_type' => 'taxonomy_term'], 'translatable' => FALSE])->save();
     FieldConfig::create(['field_name' => 'test_term_reference', 'entity_type' => 'node', 'bundle' => 'article', 'label' => 'Test term reference', 'settings' => ['handler' => 'default:taxonomy_term', 'handler_settings' => ['target_bundles' => [$this->vocabulary->id() => $this->vocabulary->id()]]]])->save();
     // Add a field to terms of the created vocabulary.
     $storage = FieldStorageConfig::create(['field_name' => 'term_field', 'entity_type' => 'taxonomy_term', 'type' => 'text']);
     $storage->save();
     $field = FieldConfig::create(['field_name' => 'term_field', 'entity_type' => 'taxonomy_term', 'bundle' => $this->vocabulary->id()]);
     $field->save();
     // Add a second language.
     $language = ConfigurableLanguage::create(['id' => 'de', 'label' => 'German']);
     $language->save();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->languageManager = $this->container->get('language_manager');
     foreach (entity_test_entity_types() as $entity_type_id) {
         // The entity_test schema is installed by the parent.
         if ($entity_type_id != 'entity_test') {
             $this->installEntitySchema($entity_type_id);
         }
     }
     $this->installConfig(array('language'));
     // Create the test field.
     module_load_install('entity_test');
     entity_test_install();
     // Enable translations for the test entity type.
     $this->state->set('entity_test.translation', TRUE);
     // Create a translatable test field.
     $this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
     // Create an untranslatable test field.
     $this->untranslatableFieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
     // Create field fields in all entity variations.
     foreach (entity_test_entity_types() as $entity_type) {
         FieldStorageConfig::create(array('field_name' => $this->fieldName, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save();
         FieldConfig::create(['field_name' => $this->fieldName, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => TRUE])->save();
         FieldStorageConfig::create(array('field_name' => $this->untranslatableFieldName, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save();
         FieldConfig::create(['field_name' => $this->untranslatableFieldName, '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();
     }
 }
Ejemplo n.º 30
0
  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();

    $this->drupalPlaceBlock('local_tasks_block');

    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
    $this->drupalCreateNode();

    ConfigurableLanguage::create(['id' => 'fi'])->save();

    // In order to reflect the changes for a multilingual site in the container
    // we have to rebuild it.
    $this->rebuildContainer();

    $alias_storage = $this->container->get('path.alias_storage');
    $alias_storage->save('/node/1', '/kittens');
    $alias_white_list = $this->container->get('path.alias_whitelist');
    $alias_white_list->set('node', TRUE);

    $admin_user = $this->drupalCreateUser([
      'bypass node access',
    ]);
    $this->drupalLogin($admin_user);
  }