diff --git a/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php index 9f98b5c..012bb39 100644 --- a/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php +++ b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php @@ -217,6 +217,54 @@ public function testSyncedFilesWithRevisions() { $file = File::load($third_fid); $this->assertTrue($file->isPermanent(), 'Third file still exists and is permanent.'); + // Delete the third translation. As the Dutch translation is the latest + // revision this will cause the Dutch file to be deleted. + $this->drupalPostForm('nl/node/' . $default_language_node->id() . '/delete', array(), t('Delete Dutch translation')); + \Drupal::entityTypeManager()->getStorage('file')->resetCache(); + + // Ensure the first file is untouched. + $file = File::load($first_fid); + $this->assertTrue($file->isPermanent(), 'First file still exists and is permanent.'); + // This inspects the HTML after the post of the translation, the file + // should be displayed on the original node. + $this->assertRaw('file--mime-text-plain'); + + // Ensure the file status of the second file is permanent. + $file = File::load($second_fid); + $this->assertTrue($file->isPermanent(), 'Second file still exists and is permanent.'); + + // Ensure the file status of the third file is permanent. + $file = File::load($third_fid); + $this->assertTrue($file->isTemporary(), 'Third file still exists and is temporary.'); + + // Re-translate the node into dutch: remove the existing file. + $this->drupalPostForm('node/' . $default_language_node->id() . '/translations/add/en/nl', array(), t('Remove')); + + // Upload a different file. + $edit = array(); + $edit['title[0][value]'] = 'Scarlett Johansson'; + $name = 'files[' . $this->fieldName . '_0]'; + $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[2]->uri); + $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); + $third_fid = $this->getLastFileId(); + + \Drupal::entityTypeManager()->getStorage('file')->resetCache(); + + // Ensure the first file is untouched. + $file = File::load($first_fid); + $this->assertTrue($file->isPermanent(), 'First file still exists and is permanent.'); + // This inspects the HTML after the post of the translation, the file + // should be displayed on the original node. + $this->assertRaw('file--mime-text-plain'); + + // Ensure the file status of the second file is permanent. + $file = File::load($second_fid); + $this->assertTrue($file->isPermanent(), 'Second file still exists and is permanent.'); + + // Ensure the file status of the third file is permanent. + $file = File::load($third_fid); + $this->assertTrue($file->isPermanent(), 'Third file still exists and is permanent.'); + // Edit the second translation: remove the existing file. $this->drupalPostForm('fr/node/' . $default_language_node->id() . '/edit', array(), t('Remove'));