View source
<?php
namespace Drupal\Tests\translation_views\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\workflows\Entity\Workflow;
class ContentModerationIntegration extends ViewTestBase {
private static $langcodes = [
'fr',
'de',
];
protected $profile = 'standard';
public static $modules = [
'translation_views_test_views',
];
public static $testViews = [
'content_moderation_integration_test',
];
public function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->drupalLogin($this->rootUser);
ViewTestData::createTestViews(get_class($this), [
'translation_views_test_views',
]);
foreach (self::$langcodes as $langcode) {
ConfigurableLanguage::createFromLangcode($langcode)
->save();
}
$this
->drupalPostForm('admin/config/regional/content-language', [
"entity_types[node]" => 1,
"settings[node][article][translatable]" => 1,
"settings[node][article][settings][language][language_alterable]" => 1,
], 'Save configuration');
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$workflow = Workflow::load('editorial');
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'article');
$workflow
->save();
$this
->drupalLogout();
}
public function testTranslationModerationFieldViews() {
$this
->drupalLogin($this->rootUser);
$node = $this
->createNode([
'type' => 'article',
]);
foreach (self::$langcodes as $langcode) {
$node
->addTranslation($langcode, [
'title' => $this
->randomMachineName(),
'status' => 0,
'moderation_state[0][state]' => 'draft',
])
->save();
}
$this
->assertTrue($node
->hasField('moderation_state'));
$this
->assertFalse($node
->get('moderation_state')
->isEmpty());
$this
->assertEquals('draft', $node
->get('moderation_state')
->first()
->getString());
$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');
$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');
$node
->set('moderation_state', 'published')
->save();
$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');
}
public function testTranslationOperations() {
$node = $this
->createNode([
'type' => 'article',
]);
foreach (self::$langcodes as $langcode) {
$node
->addTranslation($langcode, [
'title' => $this
->randomMachineName(),
'status' => 0,
'moderation_state[0][state]' => 'draft',
])
->save();
}
$this
->assertTrue($node
->hasField('moderation_state'));
$this
->assertFalse($node
->get('moderation_state')
->isEmpty());
$this
->assertEquals('draft', $node
->get('moderation_state')
->first()
->getString());
$translator = $this
->createUser([
'translate article node',
'update content translations',
]);
$this
->drupalLogin($translator);
$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-operations ul li a', 'Edit');
}
}