View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
class LingotekContentModerationSettingsTest extends LingotekTestBase {
use TaxonomyTestTrait;
use ContentModerationTestTrait;
public static $modules = [
'node',
'taxonomy',
'content_moderation',
];
protected $vocabulary;
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Page',
]);
$this->vocabulary = $this
->createVocabulary();
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'page', TRUE);
ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $this->vocabulary
->id())
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('taxonomy_term', $this->vocabulary
->id(), TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$workflow = $this
->createEditorialWorkflow();
}
public function testContentModerationStateEntityNotAvailableForLingotek() {
$assert_session = $this
->assertSession();
ContentLanguageSettings::loadByEntityTypeBundle('content_moderation_state', 'content_moderation_state')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('content_moderation_state', 'content_moderation_state', TRUE);
$this
->drupalGet('admin/lingotek/settings');
$this
->assertNoField('content_moderation_state[content_moderation_state][enabled]', 'The content moderation state entity should not be available for Lingotek translation.');
$this
->enableModerationThroughUI('article', [
'draft',
'needs_review',
'published',
], 'draft');
$this
->saveLingotekContentTranslationSettingsForNodeTypes();
$this
->drupalGet('admin/lingotek/settings');
$this
->assertNoField('content_moderation_state[content_moderation_state][enabled]', 'The content moderation state entity should not be available for Lingotek translation.');
}
public function testContentModerationSettings() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/lingotek/settings');
$this
->assertNoField('node[article][moderation][upload_status]', 'The field for setting the state when a content should be uploaded does not exist as content moderation is not enabled for this bundle.');
$this
->assertNoField('node[article][moderation][download_transition]', 'The field for setting the transition that must happen after download does not exist as content moderation is not enabled for this bundle.');
$this
->assertNoField('node[page][moderation][upload_status]', 'The field for setting the state when a content should be uploaded does not exist as content moderation is not enabled for this bundle.');
$this
->assertNoField('node[page][moderation][download_transition]', 'The field for setting the transition that must happen after download does not exist as content moderation is not enabled for this bundle.');
$this
->assertText('This entity bundle is not enabled for moderation with content_moderation. You can change its settings here.');
$assert_session
->linkByHrefExists('/admin/config/workflow/workflows', 0);
$assert_session
->linkByHrefExists('/admin/config/workflow/workflows', 1);
$this
->enableModerationThroughUI('article', [
'draft',
'needs_review',
'published',
], 'draft');
$this
->drupalGet('admin/lingotek/settings');
$this
->assertField('node[article][moderation][upload_status]', 'The field for setting the state when a content should be uploaded exists.');
$this
->assertField('node[article][moderation][download_transition]', 'The field for setting the transition that must happen after download exists.');
$assert_session
->optionExists('edit-node-article-moderation-upload-status', 'published');
$assert_session
->optionExists('edit-node-article-moderation-download-transition', 'publish');
$this
->assertNoField('node[page][moderation][upload_status]', 'The field for setting the state when a content should be uploaded does not exist as content moderation is not enabled for this bundle.');
$this
->assertNoField('node[page][moderation][download_transition]', 'The field for setting the transition that must happen after download does not exist as content moderation is not enabled for this bundle.');
$this
->assertText('This entity bundle is not enabled for moderation with content_moderation. You can change its settings here.');
$assert_session
->linkByHrefExists('/admin/config/workflow/workflows', 0);
$this
->saveLingotekContentTranslationSettings([
'node' => [
'article' => [
'profiles' => 'automatic',
'fields' => [
'title' => 1,
],
'moderation' => [
'upload_status' => 'draft',
'download_transition' => 'archive',
],
],
],
]);
$assert_session
->optionExists('edit-node-article-moderation-upload-status', 'draft');
$assert_session
->optionExists('edit-node-article-moderation-download-transition', 'archive');
$this
->assertNoField("taxonomy_term[{$this->vocabulary->id()}][moderation][upload_status]", 'The field for setting the state when a content should be uploaded does not exist as content moderation is not available for this entity type.');
$this
->assertNoField("taxonomy_term[{$this->vocabulary->id()}][moderation][download_transition]", 'The field for setting the transition that must happen after download does not exist as content moderation is not available for this entity type.');
$assert_session
->linkByHrefNotExists("/admin/structure/taxonomy/manage/{$this->vocabulary->id()}/moderation", 'There is no link to moderation settings in taxonomies as they cannot be moderated.');
$header = $this
->xpath("//details[@id='edit-entity-node']//th[text()='Content moderation']");
$this
->assertEqual(count($header), 1, 'There is a content moderation column for content.');
$header = $this
->xpath("//details[@id='edit-entity-taxonomy-term']//th[text()='Content moderation']");
$this
->assertEqual(count($header), 0, 'There is no content moderation column for taxonomies.');
}
protected function enableModerationThroughUI($content_type_id) {
$this
->drupalGet('/admin/config/workflow/workflows/manage/editorial/type/node');
$this
->assertFieldByName("bundles[{$content_type_id}]");
$edit["bundles[{$content_type_id}]"] = TRUE;
$this
->drupalPostForm(NULL, $edit, t('Save'));
}
}