You are here

function FileFieldPathsUploadTestCase::testUploadFile in File (Field) Paths 6

Same name and namespace in other branches
  1. 6.2 tests/filefield_paths.test \FileFieldPathsUploadTestCase::testUploadFile()

Test file upload.

File

tests/filefield_paths.test, line 346
This file implements tests for FileField Paths.

Class

FileFieldPathsUploadTestCase
Tests Drupal core Upload module integration.

Code

function testUploadFile() {

  // Create content type.
  $type = $this
    ->drupalCreateContentType();

  // Set FileField Paths settings.
  $edit = $this
    ->setFileFieldPathsSettings('upload');
  $this
    ->drupalPost('admin/content/node-type/' . str_replace('_', '-', $type->name), $edit, t('Save content type'));

  // Create Node with uploaded file.
  $test_files = $this
    ->drupalGetTestFiles('text');
  $nid = $this
    ->uploadNodeFile(array(
    'path' => $test_files[0]->filename,
    'name' => $test_files[0]->basename,
  ), 'upload', $type->name);

  // Load uploaded file.
  $node = node_load($nid, NULL, TRUE);
  $node_file = $node->files[1];

  // Check file has been processed correctly.
  $this
    ->checkFileName((array) $node_file, $node);
  $this
    ->checkFilePath((array) $node_file, $node);
  $this
    ->checkNodeBody((array) $node_file);

  // Change FileField Paths settings.
  $edit = FileFieldPathsTestCase::setFileFieldPathsSettings('upload', array(), TRUE);
  $this
    ->drupalPost('admin/content/node-type/' . str_replace('_', '-', $type->name), $edit, t('Save content type'));

  // Load uploaded file.
  $node = node_load($nid, NULL, TRUE);
  $node_file = $node->files[1];

  // Check file has been retroactively updated correctly.
  $this
    ->checkFileName((array) $node_file, $node, TRUE);
  $this
    ->checkFilePath((array) $node_file, $node, TRUE);
}