diff -u b/core/modules/editor/src/Tests/EditorPrivateFileReferenceFilterTest.php b/core/modules/editor/src/Tests/EditorPrivateFileReferenceFilterTest.php --- b/core/modules/editor/src/Tests/EditorPrivateFileReferenceFilterTest.php +++ b/core/modules/editor/src/Tests/EditorPrivateFileReferenceFilterTest.php @@ -4,14 +4,14 @@ use Drupal\file\Entity\File; use Drupal\file\FileInterface; -use Drupal\simpletest\WebTestBase; +use Drupal\Tests\BrowserTestBase; /** * Tests Editor module's file reference filter with private files. * * @group editor */ -class EditorPrivateFileReferenceFilterTest extends WebTestBase { +class EditorPrivateFileReferenceFilterTest extends BrowserTestBase { /** * Modules to enable. @@ -36,6 +36,9 @@ * Tests the editor file reference filter with private files. */ function testEditorPrivateFileReferenceFilter() { + $author = $this->drupalCreateUser(); + $this->drupalLogin($author); + // Create a content type with a body field. $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); @@ -45,12 +48,25 @@ /** @var FileInterface $file */ $file = File::create([ 'uri' => 'private://' . $filename, - 'status' => FILE_STATUS_PERMANENT, ]); + $file->setTemporary(); + $file->setOwner($author); // Create the file itself. file_put_contents($file->getFileUri(), $this->randomString()); $file->save(); + // The image should be visible for its author. + $this->drupalGet($src); + $this->assertSession()->statusCodeEquals(200); + // The not-yet-permanent image should NOT be visible for anonymous. + $this->drupalLogout(); + $this->drupalGet($src); + $this->assertSession()->statusCodeEquals(403); + + // Resave the file to be permanent. + $file->setPermanent(); + $file->save(); + // Create a node with its body field properly pointing to the just-created // file. $node = $this->drupalCreateNode([ @@ -59,12 +75,13 @@ 'value' => 'alt', 'format' => 'private_images', ], + 'uid' => $author->id(), ]); $this->drupalGet('/node/' . $node->id()); // Do the actual test. The image should be visible for anonymous. $this->drupalGet($src); - $this->assertResponse(200, 'Image is downloadable as anonymous.'); + $this->assertSession()->statusCodeEquals(200); } }