assertFileIsPermanent example

// Create a new node with the uploaded file.     $nid = $this->uploadNodeFile($test_file$field_name$type_name);

    // Check that the file exists on disk and in the database.     $node_storage->resetCache([$nid]);
    $node = $node_storage->load($nid);
    $node_file_r1 = File::load($node->{$field_name}->target_id);
    $node_vid_r1 = $node->getRevisionId();
    $this->assertFileExists($node_file_r1->getFileUri());
    $this->assertFileEntryExists($node_file_r1, 'File entry exists in database on node creation.');
    $this->assertFileIsPermanent($node_file_r1, 'File is permanent.');

    // Upload another file to the same node in a new revision.     $this->replaceNodeFile($test_file$field_name$nid);
    $node_storage->resetCache([$nid]);
    $node = $node_storage->load($nid);
    $node_file_r2 = File::load($node->{$field_name}->target_id);
    $node_vid_r2 = $node->getRevisionId();
    $this->assertFileExists($node_file_r2->getFileUri());
    $this->assertFileEntryExists($node_file_r2, 'Replacement file entry exists in database after creating new revision.');
    $this->assertFileIsPermanent($node_file_r2, 'Replacement file is permanent.');

    
Home | Imprint | This part of the site doesn't use cookies.