From a227db18335610af96273e8711bd3df5709a411b Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Fri, 6 Aug 2021 08:54:08 +0100
Subject: [PATCH] Issue #3021833 by pavnish, andypost, munish.kumar,
 kim.pepper, googletorp, swatichouhan012, daffie, Berdir, alexpott, xjm: Move
 FILE_STATUS_PERMANENT to \Drupal\file\FileInterface

---
 core/includes/file.inc                                |  6 ++++++
 core/lib/Drupal/Core/Entity/entity.api.php            |  2 +-
 .../Functional/ContentTranslationSyncImageTest.php    |  2 +-
 core/modules/editor/editor.module                     |  3 +--
 core/modules/file/file.module                         |  6 +++---
 core/modules/file/src/Entity/File.php                 |  4 ++--
 core/modules/file/src/FileInterface.php               |  9 +++++++++
 core/modules/file/src/FileStorage.php                 |  2 +-
 core/modules/file/src/FileStorageInterface.php        |  4 ++--
 .../Plugin/EntityReferenceSelection/FileSelection.php |  3 ++-
 .../file/tests/src/Functional/FileListingTest.php     |  2 +-
 .../src/Functional/Rest/FileResourceTestBase.php      |  2 +-
 core/modules/file/tests/src/Kernel/AccessTest.php     |  2 +-
 .../file/tests/src/Kernel/FileManagedAccessTest.php   |  5 +++--
 .../modules/file/tests/src/Kernel/FileUriItemTest.php |  2 +-
 .../tests/src/Kernel/Migrate/d6/MigrateUploadTest.php |  2 +-
 core/modules/file/tests/src/Kernel/SaveTest.php       |  6 +++---
 core/modules/file/tests/src/Kernel/SpaceUsedTest.php  | 11 ++++++-----
 .../src/Kernel/Views/RelationshipUserFileDataTest.php |  3 +--
 .../hal/tests/src/Kernel/FileNormalizeTest.php        |  2 +-
 core/modules/image/image.module                       |  4 ++--
 .../src/FunctionalJavascript/QuickEditImageTest.php   |  2 +-
 .../Kernel/Views/RelationshipUserImageDataTest.php    |  2 +-
 .../modules/jsonapi/tests/src/Functional/FileTest.php |  3 ++-
 .../InlineBlockPrivateFilesTest.php                   |  2 +-
 .../locale/tests/src/Functional/LocaleUpdateBase.php  |  2 +-
 .../tests/src/Kernel/Migrate/d6/MigrateUserTest.php   |  4 ++--
 .../src/Functional/Plugin/NumericFormatPluralTest.php |  2 +-
 28 files changed, 58 insertions(+), 41 deletions(-)

diff --git a/core/includes/file.inc b/core/includes/file.inc
index 44a3cc3343cf..c0be1e0253f4 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -21,6 +21,12 @@
  * configuration value will be, if clean-up not disabled, removed during cron
  * runs, but permanent files will not be removed during the file garbage
  * collection process.
+ *
+ * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use
+ *   \Drupal\file\FileInterface::STATUS_PERMANENT or
+ *   \Drupal\file\FileInterface::setPermanent() instead.
+ *
+ * @see https://www.drupal.org/node/3022147
  */
 const FILE_STATUS_PERMANENT = 1;
 
diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php
index f31561d70c5d..2114addd13e4 100644
--- a/core/lib/Drupal/Core/Entity/entity.api.php
+++ b/core/lib/Drupal/Core/Entity/entity.api.php
@@ -567,7 +567,7 @@
  * Here is an example, using the core File entity:
  * @code
  * $fids = Drupal::entityQuery('file')
