public function NodeTranslationUITest::testPublishedStatusNoFields in Drupal 9
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testPublishedStatusNoFields()
Tests changing the published status on a node without fields.
File
- core/
modules/ node/ tests/ src/ Functional/ NodeTranslationUITest.php, line 91
Class
- NodeTranslationUITest
- Tests the Node Translation UI.
Namespace
Drupal\Tests\node\FunctionalCode
public function testPublishedStatusNoFields() {
// Test changing the published status of an article without fields.
$this
->drupalLogin($this->administrator);
// Delete all fields.
$this
->drupalGet('admin/structure/types/manage/article/fields');
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete');
$this
->submitForm([], 'Delete');
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.field_tags/delete');
$this
->submitForm([], 'Delete');
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.field_image/delete');
$this
->submitForm([], 'Delete');
// Add a node.
$default_langcode = $this->langcodes[0];
$values[$default_langcode] = [
'title' => [
[
'value' => $this
->randomMachineName(),
],
],
];
$this->entityId = $this
->createEntity($values[$default_langcode], $default_langcode);
$storage = $this->container
->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage
->resetCache([
$this->entityId,
]);
$entity = $storage
->load($this->entityId);
// Add a content translation.
$langcode = 'fr';
$language = ConfigurableLanguage::load($langcode);
$values[$langcode] = [
'title' => [
[
'value' => $this
->randomMachineName(),
],
],
];
$entity_type_id = $entity
->getEntityTypeId();
$add_url = Url::fromRoute("entity.{$entity_type_id}.content_translation_add", [
$entity
->getEntityTypeId() => $entity
->id(),
'source' => $default_langcode,
'target' => $langcode,
], [
'language' => $language,
]);
$edit = $this
->getEditValues($values, $langcode);
$edit['status[value]'] = FALSE;
$this
->drupalGet($add_url);
$this
->submitForm($edit, 'Save (this translation)');
$storage
->resetCache([
$this->entityId,
]);
$entity = $storage
->load($this->entityId);
$translation = $entity
->getTranslation($langcode);
// Make sure we unpublished the node correctly.
$this
->assertFalse($this->manager
->getTranslationMetadata($translation)
->isPublished(), 'The translation has been correctly unpublished.');
}