You are here

public function FeedsMapperFileTestCase::testInvalidFileExtension in Feeds 7.2

File

tests/feeds_mapper_file.test, line 705
Contains FeedsMapperFileTestCase.

Class

FeedsMapperFileTestCase
Test case for Filefield mapper mappers/filefield.inc.

Code

public function testInvalidFileExtension() {
  variable_set('feeds_never_use_curl', TRUE);
  $typename = $this
    ->createContentType(array(), array(
    'files' => array(
      'type' => 'file',
      'instance_settings' => array(
        'instance[settings][file_extensions]' => 'txt',
      ),
    ),
  ));

  // Create a CSV importer configuration.
  $this
    ->createImporterConfiguration('Node import from CSV', 'invalid_extension');
  $this
    ->setPlugin('invalid_extension', 'FeedsCSVParser');
  $this
    ->setSettings('invalid_extension', 'FeedsNodeProcessor', array(
    'bundle' => $typename,
  ));
  $this
    ->setSettings('invalid_extension', NULL, array(
    'content_type' => '',
  ));
  $this
    ->addMappings('invalid_extension', array(
    0 => array(
      'source' => 'title',
      'target' => 'title',
    ),
    1 => array(
      'source' => 'file',
      'target' => 'field_files:uri',
    ),
  ));

  // Import.
  $edit = array(
    'feeds[FeedsHTTPFetcher][source]' => url('testing/feeds/files-remote.csv', array(
      'absolute' => TRUE,
    )),
  );
  $this
    ->drupalPost('import/invalid_extension', $edit, 'Import');
  $this
    ->assertText('Created 5 nodes');
  foreach (range(1, 5) as $nid) {
    $node = node_load($nid);
    $this
      ->assertTrue(empty($node->field_files));
  }
  foreach ($this
    ->listTestFiles() as $filename) {
    $message = t('The file @file has an invalid extension.', array(
      '@file' => $filename,
    ));
    $this
      ->assertTrue(db_query("SELECT 1 FROM {watchdog} WHERE message = :message", array(
      ':message' => $message,
    ))
      ->fetchField());
  }

  // Test that query string and fragments are removed.
  $enclosure = new FeedsEnclosure('http://example.com/image.jpg?thing=stuff', 'text/plain');
  $this
    ->assertEqual($enclosure
    ->getLocalValue(), 'image.jpg');
  $enclosure = new FeedsEnclosure('http://example.com/image.jpg#stuff', 'text/plain');
  $this
    ->assertEqual($enclosure
    ->getLocalValue(), 'image.jpg');
  $enclosure = new FeedsEnclosure('http://example.com/image.JPG?thing=stuff#stuff', 'text/plain');
  $this
    ->assertEqual($enclosure
    ->getLocalValue(), 'image.JPG');
}