diff -u b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php --- b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php +++ b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php @@ -56,7 +56,7 @@ $admin_user = $this->drupalCreateUser($permissions); $this->drupalLogin($admin_user); - // Add a second and third language. + // Add a second, third and fourth language. $edit = array(); $edit['predefined_langcode'] = 'fr'; $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); @@ -65,6 +65,10 @@ $edit['predefined_langcode'] = 'nl'; $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + $edit = array(); + $edit['predefined_langcode'] = 'it'; + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + // Enable translation for "Basic page" nodes. $edit = array( 'entity_types[node]' => 1, @@ -150,6 +154,35 @@ $file = File::load($third_fid); $this->assertTrue($file->isPermanent()); + // Languages are cached on many levels, and we need to clear those caches. + $this->rebuildContainer(); + + // Translate the node into Italian: remove the existing file. + $this->drupalPostForm('node/' . $default_language_node->id() . '/translations/add/en/it', array(), t('Remove')); + + // Upload a different file. + $edit = array(); + $edit['title[0][value]'] = 'David Bowie'; + $name = 'files[' . $this->fieldName . '_0]'; + $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[3]->uri); + $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); + $fourth_fid = $this->getLastFileId(); + + // Ensure the first file still exists. Calling isPermanent() would crash + // the test suite. + $file = File::load($first_fid); + $this->assertTrue(!empty($file) && $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 third file is permanent. + $file = File::load($third_fid); + $this->assertTrue($file->isPermanent()); + + // Ensure the file status of the fourth file is permanent. + $file = File::load($fourth_fid); + $this->assertTrue($file->isPermanent()); } }