Project

General

Profile

Revision 2c8c2b87

Added by Assos Assos about 9 years ago

Weekly update of contrib modules

View differences:

drupal7/sites/all/modules/feeds/tests/feeds_mapper_file.test
21 21
    );
22 22
  }
23 23

  
24
  public function setUp() {
25
    parent::setUp(array('dblog'));
26
  }
27

  
24 28
  /**
25 29
   * Basic test loading a single entry CSV file.
26 30
   */
......
40 44
      // Reset all the caches!
41 45
      $this->resetAll();
42 46
    }
43
    $typename = $this->createContentType(array(), array('files' => 'file'));
47
    $typename = $this->createContentType(array(), array(
48
      'files' => array(
49
        'type' => 'file',
50
        'instance_settings' => array(
51
          'instance[settings][file_extensions]' => 'png, gif, jpg, jpeg',
52
        ),
53
      ),
54
    ));
44 55

  
45 56
    // 1) Test mapping remote resources to file field.
46 57

  
......
72 83
      ->execute();
73 84
    foreach ($entities as $entity) {
74 85
      $this->drupalGet('node/' . $entity->entity_id . '/edit');
75
      $f = new FeedsEnclosure(array_shift($files), NULL);
76
      $this->assertText($f->getLocalValue());
86
      $this->assertText(str_replace(' ', '_', array_shift($files)));
77 87
    }
78 88

  
79 89
    // 2) Test mapping local resources to file field.
......
118 128
      ->execute();
119 129
    foreach ($entities as $entity) {
120 130
      $this->drupalGet('node/' . $entity->entity_id . '/edit');
121
      $f = new FeedsEnclosure(array_shift($files), NULL);
122
      $this->assertRaw('resources/' . $f->getUrlEncodedValue());
131
      $this->assertRaw('resources/' . rawurlencode(array_shift($files)));
123 132
    }
124 133

  
125 134
    // 3) Test mapping of local resources, this time leave files in place.
......
144 153
      ->execute();
145 154
    foreach ($entities as $entity) {
146 155
      $this->drupalGet('node/' . $entity->entity_id . '/edit');
147
      $f = new FeedsEnclosure(array_shift($files), NULL);
148
      $this->assertRaw('images/' . $f->getUrlEncodedValue());
156
      $this->assertRaw('images/' . rawurlencode(array_shift($files)));
149 157
    }
150 158

  
151 159
    // Deleting all imported items will delete the files from the images/ dir.
......
156 164
//    }
157 165
  }
158 166

  
167
  public function testInvalidFileExtension() {
168
    variable_set('feeds_never_use_curl', TRUE);
169

  
170
    $typename = $this->createContentType(array(), array(
171
      'files' => array(
172
        'type' => 'file',
173
        'instance_settings' => array(
174
          'instance[settings][file_extensions]' => 'txt',
175
        ),
176
      ),
177
    ));
178

  
179
    // Create a CSV importer configuration.
180
    $this->createImporterConfiguration('Node import from CSV', 'invalid_extension');
181
    $this->setPlugin('invalid_extension', 'FeedsCSVParser');
182
    $this->setSettings('invalid_extension', 'FeedsNodeProcessor', array('bundle' => $typename));
183
    $this->setSettings('invalid_extension', NULL, array('content_type' => ''));
184
    $this->addMappings('invalid_extension', array(
185
      0 => array(
186
        'source' => 'title',
187
        'target' => 'title',
188
      ),
189
      1 => array(
190
        'source' => 'file',
191
        'target' => 'field_files',
192
      ),
193
    ));
194

  
195
    // Import.
196
    $edit = array(
197
      'feeds[FeedsHTTPFetcher][source]' => url('testing/feeds/files.csv', array('absolute' => TRUE)),
198
    );
199
    $this->drupalPost('import/invalid_extension', $edit, 'Import');
200
    $this->assertText('Created 5 nodes');
201

  
202
    foreach (range(1, 5) as $nid) {
203
      $node = node_load($nid);
204
      $this->assertTrue(empty($node->field_files));
205
    }
206

  
207
    foreach ($this->_testFiles() as $filename) {
208
      $message = t('The file @file has an invalid extension.', array('@file' => $filename));
209
      $this->assertTrue(db_query("SELECT 1 FROM {watchdog} WHERE message = :message", array(':message' => $message))->fetchField());
210
    }
211
  }
212

  
159 213
  /**
160 214
   * Lists test files.
161 215
   */

Also available in: Unified diff