diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php index 8a1b198..fc9f93b 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php @@ -70,7 +70,7 @@ protected function doTestBasicTranslation() { $uri = $entity->uri('drupal:content-translation-overview'); $path = $langcode . '/' . $uri['path'] . '/add/' . $default_langcode . '/' . $langcode; - $this->drupalPostForm($path, $this->getEditValues($values, $langcode), $this->getFormSubmitAction($entity)); + $this->drupalPostForm($path, $this->getEditValues($values, $langcode), $this->getFormSubmitAction($entity, $langcode)); if ($this->testLanguageSelector) { $this->assertNoFieldByXPath('//select[@id="edit-langcode"]', NULL, 'Language selector correclty disabled on translations.'); } @@ -87,7 +87,7 @@ protected function doTestBasicTranslation() { // Add another translation and mark the other ones as outdated. $values[$langcode] = $this->getNewEntityValues($langcode); $edit = $this->getEditValues($values, $langcode) + array('content_translation[retranslate]' => TRUE); - $this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity)); + $this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity, $langcode)); $entity = entity_load($this->entityType, $this->entityId, TRUE); // Check that the entered values have been correctly stored. @@ -128,7 +128,7 @@ protected function doTestOutdatedStatus() { // Mark translations as outdated. $edit = array('content_translation[retranslate]' => TRUE); $uri = $entity->uri('edit-form'); - $this->drupalPostForm($langcode . '/' . $uri['path'], $edit, $this->getFormSubmitAction($entity)); + $this->drupalPostForm($langcode . '/' . $uri['path'], $edit, $this->getFormSubmitAction($entity, $langcode)); $entity = entity_load($this->entityType, $this->entityId, TRUE); // Check that every translation has the correct "outdated" status. @@ -142,7 +142,7 @@ protected function doTestOutdatedStatus() { else { $this->assertFieldByXPath('//input[@name="content_translation[outdated]"]', TRUE, 'The translate flag is checked by default.'); $edit = array('content_translation[outdated]' => FALSE); - $this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity)); + $this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity, $enabled_langcode)); $this->drupalGet($path); $this->assertFieldByXPath('//input[@name="content_translation[retranslate]"]', FALSE, 'The retranslate flag is now shown.'); $entity = entity_load($this->entityType, $this->entityId, TRUE); @@ -163,7 +163,7 @@ protected function doTestPublishedStatus() { foreach ($this->langcodes as $index => $langcode) { if ($index > 0) { $edit = array('content_translation[status]' => FALSE); - $this->drupalPostForm($langcode . '/' . $path, $edit, $this->getFormSubmitAction($entity)); + $this->drupalPostForm($langcode . '/' . $path, $edit, $this->getFormSubmitAction($entity, $langcode)); $entity = entity_load($this->entityType, $this->entityId, TRUE); $this->assertFalse($entity->translation[$langcode]['status'], 'The translation has been correctly unpublished.'); } @@ -195,7 +195,7 @@ protected function doTestAuthoringInfo() { 'content_translation[created]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'), ); $prefix = $index > 0 ? $langcode . '/' : ''; - $this->drupalPostForm($prefix . $path, $edit, $this->getFormSubmitAction($entity)); + $this->drupalPostForm($prefix . $path, $edit, $this->getFormSubmitAction($entity, $langcode)); } $entity = entity_load($this->entityType, $this->entityId, TRUE); @@ -211,7 +211,7 @@ protected function doTestAuthoringInfo() { 'content_translation[name]' => $this->randomName(12), 'content_translation[created]' => '19/11/1978', ); - $this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity)); + $this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity, $langcode)); $this->assertTrue($this->xpath('//div[contains(@class, "error")]//ul'), 'Invalid values generate a list of form errors.'); $this->assertEqual($entity->translation[$langcode]['uid'], $values[$langcode]['uid'], 'Translation author correctly kept.'); $this->assertEqual($entity->translation[$langcode]['created'], $values[$langcode]['created'], 'Translation date correctly kept.'); @@ -265,7 +265,7 @@ protected function getEditValues($values, $langcode, $new = FALSE) { * @return string * Name of the button to hit. */ - protected function getFormSubmitAction(EntityInterface $entity) { + protected function getFormSubmitAction(EntityInterface $entity, $langcode = NULL) { return t('Save'); } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php index 25cce23..ca847bb 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php @@ -90,7 +90,7 @@ protected function createEntity($values, $langcode, $bundle_name = NULL) { "{$this->fieldName}[0][value]" => $values[$this->fieldName][0]['value'], 'langcode' => $langcode, ); - $this->drupalPostForm('node/add/article', $edit,t('Save and publish')); + $this->drupalPostForm('node/add/article', $edit, t('Save and publish')); $this->drupalLogin($this->translator); $node = $this->drupalGetNodeByTitle($values['title']); return $node->id(); @@ -99,7 +99,14 @@ protected function createEntity($values, $langcode, $bundle_name = NULL) { /** * Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::getFormSubmitAction(). */ - protected function getFormSubmitAction(EntityInterface $entity) { + protected function getFormSubmitAction(EntityInterface $entity, $langcode = NULL) { + if (isset($langcode)) { + $translation = $entity->getTranslation($langcode); + if ($translation->isPublished()) { + return t('Save and unpublish'); + } + return t('Save and keep unpublished'); + } if ($entity->isPublished()) { return t('Save and unpublish'); } @@ -115,25 +122,24 @@ protected function doTestPublishedStatus() { $languages = language_list(); $actions = array( - array(t('Save and publish'), t('Save and keep published')), - array(t('Save and unpublish'), t('Save and keep unpublished')), + t('Save and publish'), + t('Save and unpublish'), ); - foreach ($actions as $index => $status_actions) { + foreach ($actions as $index => $action) { // (Un)publish the node translations and check that the translation // statuses are (un)published accordingly. foreach ($this->langcodes as $langcode) { - if (!empty($status_actions)) { - $action = array_shift($status_actions); - } $this->drupalPostForm($uri['path'], array(), $action, array('language' => $languages[$langcode])); } $entity = entity_load($this->entityType, $this->entityId, TRUE); foreach ($this->langcodes as $langcode) { - // The node is created as unpulished thus we switch to the published + // The node is created as unpublished thus we switch to the published // status first. $status = !$index; $this->assertEqual($status, $entity->translation[$langcode]['status'], 'The translation has been correctly unpublished.'); + $translation = $entity->getTranslation($langcode); + $this->assertEqual($status, $translation->isPublished(), 'The status of the translation has been correctly saved.'); } } } @@ -147,25 +153,36 @@ protected function doTestAuthoringInfo() { $languages = language_list(); $values = array(); - // Post different authoring information for each translation. + // Post different base field information for each translation. + $flip = TRUE; foreach ($this->langcodes as $langcode) { $user = $this->drupalCreateUser(); $values[$langcode] = array( 'uid' => $user->id(), 'created' => REQUEST_TIME - mt_rand(0, 1000), + 'sticky' => $flip, + 'promote' => $flip, ); $edit = array( 'name' => $user->getUsername(), 'date[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'), 'date[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'), + 'sticky' => $flip, + 'promote' => $flip, ); - $this->drupalPostForm($uri['path'], $edit, $this->getFormSubmitAction($entity), array('language' => $languages[$langcode])); + $this->drupalPostForm($uri['path'], $edit, $this->getFormSubmitAction($entity, $langcode), array('language' => $languages[$langcode])); + $flip = !$flip; } $entity = entity_load($this->entityType, $this->entityId, TRUE); foreach ($this->langcodes as $langcode) { $this->assertEqual($entity->translation[$langcode]['uid'] == $values[$langcode]['uid'], 'Translation author correctly stored.'); $this->assertEqual($entity->translation[$langcode]['created'] == $values[$langcode]['created'], 'Translation date correctly stored.'); + $translation = $entity->getTranslation($langcode); + $this->assertEqual($translation->getAuthorId() == $values[$langcode]['uid'], 'Author of translation correctly stored.'); + $this->assertEqual($translation->getCreatedTime() == $values[$langcode]['created'], 'Date of Translation correctly stored.'); + $this->assertEqual($translation->isSticky() == $values[$langcode]['sticky'], 'Sticky of Translation correctly stored.'); + $this->assertEqual($translation->isPromoted() == $values[$langcode]['promote'], 'Promoted of Translation correctly stored.'); } } @@ -230,6 +247,7 @@ function testTranslationRendering() { $default_langcode = $this->langcodes[0]; $values[$default_langcode] = $this->getNewEntityValues($default_langcode); $this->entityId = $this->createEntity($values[$default_langcode], $default_langcode); + /** @var \Drupal\node\Entity\Node $node */ $node = \Drupal::entityManager()->getStorageController($this->entityType)->load($this->entityId); $node->setPromoted(TRUE); @@ -237,7 +255,10 @@ function testTranslationRendering() { foreach (array_diff($this->langcodes, array($default_langcode)) as $langcode) { $values[$langcode] = $this->getNewEntityValues($langcode); $translation = $node->addTranslation($langcode, $values[$langcode]); + // Promoted and Published is translatable so it needs to be set for the + // translation too. $translation->setPromoted(TRUE); + $translation->setPublished(TRUE); } $node->save(); @@ -251,7 +272,7 @@ function testTranslationRendering() { } /** - * Tests that the given path dsiplays the correct translation values. + * Tests that the given path displays the correct translation values. * * @param string $path * The path to be tested.