createFromLangcode example

$path = '/path/add-one';
    $request = Request::create($path, 'GET');
    $provider->getRouteCollectionForRequest($request);

    $cache = $this->cache->get('route:[language]=en:/path/add-one:');
    $this->assertEquals('/path/add/one', $cache->data['path']);
    $this->assertEquals([]$cache->data['query']);
    $this->assertCount(3, $cache->data['routes']);

    // Test with a different current language by switching out the default     // language.     $swiss = ConfigurableLanguage::createFromLangcode('gsw-berne');
    $language_manager->reset();
    \Drupal::service('language.default')->set($swiss);

    $path = '/path/add-one';
    $request = Request::create($path, 'GET');
    $provider->getRouteCollectionForRequest($request);

    $cache = $this->cache->get('route:[language]=gsw-berne:/path/add-one:');
    $this->assertEquals('/path/add/one', $cache->data['path']);
    $this->assertEquals([]$cache->data['query']);
    $this->assertCount(3, $cache->data['routes']);
  }
'bypass node access',
      'administer content types',
      'translate interface',
      'administer entity_test fields',
    ]);
    // Create and login user.     $this->translatorUser = $this->drupalCreateUser($translator_permissions);
    $this->adminUser = $this->drupalCreateUser($admin_permissions);

    // Add languages.     foreach ($this->langcodes as $langcode) {
      ConfigurableLanguage::createFromLangcode($langcode)->save();
    }
    $this->drupalPlaceBlock('local_tasks_block');
    $this->drupalPlaceBlock('page_title_block');
  }

  /** * Tests the translation of field and field storage configuration. */
  public function testFieldConfigTranslation() {
    // Add a test field which has a translatable field setting and a     // translatable field storage setting.

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    // Delete the override config_test entity. It is not required by this test.     \Drupal::entityTypeManager()->getStorage('config_test')->load('override')->delete();
    ConfigurableLanguage::createFromLangcode('hu')->save();

    $this->drupalPlaceBlock('local_actions_block');
  }

  /** * Tests the listing UI with different language scenarios. */
  public function testListUI() {
    // Log in as an administrative user to access the full menu trail.     $this->drupalLogin($this->drupalCreateUser([
      'access administration pages',
      

  protected static $modules = ['views_ui', 'language'];

  /** * Tests changing label, description and tag. * * @see views_ui_edit_details_form */
  public function testDetails() {
    $view_name = 'test_view';

    ConfigurableLanguage::createFromLangcode('fr')->save();

    $edit = [
      'label' => $this->randomMachineName(),
      'tag' => $this->randomMachineName(),
      'description' => $this->randomMachineName(30),
      'langcode' => 'fr',
    ];

    $this->drupalGet("admin/structure/views/nojs/edit-details/{$view_name}/default");
    $this->submitForm($edit, 'Apply');
    $this->submitForm([], 'Save');

    
/** * 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 = [
      'Format',
      'Fields',
      'Sort criteria',
      'Filter criteria',
    ];

    foreach ($handler_titles as $handler_title) {
      // Create source string.

  protected $profile = 'testing';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    // Set up an additional language.     $this->langcodes = [\Drupal::languageManager()->getDefaultLanguage()->getId(), 'es'];
    ConfigurableLanguage::createFromLangcode('es')->save();

    // Create a content type.     $this->bundle = $this->randomMachineName();
    $this->contentType = $this->drupalCreateContentType(['type' => $this->bundle]);

    // Add a field to the content type. The field is not yet translatable.     FieldStorageConfig::create([
      'field_name' => 'field_test_text',
      'entity_type' => 'node',
      'type' => 'text',
      'cardinality' => 1,
    ])
// Setup users.     $admin_user = $this->drupalCreateUser([
      'administer languages',
      'administer content types',
      'access administration pages',
      'create page content',
      'edit own page content',
    ]);
    $this->drupalLogin($admin_user);

    // Add a new language.     ConfigurableLanguage::createFromLangcode('it')->save();

    // Enable URL language detection and selection.     $edit = ['language_interface[enabled][language-url]' => '1'];
    $this->drupalGet('admin/config/regional/language/detection');
    $this->submitForm($edit, 'Save settings');

    // Set "Basic page" content type to use multilingual support.     $edit = [
      'language_configuration[language_alterable]' => TRUE,
    ];
    $this->drupalGet('admin/structure/types/manage/page');
    
'language',
    'content_translation',
  ];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Enable additional languages.     ConfigurableLanguage::createFromLangcode('de')->save();
    ConfigurableLanguage::createFromLangcode('it')->save();

    $field_storage_definition = [
      'field_name' => 'untranslatable_string_field',
      'entity_type' => 'node',
      'type' => 'string',
      'cardinality' => 1,
      'translatable' => FALSE,
    ];
    $field_storage = FieldStorageConfig::create($field_storage_definition);
    $field_storage->save();

    
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example');
    $workflow->save();

    $this->testNode = Node::create([
      'type' => 'example',
      'title' => 'Test title',
    ]);
    $this->testNode->save();
    \Drupal::entityTypeManager()->getStorage('node')->resetCache();
    $this->testNode = Node::load($this->testNode->id());

    ConfigurableLanguage::createFromLangcode('de')->save();
  }

  /** * Tests the field item list when accessing an index. */
  public function testArrayIndex() {
    $this->assertFalse($this->testNode->isPublished());
    $this->assertEquals('draft', $this->testNode->moderation_state[0]->value);
  }

  /** * Tests the field item list when iterating. */

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create some languages.     foreach (['nl', 'es'] as $langcode) {
      ConfigurableLanguage::createFromLangcode($langcode)->save();
    }

    // Create an image media type and article node type.     $this->createMediaType('image', ['id' => 'image']);
    $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);

    // Make the media translatable and ensure the change is picked up.     \Drupal::service('content_translation.manager')->setEnabled('media', 'image', TRUE);

    // Create a media reference field on articles.     $this->createEntityReferenceField(
      
'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 = [
      [
$assert_session->linkByHrefExists('node/' . $nodes['draft_page_1']->id() . '/edit');
    $assert_session->linkByHrefExists('node/' . $nodes['draft_page_2']->id() . '/edit');
    $assert_session->linkByHrefNotExists('node/' . $nodes['published_then_draft_article']->id() . '/edit');
    $assert_session->linkByHrefNotExists('node/' . $nodes['published_then_archived_article']->id() . '/edit');
    $assert_session->linkByHrefNotExists('node/' . $nodes['draft_article']->id() . '/edit');
  }

  /** * Tests the moderated content page with multilingual content. */
  public function testModeratedContentPageMultilingual() {
    ConfigurableLanguage::createFromLangcode('fr')->save();

    $node = $this->drupalCreateNode([
      'type' => 'article',
      'moderation_state' => 'published',
      'title' => 'en article published',
    ]);

    $node->title = 'en draft revision';
    $node->moderation_state = 'draft';
    $node->save();

    
'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',
      
->execute();
    }
  }

  /** * Tests deleting a base field when it has existing data. * * @dataProvider baseFieldDeleteWithExistingDataTestCases */
  public function testBaseFieldDeleteWithExistingData($entity_type_id$create_entity_revision$base_field_revisionable$create_entity_translation) {
    // Enable an additional language.     ConfigurableLanguage::createFromLangcode('ro')->save();

    /** @var \Drupal\Core\Entity\Sql\SqlEntityStorageInterface $storage */
    $storage = $this->entityTypeManager->getStorage($entity_type_id);
    $schema_handler = $this->database->schema();

    // Create an entity without the base field, to ensure NULL values are not     // added to the dedicated table storage to be purged.     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $storage->create();
    $entity->save();

    

  protected function setUp(): void {
    parent::setUp();
    $this->webUser = $this->drupalCreateUser([
      'administer entity_test content',
      'view test entity',
    ]);
    $this->drupalLogin($this->webUser);

    // Add a language.     ConfigurableLanguage::createFromLangcode('ro')->save();
  }

  /** * Tests basic form CRUD functionality. */
  public function testFormCRUD() {
    // All entity variations have to have the same results.     foreach (entity_test_entity_types() as $entity_type) {
      $this->doTestFormCRUD($entity_type);
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.