assertPathMatch example

// Check that the file was uploaded to the correct location.     $node_storage->resetCache([$nid]);
    $node = $node_storage->load($nid);
    /** @var \Drupal\file\FileInterface $node_file */
    $node_file = $node->{$field_name}->entity;
    $date_formatter = $this->container->get('date.formatter');
    $expected_filename =
      'public://' .
      $date_formatter->format(REQUEST_TIME, 'custom', 'Y') . '-' .
      $date_formatter->format(REQUEST_TIME, 'custom', 'm') . '/' .
      $test_file->getFilename();
    $this->assertPathMatch($expected_filename$node_file->getFileUri()new FormattableMarkup('The file %file was uploaded to the correct path.', ['%file' => $node_file->getFileUri()]));

    // Change the path to contain multiple subdirectories.     $this->updateFileField($field_name$type_name['file_directory' => 'foo/bar/baz']);

    // Upload a new file into the subdirectories.     $nid = $this->uploadNodeFile($test_file$field_name$type_name);

    // Check that the file was uploaded into the subdirectory.     $node_storage->resetCache([$nid]);
    $node = $node_storage->load($nid);
    $node_file = File::load($node->{$field_name}->target_id);
    
Home | Imprint | This part of the site doesn't use cookies.