function TaxonomyTermParentMultilingualTest::testMultilingualTermParentUpdate

Tests taxonomy multilingual term parents update.

See also

taxonomy_update_8501()

taxonomy_update_8502()

taxonomy_update_8503()

taxonomy_update_8702()

File

core/modules/taxonomy/tests/src/Functional/Update/TaxonomyTermParentMultilingualTest.php, line 36

Class

TaxonomyTermParentMultilingualTest
Tests the upgrade path for taxonomy parents with multilingual terms.

Namespace

Drupal\Tests\taxonomy\Functional\Update

Code

public function testMultilingualTermParentUpdate() {
    // There are 65 terms in the database. Process them in groups of 30 to test
    // batching.
    $settings['entity_update_batch_size'] = (object) [
        'value' => 30,
        'required' => TRUE,
    ];
    $this->writeSettings($settings);
    $this->runUpdates();
    $term = Term::load(65);
    $this->assertSame('64', $term->parent[0]->target_id);
    // Term 2 should have the root parent.
    $term = Term::load(2);
    $this->assertSame('0', $term->parent[0]->target_id);
    // Log in as user 1.
    $account = User::load(1);
    $account->passRaw = 'drupal';
    $this->drupalLogin($account);
    // Make sure our vocabulary exists.
    $this->drupalGet('admin/structure/taxonomy/manage/test_vocabulary/overview');
    // Make sure our terms exist.
    $assert_session = $this->assertSession();
    $assert_session->pageTextContains('Test root term');
    $assert_session->pageTextContains('Test child term');
    // Make sure the terms are still translated.
    $this->drupalGet('taxonomy/term/2/translations');
    $assert_session->linkExists('Test root term - Spanish');
    $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
    // Check that the 'content_translation_status' field has been updated
    // correctly.
    
    /** @var \Drupal\taxonomy\TermInterface $term */
    $term = $storage->load(2);
    $translation = $term->getTranslation('es');
    $this->assertTrue($translation->isPublished());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.