function ModerationLocaleTest::testTranslationRevisionsHistory

Same name in other branches
  1. 11.x core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php \Drupal\Tests\content_moderation\Functional\ModerationLocaleTest::testTranslationRevisionsHistory()

Tests article revision history shows revisions for the correct translation.

File

core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php, line 453

Class

ModerationLocaleTest
Test content_moderation functionality with localization and translation.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function testTranslationRevisionsHistory() : void {
    // Create a published article in English.
    $edit = [
        'title[0][value]' => 'English node',
        'langcode[0][value]' => 'en',
        'moderation_state[0][state]' => 'published',
        'revision_log[0][value]' => 'Log Message - English - Published - Edit 1',
    ];
    $this->drupalGet('node/add/article');
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->pageTextContains('Article English node has been created.');
    $node = $this->drupalGetNodeByTitle('English node');
    // Add a French translation.
    $this->drupalGet('node/' . $node->id() . '/translations');
    $this->clickLink('Add');
    $edit = [
        'title[0][value]' => 'French node',
        'moderation_state[0][state]' => 'draft',
        'revision_log[0][value]' => 'Log Message - French - Draft - Edit 1',
    ];
    $this->submitForm($edit, 'Save (this translation)');
    // Here the error has occurred "The website encountered an unexpected error.
    // Try again later."
    // If the translation has got lost.
    $this->assertSession()
        ->pageTextContains('Article French node has been updated.');
    $french_node = $this->loadTranslation($node, 'fr');
    $this->assertEquals('published', $node->moderation_state->value);
    $this->assertTrue($node->isPublished());
    $this->assertEquals('draft', $french_node->moderation_state->value);
    $this->assertFalse($french_node->isPublished());
    // Verify the revisions history for the English node.
    $this->drupalGet('node/' . $node->id() . '/revisions');
    $this->assertSession()
        ->pageTextContains('Log Message - English - Published - Edit 1');
    $this->assertSession()
        ->pageTextNotContains('Log Message - French');
    // Verify the revisions history for the French node.
    $this->drupalGet($french_node->language()
        ->getId() . '/node/' . $node->id() . '/revisions');
    $this->assertSession()
        ->pageTextContains('Log Message - French - Draft - Edit 1');
    $this->assertSession()
        ->pageTextNotContains('Log Message - English');
    // Create a new draft for the English article.
    $edit = [
        'moderation_state[0][state]' => 'draft',
        'revision_log[0][value]' => 'Log Message - English - Draft - Edit 2',
    ];
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->pageTextContains('Article English node has been updated.');
    // Create a new draft for the French article.
    $edit = [
        'moderation_state[0][state]' => 'draft',
        'revision_log[0][value]' => 'Log Message - French - Draft - Edit 2',
    ];
    $this->drupalGet($french_node->language()
        ->getId() . '/node/' . $node->id() . '/edit');
    $this->submitForm($edit, 'Save (this translation)');
    $this->assertSession()
        ->pageTextContains('Article French node has been updated.');
    // Verify the revisions history for the English node.
    $this->drupalGet('node/' . $node->id() . '/revisions');
    $this->assertSession()
        ->pageTextContains('Log Message - English - Published - Edit 1');
    $this->assertSession()
        ->pageTextContains('Log Message - English - Draft - Edit 2');
    $this->assertSession()
        ->pageTextNotContains('Log Message - French');
    // Verify the revisions history for the French node.
    $this->drupalGet($french_node->language()
        ->getId() . '/node/' . $node->id() . '/revisions');
    $this->assertSession()
        ->pageTextContains('Log Message - French - Draft - Edit 1');
    $this->assertSession()
        ->pageTextContains('Log Message - French - Draft - Edit 2');
    $this->assertSession()
        ->pageTextNotContains('Log Message - English');
    // Publish the French Node.
    $edit = [
        'moderation_state[0][state]' => 'published',
        'revision_log[0][value]' => 'Log Message - French - Published - Edit 3',
    ];
    $this->drupalGet($french_node->language()
        ->getId() . '/node/' . $node->id() . '/edit');
    $this->submitForm($edit, 'Save (this translation)');
    $this->assertSession()
        ->pageTextContains('Article French node has been updated.');
    // Verify the revisions history for the English node.
    $this->drupalGet('node/' . $node->id() . '/revisions');
    $this->assertSession()
        ->pageTextContains('Log Message - English - Published - Edit 1');
    $this->assertSession()
        ->pageTextContains('Log Message - English - Draft - Edit 2');
    $this->assertSession()
        ->pageTextNotContains('Log Message - French');
    // Verify the revisions history for the French node.
    $this->drupalGet($french_node->language()
        ->getId() . '/node/' . $node->id() . '/revisions');
    $this->assertSession()
        ->pageTextContains('Log Message - French - Draft - Edit 1');
    $this->assertSession()
        ->pageTextContains('Log Message - French - Draft - Edit 2');
    $this->assertSession()
        ->pageTextContains('Log Message - French - Published - Edit 3');
    $this->assertSession()
        ->pageTextNotContains('Log Message - English');
}

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