You are here

public function FileFieldPathsGeneralTest::testLongPath in File (Field) Paths 8

Test File (Field) Paths with a very long path.

File

tests/src/Functional/FileFieldPathsGeneralTest.php, line 139

Class

FileFieldPathsGeneralTest
Test general functionality.

Namespace

Drupal\Tests\filefield_paths\Functional

Code

public function testLongPath() {

  // Create a File field with 'node/[random:hash:sha256]' as the File path.
  $field_name = mb_strtolower($this
    ->randomMachineName());
  $third_party_settings['filefield_paths']['file_path']['value'] = 'node/[random:hash:sha512]/[random:hash:sha512]';
  $this
    ->createFileField($field_name, 'node', $this->contentType, [], [], $third_party_settings);

  // Create a node with a test file.

  /** @var \Drupal\file\Entity\File $test_file */
  $test_file = $this
    ->getTestFile('text');
  $nid = $this
    ->uploadNodeFile($test_file, $field_name, $this->contentType);

  // Ensure file path is no more than 255 characters.
  $node = Node::load($nid);
  $this
    ->assertLessThanOrEqual(255, mb_strlen($node->{$field_name}->uri), 'File path is no more than 255 characters');
}