Commit 7e7ec357 authored by catch's avatar catch
Browse files

Issue #3415038 by Spokje, kim.pepper: Convert FileMoveTest into a Kernel test

(cherry picked from commit 0255591f)
parent 79b14beb
Loading
Loading
Loading
Loading
Loading
+24 −16
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\image\Functional;
namespace Drupal\Tests\image\Kernel;

use Drupal\Core\File\FileSystemInterface;
use Drupal\file\Entity\File;
use Drupal\file\FileRepository;
use Drupal\image\Entity\ImageStyle;
use Drupal\Tests\BrowserTestBase;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\TestFileCreationTrait;

/**
@@ -13,44 +14,51 @@
 *
 * @group image
 */
class FileMoveTest extends BrowserTestBase {
class FileMoveTest extends KernelTestBase {

  use TestFileCreationTrait {
    getTestFiles as drupalGetTestFiles;
    compareFiles as drupalCompareFiles;
  }

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = ['image'];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  protected static $modules = [
    'file',
    'image',
    'system',
    'user',
  ];

  /**
   * The file repository service.
   *
   * @var \Drupal\file\FileRepository
   */
  protected $fileRepository;
  protected FileRepository $fileRepository;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    $this->installConfig(['system']);
    $this->installEntitySchema('file');
    $this->installEntitySchema('user');
    $this->installSchema('file', ['file_usage']);

    ImageStyle::create([
      'name' => 'main_style',
      'label' => 'Main',
    ])->save();

    $this->fileRepository = $this->container->get('file.repository');
  }

  /**
   * Tests moving a randomly generated image.
   */
  public function testNormal() {
  public function testNormal(): void {
    // Pick a file for testing.
    $file = File::create((array) current($this->drupalGetTestFiles('image')));

@@ -64,7 +72,7 @@ public function testNormal() {
    // Check if derivative image exists.
    $this->assertFileExists($derivative_uri);

    // Clone the object so we don't have to worry about the function changing
    // Clone the object, so we don't have to worry about the function changing
    // our reference copy.
    $desired_filepath = 'public://' . $this->randomMachineName();
    $result = $this->fileRepository->move(clone $file, $desired_filepath, FileSystemInterface::EXISTS_ERROR);