public function NodeTranslationUITest::testPublishedStatusNoFields in Drupal 8
Same name and namespace in other branches
- 9 core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testPublishedStatusNoFields()
- 10 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 92
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
->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete', [], t('Delete'));
$this
->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_tags/delete', [], t('Delete'));
$this
->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image/delete', [], t('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
->drupalPostForm($add_url, $edit, t('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.');
}