public function LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable in Lingotek Translation 3.2.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable()
- 4.0.x tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable()
- 3.0.x tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable()
- 3.1.x tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable()
- 3.3.x tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable()
- 3.4.x tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable()
- 3.5.x tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable()
- 3.6.x tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable()
- 3.7.x tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable()
- 3.8.x tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabContentFormTest::testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable()
Test that if we disable content translation for an entity or an entity field, they are disabled for Lingotek.
Throws
\Exception
File
- tests/
src/ Functional/ Form/ LingotekSettingsTabContentFormTest.php, line 312
Class
- LingotekSettingsTabContentFormTest
- Tests the Lingotek content settings form.
Namespace
Drupal\Tests\lingotek\Functional\FormCode
public function testFieldsAreDisabledInLingotekIfFieldsAreMarkedAsNotTranslatable() {
// Enable translation for the current entity type and ensure the change is
// picked up.
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
// Rebuild the container so that the new languages are picked up by services
// that hold a list of languages.
$this
->rebuildContainer();
$this
->applyEntityUpdates();
// Check the form contains the article type and only its text-based fields.
$this
->drupalGet('admin/lingotek/settings');
// Check the title and body fields.
$edit = [
'node[article][enabled]' => 1,
'node[article][profiles]' => 'automatic',
'node[article][fields][title]' => 1,
'node[article][fields][body]' => 1,
'node[article][fields][field_image]' => 1,
'node[article][fields][field_image:properties][alt]' => 'alt',
];
$this
->drupalPostForm(NULL, $edit, 'Save', [], 'lingoteksettings-tab-content-form');
// Assert that body translation is enabled.
$this
->assertFieldChecked('edit-node-article-fields-title', 'The title field is enabled after enabled for Lingotek translation');
$this
->assertFieldChecked('edit-node-article-fields-body', 'The body field is enabled after enabled for Lingotek translation');
$this
->assertFieldChecked('edit-node-article-fields-field-image', 'The image field is enabled after enabled for Lingotek translation');
$this
->assertFieldChecked('edit-node-article-fields-field-imageproperties-alt', 'The image alt property is enabled after enabled for Lingotek translation');
// Go to the content language settings, and disable the body field.
// It should result that the field is disabled in Lingotek too.
$edit = [
'entity_types[node]' => TRUE,
'settings[node][article][settings][language][language_alterable]' => TRUE,
'settings[node][article][translatable]' => TRUE,
'settings[node][article][fields][title]' => TRUE,
'settings[node][article][fields][body]' => FALSE,
'settings[node][article][fields][field_image]' => FALSE,
];
$this
->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
// Get the form and check the fields are not available, because they cannot be translated.
$this
->drupalGet('admin/lingotek/settings');
$this
->assertFieldChecked('edit-node-article-fields-title', 'The title field is enabled after other fields were disabled for content translation');
$this
->assertNoFieldById('edit-node-article-fields-body', 'The body field is not present after disabled for content translation');
$this
->assertNoFieldById('edit-node-article-fields-field-image', 'The image field is not present after disabled for content translation');
$this
->assertNoFieldById('edit-node-article-fields-field-imageproperties-alt', 'The image alt property is not present after image was disabled for content translation');
// But also check that the fields are not enabled.
/** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
$lingotek_config = \Drupal::service('lingotek.configuration');
$this
->assertFalse($lingotek_config
->isFieldLingotekEnabled('node', 'article', 'body'), 'The body field is disabled after being disabled for content translation');
$this
->assertFalse($lingotek_config
->isFieldLingotekEnabled('node', 'article', 'image'), 'The image field is disabled after being disabled for content translation');
// And if we disable the entity itself, it should not be enabled anymore.
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', FALSE);
$this
->assertFalse($lingotek_config
->isEnabled('node', 'article'), 'The article entity is disabled after being disabled for content translation');
$this
->assertFalse($lingotek_config
->isFieldLingotekEnabled('node', 'article', 'title'), 'The title field is disabled after the entity being disabled for content translation');
}