public function ContentModerationIntegration::testTranslationModerationFieldViews in Translation Views 8
Test view's field "Translation Moderation State".
File
- tests/
src/ Functional/ ContentModerationIntegration.php, line 75
Class
- ContentModerationIntegration
- Class ContentModerationIntegration.
Namespace
Drupal\Tests\translation_views\FunctionalCode
public function testTranslationModerationFieldViews() {
// Login as a root user.
$this
->drupalLogin($this->rootUser);
// Create node for test.
$node = $this
->createNode([
'type' => 'article',
]);
// Create translations
foreach (self::$langcodes as $langcode) {
$node
->addTranslation($langcode, [
'title' => $this
->randomMachineName(),
'status' => 0,
'moderation_state[0][state]' => 'draft',
])
->save();
}
// Ensure we have moderation state "Draft" by default
// in the newly created node.
$this
->assertTrue($node
->hasField('moderation_state'));
$this
->assertFalse($node
->get('moderation_state')
->isEmpty());
$this
->assertEquals('draft', $node
->get('moderation_state')
->first()
->getString());
// Check that created node has "Draft" moderation state in English.
$this
->drupalGet('/content-moderation-integration-test', [
'query' => [
'translation_target_language' => 'en',
],
]);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->elementTextContains('css', 'table > tbody > tr:nth-child(1) .views-field-translation-moderation-state', 'Draft');
// Check that created node has "Draft" moderation state in German.
$this
->drupalGet('/content-moderation-integration-test', [
'query' => [
'translation_target_language' => 'de',
],
]);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->elementTextContains('css', 'table > tbody > tr:nth-child(1) .views-field-translation-moderation-state', 'Draft');
// Change moderation state to "Published".
$node
->set('moderation_state', 'published')
->save();
// Check that created node has "Published" moderation state in English.
$this
->drupalGet('/content-moderation-integration-test', [
'query' => [
'translation_target_language' => 'en',
],
]);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->elementTextContains('css', 'table > tbody > tr:nth-child(1) .views-field-translation-moderation-state', 'Published');
}