- *   ->condition('status', FILE_STATUS_PERMANENT, '<>')
+ *   ->condition('status', \Drupal\file\FileInterface::STATUS_PERMANENT, '<>')
  *   ->condition('changed', REQUEST_TIME - $age, '<')
  *   ->range(0, 100)
  *   ->execute();
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php
index c4d9439b7789..4ff54ff0430d 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php
@@ -152,9 +152,9 @@ public function testImageFieldSync() {
       $field_values = [
         'uri' => $this->files[$index]->uri,
         'uid' => \Drupal::currentUser()->id(),
-        'status' => FILE_STATUS_PERMANENT,
       ];
       $file = File::create($field_values);
+      $file->setPermanent();
       $file->save();
       $fid = $file->id();
       $this->files[$index]->fid = $fid;
diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module
index 2dd2ed976028..3031931afec2 100644
--- a/core/modules/editor/editor.module
+++ b/core/modules/editor/editor.module
@@ -444,8 +444,7 @@ function editor_entity_revision_delete(EntityInterface $entity) {
 /**
  * Records file usage of files referenced by formatted text fields.
  *
- * Every referenced file that does not yet have the FILE_STATUS_PERMANENT state,
- * will be given that state.
+ * Every referenced file that is temporally saved will be resaved as permanent.
  *
  * @param array $uuids
  *   An array of file entity UUIDs.
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 33a57d9ba935..f7bdcb409dc2 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -560,8 +560,8 @@ function file_save_data($data, $destination = NULL, $replace = FileSystemInterfa
     $file = File::create([
       'uri' => $uri,
       'uid' => $user->id(),
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     // If we are replacing an existing file re-use its database record.
     // @todo Do not create a new entity in order to update it. See
     //   https://www.drupal.org/node/2241865.
@@ -709,7 +709,7 @@ function file_cron() {
   if ($age) {
     $fids = Drupal::entityQuery('file')
       ->accessCheck(FALSE)
-      ->condition('status', FILE_STATUS_PERMANENT, '<>')
+      ->condition('status', FileInterface::STATUS_PERMANENT, '<>')
       ->condition('changed', REQUEST_TIME - $age, '<')
       ->range(0, 100)
       ->execute();
@@ -1782,7 +1782,7 @@ function file_get_file_references(FileInterface $file, FieldDefinitionInterface
 function _views_file_status($choice = NULL) {
   $status = [
     0 => t('Temporary'),
-    FILE_STATUS_PERMANENT => t('Permanent'),
+    FileInterface::STATUS_PERMANENT => t('Permanent'),
   ];
 
   if (isset($choice)) {
diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php
index e6e19a15dd12..57276f495e86 100644
--- a/core/modules/file/src/Entity/File.php
+++ b/core/modules/file/src/Entity/File.php
@@ -124,7 +124,7 @@ public function getCreatedTime() {
    * {@inheritdoc}
    */
   public function isPermanent() {
-    return $this->get('status')->value == FILE_STATUS_PERMANENT;
+    return $this->get('status')->value == static::STATUS_PERMANENT;
   }
 
   /**
@@ -138,7 +138,7 @@ public function isTemporary() {
    * {@inheritdoc}
    */
   public function setPermanent() {
-    $this->get('status')->value = FILE_STATUS_PERMANENT;
+    $this->get('status')->value = static::STATUS_PERMANENT;
   }
 
   /**
diff --git a/core/modules/file/src/FileInterface.php b/core/modules/file/src/FileInterface.php
index 0a565e23c956..c90575aa4f98 100644
--- a/core/modules/file/src/FileInterface.php
+++ b/core/modules/file/src/FileInterface.php
@@ -13,6 +13,15 @@
  */
 interface FileInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
 
+  /**
+   * Indicates that the file is permanent and should not be deleted.
+   *
+   * Temporary files older than the system.file.temporary_maximum_age will be
+   * removed during cron runs if cleanup is not disabled. (Permanent files will
+   * not be removed during the file garbage collection process.)
+   */
+  const STATUS_PERMANENT = 1;
+
   /**
    * Returns the name of the file.
    *
diff --git a/core/modules/file/src/FileStorage.php b/core/modules/file/src/FileStorage.php
index ce9343eeadf5..dedf0851ace6 100644
--- a/core/modules/file/src/FileStorage.php
+++ b/core/modules/file/src/FileStorage.php
@@ -12,7 +12,7 @@ class FileStorage extends SqlContentEntityStorage implements FileStorageInterfac
   /**
    * {@inheritdoc}
    */
-  public function spaceUsed($uid = NULL, $status = FILE_STATUS_PERMANENT) {
+  public function spaceUsed($uid = NULL, $status = FileInterface::STATUS_PERMANENT) {
     $query = $this->database->select($this->entityType->getBaseTable(), 'f')
       ->condition('f.status', $status);
     $query->addExpression('SUM([f].[filesize])', 'filesize');
diff --git a/core/modules/file/src/FileStorageInterface.php b/core/modules/file/src/FileStorageInterface.php
index 3bbd92c5be1d..9a898aa6d2f1 100644
--- a/core/modules/file/src/FileStorageInterface.php
+++ b/core/modules/file/src/FileStorageInterface.php
@@ -17,11 +17,11 @@ interface FileStorageInterface extends ContentEntityStorageInterface {
    *   non-temporary files.
    * @param int $status
    *   (Optional) The file status to consider. The default is to only
-   *   consider files in status FILE_STATUS_PERMANENT.
+   *   consider files in status FileInterface::STATUS_PERMANENT.
    *
    * @return int
    *   An integer containing the number of bytes used.
    */
-  public function spaceUsed($uid = NULL, $status = FILE_STATUS_PERMANENT);
+  public function spaceUsed($uid = NULL, $status = FileInterface::STATUS_PERMANENT);
 
 }
diff --git a/core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php b/core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php
index 18abe836cde9..8c8623bc04cd 100644
--- a/core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php
+++ b/core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php
@@ -3,6 +3,7 @@
 namespace Drupal\file\Plugin\EntityReferenceSelection;
 
 use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
+use Drupal\file\FileInterface;
 
 /**
  * Provides specific access control for the file entity type.
@@ -28,7 +29,7 @@ protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS')
     //   become "permanent" after the containing entity gets validated and
     //   saved.)
     $query->condition($query->orConditionGroup()
-      ->condition('status', FILE_STATUS_PERMANENT)
+      ->condition('status', FileInterface::STATUS_PERMANENT)
       ->condition('uid', $this->currentUser->id()));
     return $query;
   }
diff --git a/core/modules/file/tests/src/Functional/FileListingTest.php b/core/modules/file/tests/src/Functional/FileListingTest.php
index f4081cd03ea8..ee645eaf1c75 100644
--- a/core/modules/file/tests/src/Functional/FileListingTest.php
+++ b/core/modules/file/tests/src/Functional/FileListingTest.php
@@ -227,8 +227,8 @@ protected function createFile() {
       'filemime' => 'text/plain',
       'created' => 1,
       'changed' => 1,
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     file_put_contents($file->getFileUri(), 'hello world');
 
     // Save it, inserting a new record.
diff --git a/core/modules/file/tests/src/Functional/Rest/FileResourceTestBase.php b/core/modules/file/tests/src/Functional/Rest/FileResourceTestBase.php
index 785c82c77c67..2d87ca796b88 100644
--- a/core/modules/file/tests/src/Functional/Rest/FileResourceTestBase.php
+++ b/core/modules/file/tests/src/Functional/Rest/FileResourceTestBase.php
@@ -80,7 +80,7 @@ protected function createEntity() {
     $file->setFilename('drupal.txt');
     $file->setMimeType('text/plain');
     $file->setFileUri('public://drupal.txt');
-    $file->set('status', FILE_STATUS_PERMANENT);
+    $file->setPermanent();
     $file->save();
 
     file_put_contents($file->getFileUri(), 'Drupal');
diff --git a/core/modules/file/tests/src/Kernel/AccessTest.php b/core/modules/file/tests/src/Kernel/AccessTest.php
index 5f9c0100c2ab..bfc8fc03cf4d 100644
--- a/core/modules/file/tests/src/Kernel/AccessTest.php
+++ b/core/modules/file/tests/src/Kernel/AccessTest.php
@@ -131,8 +131,8 @@ public function testFileCacheability() {
       'filename' => 'green-scarf',
       'uri' => 'private://green-scarf',
       'filemime' => 'text/plain',
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     $file->save();
     \Drupal::service('session')->set('anonymous_allowed_file_ids', [$file->id() => $file->id()]);
 
diff --git a/core/modules/file/tests/src/Kernel/FileManagedAccessTest.php b/core/modules/file/tests/src/Kernel/FileManagedAccessTest.php
index 87a11f789a60..a9eda570fc1f 100644
--- a/core/modules/file/tests/src/Kernel/FileManagedAccessTest.php
+++ b/core/modules/file/tests/src/Kernel/FileManagedAccessTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Session\AccountInterface;
 use Drupal\file\Entity\File;
+use Drupal\file\FileInterface;
 use Drupal\KernelTests\KernelTestBase;
 use Drupal\Tests\user\Traits\UserCreationTrait;
 use Drupal\user\Entity\User;
@@ -48,7 +49,7 @@ public function testFileAccess() {
       'uid' => 1,
       'filename' => 'drupal.txt',
       'uri' => 'public://drupal.txt',
-      'status' => FILE_STATUS_PERMANENT,
+      'status' => FileInterface::STATUS_PERMANENT,
     ]);
     $file_public->save();
 
@@ -63,7 +64,7 @@ public function testFileAccess() {
       'uid' => 1,
       'filename' => 'drupal.txt',
       'uri' => 'private://drupal.txt',
-      'status' => FILE_STATUS_PERMANENT,
+      'status' => FileInterface::STATUS_PERMANENT,
     ]);
     $file_private->save();
 
diff --git a/core/modules/file/tests/src/Kernel/FileUriItemTest.php b/core/modules/file/tests/src/Kernel/FileUriItemTest.php
index d67eba07070c..120af7f51c66 100644
--- a/core/modules/file/tests/src/Kernel/FileUriItemTest.php
+++ b/core/modules/file/tests/src/Kernel/FileUriItemTest.php
@@ -26,8 +26,8 @@ public function testCustomFileUriField() {
       'filename' => 'druplicon.txt',
       'uri' => $uri,
       'filemime' => 'text/plain',
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     file_put_contents($file->getFileUri(), 'hello world');
 
     $file->save();
diff --git a/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php
index 5573cd1032ce..5a8063367280 100644
--- a/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php
+++ b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php
@@ -44,8 +44,8 @@ protected function setUp(): void {
         'filemime' => 'text/plain',
         'created' => 1,
         'changed' => 1,
-        'status' => FILE_STATUS_PERMANENT,
       ]);
+      $file->setPermanent();
       $file->enforceIsNew();
       file_put_contents($file->getFileUri(), 'hello world');
 
diff --git a/core/modules/file/tests/src/Kernel/SaveTest.php b/core/modules/file/tests/src/Kernel/SaveTest.php
index 8edacab0d849..6e7524bdd5b1 100644
--- a/core/modules/file/tests/src/Kernel/SaveTest.php
+++ b/core/modules/file/tests/src/Kernel/SaveTest.php
@@ -18,8 +18,8 @@ public function testFileSave() {
       'filename' => 'druplicon.txt',
       'uri' => 'public://druplicon.txt',
       'filemime' => 'text/plain',
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     file_put_contents($file->getFileUri(), 'hello world');
 
     // Save it, inserting a new record.
@@ -61,8 +61,8 @@ public function testFileSave() {
       'filename' => 'DRUPLICON.txt',
       'uri' => 'public://DRUPLICON.txt',
       'filemime' => 'text/plain',
-      'status' => FILE_STATUS_PERMANENT,
     ];
+    $file->setPermanent();
     $uppercase_file = File::create($uppercase_values);
     file_put_contents($uppercase_file->getFileUri(), 'hello world');
     $violations = $uppercase_file->validate();
@@ -90,8 +90,8 @@ public function testFileSave() {
       'filename' => 'no-druplicon.txt',
       'uri' => 'public://no-druplicon.txt',
       'filemime' => 'text/plain',
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
 
     file_put_contents($file->getFileUri(), '');
 
diff --git a/core/modules/file/tests/src/Kernel/SpaceUsedTest.php b/core/modules/file/tests/src/Kernel/SpaceUsedTest.php
index 5cbf11fdf3df..f7e1ee7b8fa8 100644
--- a/core/modules/file/tests/src/Kernel/SpaceUsedTest.php
+++ b/core/modules/file/tests/src/Kernel/SpaceUsedTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\file\Kernel;
 
 use Drupal\file\Entity\File;
+use Drupal\file\FileInterface;
 
 /**
  * Tests the spaceUsed() function.
@@ -40,7 +41,7 @@ protected function setUp(): void {
    * @return \Drupal\Core\Entity\EntityInterface
    *   The file entity.
    */
-  protected function createFileWithSize($uri, $size, $uid, $status = FILE_STATUS_PERMANENT) {
+  protected function createFileWithSize($uri, $size, $uid, $status = FileInterface::STATUS_PERMANENT) {
     file_put_contents($uri, $this->randomMachineName($size));
     $file = File::create([
       'uri' => $uri,
@@ -63,15 +64,15 @@ public function testFileSpaceUsed() {
 
     // Test the status fields
     $this->assertEquals(4, $file->spaceUsed(NULL, 0));
-    $this->assertEquals(370, $file->spaceUsed(NULL, FILE_STATUS_PERMANENT));
+    $this->assertEquals(370, $file->spaceUsed());
 
     // Test both the user and status.
     $this->assertEquals(0, $file->spaceUsed(1, 0));
-    $this->assertEquals(0, $file->spaceUsed(1, FILE_STATUS_PERMANENT));
+    $this->assertEquals(0, $file->spaceUsed(1));
     $this->assertEquals(1, $file->spaceUsed(2, 0));
-    $this->assertEquals(70, $file->spaceUsed(2, FILE_STATUS_PERMANENT));
+    $this->assertEquals(70, $file->spaceUsed(2));
     $this->assertEquals(3, $file->spaceUsed(3, 0));
-    $this->assertEquals(300, $file->spaceUsed(3, FILE_STATUS_PERMANENT));
+    $this->assertEquals(300, $file->spaceUsed(3));
   }
 
 }
diff --git a/core/modules/file/tests/src/Kernel/Views/RelationshipUserFileDataTest.php b/core/modules/file/tests/src/Kernel/Views/RelationshipUserFileDataTest.php
index 4839fc2cd204..1a3a61bb05ae 100644
--- a/core/modules/file/tests/src/Kernel/Views/RelationshipUserFileDataTest.php
+++ b/core/modules/file/tests/src/Kernel/Views/RelationshipUserFileDataTest.php
@@ -82,9 +82,8 @@ public function testViewsHandlerRelationshipUserFileData() {
       'filemime' => 'image/jpeg',
       'created' => 1,
       'changed' => 1,
-      'status' => FILE_STATUS_PERMANENT,
     ]);
-    $file->enforceIsNew();
+    $file->enforceIsNew()->setPermanent();
     file_put_contents($file->getFileUri(), file_get_contents('core/tests/fixtures/files/image-1.png'));
     $file->save();
 
diff --git a/core/modules/hal/tests/src/Kernel/FileNormalizeTest.php b/core/modules/hal/tests/src/Kernel/FileNormalizeTest.php
index c73e9d567692..dfdd67680ff1 100644
--- a/core/modules/hal/tests/src/Kernel/FileNormalizeTest.php
+++ b/core/modules/hal/tests/src/Kernel/FileNormalizeTest.php
@@ -34,10 +34,10 @@ public function testNormalize() {
       'filename' => 'test_1.txt',
       'uri' => 'public://test_1.txt',
       'filemime' => 'text/plain',
-      'status' => FILE_STATUS_PERMANENT,
     ];
     // Create a new file entity.
     $file = File::create($file_params);
+    $file->setPermanent();
     file_put_contents($file->getFileUri(), 'hello world');
     $file->save();
 
diff --git a/core/modules/image/image.module b/core/modules/image/image.module
index ab4b12fba0b1..8b5fc77da101 100644
--- a/core/modules/image/image.module
+++ b/core/modules/image/image.module
@@ -389,7 +389,7 @@ function image_field_storage_config_update(FieldStorageConfigInterface $field_st
 
     // Is there a new file?
     if ($file_new) {
-      $file_new->status = FILE_STATUS_PERMANENT;
+      $file_new->setPermanent();
       $file_new->save();
       \Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field_storage->uuid());
     }
@@ -428,7 +428,7 @@ function image_field_config_update(FieldConfigInterface $field) {
   if ($uuid_new != $uuid_old) {
     // Save the new file, if present.
     if ($file_new) {
-      $file_new->status = FILE_STATUS_PERMANENT;
+      $file_new->setPermanent();
       $file_new->save();
       \Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field->uuid());
     }
diff --git a/core/modules/image/tests/src/FunctionalJavascript/QuickEditImageTest.php b/core/modules/image/tests/src/FunctionalJavascript/QuickEditImageTest.php
index d97faf89e47c..869cb4efa679 100644
--- a/core/modules/image/tests/src/FunctionalJavascript/QuickEditImageTest.php
+++ b/core/modules/image/tests/src/FunctionalJavascript/QuickEditImageTest.php
@@ -91,8 +91,8 @@ public function testImageInPlaceEditor() {
     $file = File::create([
       'uri' => $valid_images[0]->uri,
       'uid' => $this->contentAuthorUser->id(),
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     $file->save();
 
     // Use the first valid image to create a new Node.
diff --git a/core/modules/image/tests/src/Kernel/Views/RelationshipUserImageDataTest.php b/core/modules/image/tests/src/Kernel/Views/RelationshipUserImageDataTest.php
index 95dfd4f5b1ed..04a605c7f8c9 100644
--- a/core/modules/image/tests/src/Kernel/Views/RelationshipUserImageDataTest.php
+++ b/core/modules/image/tests/src/Kernel/Views/RelationshipUserImageDataTest.php
@@ -76,8 +76,8 @@ public function testViewsHandlerRelationshipUserImageData() {
       'filemime' => 'image/jpeg',
       'created' => 1,
       'changed' => 1,
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     $file->enforceIsNew();
     file_put_contents($file->getFileUri(), file_get_contents('core/tests/fixtures/files/image-1.png'));
     $file->save();
diff --git a/core/modules/jsonapi/tests/src/Functional/FileTest.php b/core/modules/jsonapi/tests/src/Functional/FileTest.php
index 719bae7608d0..81f6847d4ded 100644
--- a/core/modules/jsonapi/tests/src/Functional/FileTest.php
+++ b/core/modules/jsonapi/tests/src/Functional/FileTest.php
@@ -6,6 +6,7 @@
 use Drupal\Component\Utility\NestedArray;
 use Drupal\Core\Url;
 use Drupal\file\Entity\File;
+use Drupal\file\FileInterface;
 use Drupal\Tests\jsonapi\Traits\CommonCollectionFilterAccessTestPatternsTrait;
 use Drupal\user\Entity\User;
 use GuzzleHttp\RequestOptions;
@@ -105,7 +106,7 @@ protected function createEntity() {
     $file->setFilename('drupal.txt');
     $file->setMimeType('text/plain');
     $file->setFileUri('public://drupal.txt');
-    $file->set('status', FILE_STATUS_PERMANENT);
+    $file->set('status', FileInterface::STATUS_PERMANENT);
     $file->save();
 
     file_put_contents($file->getFileUri(), 'Drupal');
diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php
index f2b52a9aadaa..90bd6a5e7788 100644
--- a/core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php
+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php
@@ -228,8 +228,8 @@ protected function createPrivateFile($file_name) {
       'filename' => $file_name,
       'uri' => "private://$file_name",
       'filemime' => 'text/plain',
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     file_put_contents($file->getFileUri(), $this->getFileSecret($file));
     $file->save();
     return $file;
diff --git a/core/modules/locale/tests/src/Functional/LocaleUpdateBase.php b/core/modules/locale/tests/src/Functional/LocaleUpdateBase.php
index de32688ffa69..e6ddd71ee341 100644
--- a/core/modules/locale/tests/src/Functional/LocaleUpdateBase.php
+++ b/core/modules/locale/tests/src/Functional/LocaleUpdateBase.php
@@ -139,8 +139,8 @@ protected function makePoFile($path, $filename, $timestamp = NULL, array $transl
       'uri' => $path . '/' . $filename,
       'filemime' => 'text/x-gettext-translation',
       'timestamp' => $timestamp,
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     file_put_contents($file->getFileUri(), $po_header . $text);
     touch(\Drupal::service('file_system')->realpath($file->getFileUri()), $timestamp);
     $file->save();
diff --git a/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserTest.php b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserTest.php
index e863200990e5..b104b2b8467c 100644
--- a/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserTest.php
+++ b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserTest.php
@@ -45,8 +45,8 @@ protected function setUp(): void {
       'filemime' => 'image/jpeg',
       'created' => 1,
       'changed' => 1,
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     $file->enforceIsNew();
     file_put_contents($file->getFileUri(), file_get_contents('core/tests/fixtures/files/image-1.png'));
     $file->save();
@@ -59,8 +59,8 @@ protected function setUp(): void {
       'filemime' => 'image/png',
       'created' => 1,
       'changed' => 1,
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     $file->enforceIsNew();
     file_put_contents($file->getFileUri(), file_get_contents('core/tests/fixtures/files/image-2.jpg'));
     $file->save();
diff --git a/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php b/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php
index b98cdd824b80..50b800a75432 100644
--- a/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php
@@ -157,8 +157,8 @@ protected function createFile() {
       'filemime' => 'text/plain',
       'created' => 1,
       'changed' => 1,
-      'status' => FILE_STATUS_PERMANENT,
     ]);
+    $file->setPermanent();
     file_put_contents($file->getFileUri(), 'hello world');
 
     // Save it, inserting a new record.
-- 
GitLab