View source
<?php
namespace Drupal\Tests\lingotek\Functional\Form;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Lingotek;
use Drupal\Tests\lingotek\Functional\LingotekTestBase;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
class LingotekSettingsTabParagraphsIntegrationFormTest extends LingotekTestBase {
use TaxonomyTestTrait;
protected $vocabulary;
public static $modules = [
'block',
'node',
'image',
'paragraphs',
'lingotek_paragraphs_test',
'taxonomy',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'content',
'weight' => -5,
]);
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'content',
'weight' => -10,
]);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this->vocabulary = $this
->createVocabulary();
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $this->vocabulary
->id())
->setLanguageAlterable(TRUE)
->save();
ContentLanguageSettings::loadByEntityTypeBundle('paragraph', 'image_text')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
\Drupal::service('content_translation.manager')
->setEnabled('paragraph', 'image_text', TRUE);
\Drupal::service('content_translation.manager')
->setEnabled('taxonomy_term', $this->vocabulary
->id(), TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$this
->saveLingotekContentTranslationSettings([
'node' => [
'article' => [
'profiles' => 'automatic',
'fields' => [
'title' => 1,
'body' => 1,
],
],
],
'paragraph' => [
'image_text' => [
'fields' => [
'field_image_demo' => [
'title',
'alt',
],
'field_text_demo' => 1,
],
],
],
]);
$this
->drupalLogin($this->rootUser);
}
public function testTabShownIfThereAreSettings() {
$this
->drupalGet('admin/lingotek/settings');
$this
->assertText('Integrations Settings');
$this
->assertText('Paragraphs');
$this
->assertText('Enable paragraphs to be managed individually instead of embedded in their parent entity.');
}
public function testBulkTabNotShownIfNotActive() {
$assert_session = $this
->assertSession();
$this
->goToContentBulkManagementForm();
$assert_session
->linkNotExists('Paragraph');
}
public function testBulkTabCanBeActivated() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/lingotek/settings');
$edit = [
'contrib[paragraphs][enable_bulk_management]' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Save settings', [], 'lingoteksettings-integrations-form');
$this
->assertText('The configuration options have been saved.');
$this
->goToContentBulkManagementForm();
$assert_session
->linkExists('Paragraph');
$this
->clickLink('Paragraph');
$this
->assertText('Manage Translations');
$this
->assertText('No content available');
}
public function testBulkTabCanBeDeactivated() {
$assert_session = $this
->assertSession();
$this
->testBulkTabCanBeActivated();
$this
->drupalGet('admin/lingotek/settings');
$edit = [
'contrib[paragraphs][enable_bulk_management]' => FALSE,
];
$this
->drupalPostForm(NULL, $edit, 'Save settings', [], 'lingoteksettings-integrations-form');
$this
->assertText('The configuration options have been saved.');
$this
->goToContentBulkManagementForm();
$assert_session
->linkNotExists('Paragraph');
}
public function testOtherBulkTabsAreShownAfterDeactivating() {
$assert_session = $this
->assertSession();
$this
->testBulkTabCanBeDeactivated();
$bundle = $this->vocabulary
->id();
$this
->saveLingotekContentTranslationSettings([
'taxonomy_term' => [
$bundle => [
'profiles' => 'automatic',
'fields' => [
'name' => 1,
'description' => 1,
],
],
],
]);
$this
->goToContentBulkManagementForm();
$assert_session
->statusCodeEquals(200);
$assert_session
->linkExists('Content');
$assert_session
->linkNotExists('Paragraph');
$assert_session
->linkExists('Taxonomy term');
$this
->goToContentBulkManagementForm('taxonomy_term');
$assert_session
->statusCodeEquals(200);
$assert_session
->linkExists('Content');
$assert_session
->linkNotExists('Paragraph');
$assert_session
->linkExists('Taxonomy term');
}
public function testParagraphsProfileIsNotSelectableUnlessExplicit() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/lingotek/settings');
$this
->assertNoFieldByName('paragraph[image_text][profiles]', NULL, 'The profile is not selectable for paragraphs by default.');
$edit = [
'contrib[paragraphs][enable_bulk_management]' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Save settings', [], 'lingoteksettings-integrations-form');
$this
->assertText('The configuration options have been saved.');
$this
->assertFieldByName('paragraph[image_text][profiles]', NULL, 'The profile can be assigned to a paragraph if they are managed individually.');
$this
->assertFieldByName('paragraph[image_text][profiles]', Lingotek::PROFILE_DISABLED, 'The default profile is disabled for paragraphs if they are managed individually.');
}
}