From dd994edd2020a8591f95c43364a85fccaf0acf96 Mon Sep 17 00:00:00 2001 From: nod_ <nod_@598310.no-reply.drupal.org> Date: Mon, 29 Jul 2024 12:06:42 +0200 Subject: [PATCH] Issue #3439836 by pooja_sharma, thebumik, FeyP, vensires, smustgrave, kim.pepper, quietone: Fix File tests that rely on UID1's super user behavior (cherry picked from commit 35dbb2d49865189a0dc6a9f78cd58cfad4705546) --- core/modules/file/tests/src/Kernel/SaveTest.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/modules/file/tests/src/Kernel/SaveTest.php b/core/modules/file/tests/src/Kernel/SaveTest.php index 82113681aded..6de2071e05f2 100644 --- a/core/modules/file/tests/src/Kernel/SaveTest.php +++ b/core/modules/file/tests/src/Kernel/SaveTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\file\Kernel; use Drupal\file\Entity\File; +use Drupal\Tests\user\Traits\UserCreationTrait; /** * File saving tests. @@ -13,18 +14,13 @@ */ class SaveTest extends FileManagedUnitTestBase { - /** - * {@inheritdoc} - * - * @todo Remove and fix test to not rely on super user. - * @see https://www.drupal.org/project/drupal/issues/3437620 - */ - protected bool $usesSuperUserAccessPolicy = TRUE; + use UserCreationTrait; public function testFileSave(): void { + $account = $this->createUser(); // Create a new file entity. $file = File::create([ - 'uid' => 1, + 'uid' => $account->id(), 'filename' => 'druplicon.txt', 'uri' => 'public://druplicon.txt', 'filemime' => 'text/plain', @@ -67,7 +63,7 @@ public function testFileSave(): void { // Try to insert a second file with the same name apart from case insensitivity // to ensure the 'uri' index allows for filenames with different cases. $uppercase_values = [ - 'uid' => 1, + 'uid' => $account->id(), 'filename' => 'DRUPLICON.txt', 'uri' => 'public://DRUPLICON.txt', 'filemime' => 'text/plain', @@ -96,7 +92,7 @@ public function testFileSave(): void { // Save a file with zero bytes. $file = File::create([ - 'uid' => 1, + 'uid' => $account->id(), 'filename' => 'no-druplicon.txt', 'uri' => 'public://no-druplicon.txt', 'filemime' => 'text/plain', -- GitLab