Projet

Général

Profil

Paste
Télécharger (14,9 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / feeds_ui / feeds_ui.test @ ed9a13f1

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for Feeds Admin UI module.
6
 */
7

    
8
/**
9
 * Test basic Feeds UI functionality.
10
 */
11
class FeedsUIUserInterfaceTestCase extends FeedsWebTestCase {
12

    
13
  /**
14
   * {@inheritdoc}
15
   */
16
  public static function getInfo() {
17
    return array(
18
      'name' => 'Feeds UI user interface',
19
      'description' => 'Tests Feeds Admin UI module\'s GUI.',
20
      'group' => 'Feeds',
21
    );
22
  }
23

    
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function setUp() {
28
    parent::setUp(array('php', 'locale'), array('use PHP for settings', 'administer languages'));
29
  }
30

    
31
  /**
32
   * UI functionality tests on disabled feeds.
33
   */
34
  public function testEditDisabledImporter() {
35
    // Create an importer.
36
    $this->createImporterConfiguration('Test feed', 'test_feed');
37
    // Disable the importer.
38
    $edit = array(
39
      'test_feed' => FALSE,
40
    );
41
    $this->drupalPost('admin/structure/feeds', $edit, t('Save'));
42
    // Try to edit the importer.
43
    $this->doEditFeedsConfiguration('Test feed', 'test_feed');
44
  }
45

    
46
  /**
47
   * UI functionality tests on
48
   * feeds_ui_overview(),
49
   * feeds_ui_create_form(),
50
   * Change plugins on feeds_ui_edit_page().
51
   */
52
  public function testEditFeedConfiguration() {
53

    
54
    // Create an importer.
55
    $this->createImporterConfiguration('Test feed', 'test_feed');
56

    
57
    // Try to edit the importer.
58
    $this->doEditFeedsConfiguration('Test feed', 'test_feed');
59

    
60
    // Check if importer is available on /import.
61
    $this->drupalGet('import');
62
    $this->assertText('Basic page');
63

    
64
    // Select some other plugins.
65
    $this->drupalGet('admin/structure/feeds/test_feed');
66

    
67
    $this->clickLink('Change', 0);
68
    $this->assertText('Select a fetcher');
69
    $edit = array(
70
      'plugin_key' => 'FeedsFileFetcher',
71
    );
72
    $this->drupalPost('admin/structure/feeds/test_feed/fetcher', $edit, 'Save');
73

    
74
    $this->clickLink('Change', 1);
75
    $this->assertText('Select a parser');
76
    $edit = array(
77
      'plugin_key' => 'FeedsCSVParser',
78
    );
79
    $this->drupalPost('admin/structure/feeds/test_feed/parser', $edit, 'Save');
80

    
81
    $this->clickLink('Change', 2);
82
    $this->assertText('Select a processor');
83
    $edit = array(
84
      'plugin_key' => 'FeedsUserProcessor',
85
    );
86
    $this->drupalPost('admin/structure/feeds/test_feed/processor', $edit, 'Save');
87

    
88
    // Assert changed configuration.
89
    $this->assertPlugins('test_feed', 'FeedsFileFetcher', 'FeedsCSVParser', 'FeedsUserProcessor');
90

    
91
    // Delete importer.
92
    $this->drupalPost('admin/structure/feeds/test_feed/delete', array(), 'Delete');
93
    $this->drupalGet('import');
94
    $this->assertNoText('Test feed');
95

    
96
    // Create the same importer again.
97
    $this->createImporterConfiguration('Test feed', 'test_feed');
98

    
99
    // Test basic settings settings.
100
    $edit = array(
101
      'name' => 'Syndication feed',
102
      'content_type' => 'page',
103
      'import_period' => 3600,
104
    );
105
    $this->setSettings('test_feed', NULL, $edit);
106

    
107
    // Assert results of change.
108
    $this->assertText('Syndication feed');
109
    $this->assertText('Your changes have been saved.');
110
    $this->assertText('Attached to: Basic page');
111
    $this->assertText('Periodic import: every 1 hour');
112
    $this->drupalGet('admin/structure/feeds');
113
    $this->assertLink('Basic page');
114

    
115
    // Configure processor.
116
    $this->setSettings('test_feed', 'FeedsNodeProcessor', array('bundle' => 'article'));
117
    $this->assertFieldByName('bundle', 'article');
118

    
119
    // Create a feed node.
120
    $edit = array(
121
      'title' => 'Development Seed',
122
      'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
123
    );
124
    $this->drupalPost('node/add/page', $edit, 'Save');
125
    $this->assertText('Basic page Development Seed has been created.');
126

    
127
    // @todo Refreshing/deleting feed items. Needs to live in feeds.test
128
  }
129

    
130
  /**
131
   * Tests if the user is warned when an invalid plugin is used.
132
   */
133
  public function testInvalidPlugin() {
134
    // Create an importer.
135
    $this->createImporterConfiguration('Test feed', 'test_feed');
136

    
137
    // Assert that there is no error message yet.
138
    $this->drupalGet('admin/structure/feeds/test_feed');
139
    $this->assertNoText('There are some issues with the importer configuration');
140

    
141
    // Add invalid fetcher plugin.
142
    $invalid_plugin = $this->randomName();
143
    $importer = feeds_importer('test_feed');
144
    $importer->addConfig(array(
145
      'fetcher' => array(
146
        'plugin_key' => $invalid_plugin,
147
        'config' => array(),
148
      ),
149
    ));
150
    $importer->save();
151

    
152
    // Assert error message on importer page.
153
    $this->drupalGet('admin/structure/feeds/test_feed');
154
    $this->assertText(format_string('The plugin @invalid_plugin is unavailable.', array(
155
      '@invalid_plugin' => $invalid_plugin,
156
    )));
157
  }
158

    
159
  /**
160
   * Tests if the user is warned when an invalid bundle is selected.
161
   */
162
  public function testInvalidBundle() {
163
    // Create an importer.
164
    $this->createImporterConfiguration('Test feed', 'test_feed');
165

    
166
    // Set invalid bundle.
167
    $invalid_bundle = drupal_strtolower($this->randomName());
168
    $importer = feeds_importer('test_feed');
169
    $importer->processor->addConfig(array(
170
      'bundle' => $invalid_bundle,
171
    ));
172
    $importer->save();
173

    
174
    // Assert error message on processor settings page.
175
    $this->drupalGet('admin/structure/feeds/test_feed/settings/FeedsNodeProcessor');
176
    $this->assertText(format_string('Invalid value @invalid_bundle for config option Bundle.', array(
177
      '@invalid_bundle' => $invalid_bundle,
178
    )));
179

    
180
    // But the option should still be selected.
181
    $this->assertFieldByName('bundle', $invalid_bundle);
182
  }
183

    
184
  /**
185
   * Tests if the user is warned when an invalid language is selected.
186
   */
187
  public function testInvalidLanguage() {
188
    // Add the Dutch language.
189
    $edit = array(
190
      'langcode' => 'nl',
191
    );
192
    $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
193

    
194
    // Create an importer.
195
    $this->createImporterConfiguration('Test feed', 'test_feed');
196
    // Change processor's language to Dutch.
197
    $this->setSettings('test_feed', 'FeedsNodeProcessor', array('language' => 'nl'));
198
    // Assert that there is no error message yet.
199
    $this->assertNoText('There are some issues with the importer configuration');
200

    
201
    // Now remove the Dutch language.
202
    $path = 'admin/config/regional/language/delete/nl';
203
    $this->drupalPost($path, array(), t('Delete'));
204

    
205
    // Assert error message on processor settings page.
206
    $this->drupalGet('admin/structure/feeds/test_feed/settings/FeedsNodeProcessor');
207
    $this->assertText(format_string('Invalid value @invalid_lang for config option Language.', array(
208
      '@invalid_lang' => 'nl',
209
    )));
210

    
211
    // But the option should still be selected.
212
    $this->assertFieldByName('language', 'nl');
213
  }
214

    
215
  /**
216
   * Tests if the user is warned when having both "Import on submission" and
217
   * "Periodic import" turned off.
218
   */
219
  public function testWarningPeriodicImportAndImportOnSubmissionTurnedOff() {
220
    // Create an importer.
221
    $this->createImporterConfiguration('Test feed', 'test_feed');
222

    
223
    $this->setSettings('test_feed', NULL, array(
224
      'content_type' => '',
225
      'import_period' => FEEDS_SCHEDULE_NEVER,
226
      'import_on_create' => FALSE,
227
    ));
228

    
229
    // Assert error message.
230
    $this->assertText(t('"@import_period" and "@import_on_create" are both turned off and the importer is not attached to a content type. Unless you have alternative methods of running imports for this importer, Feeds will not import anything for this importer.', array(
231
      '@import_period' => t('Periodic import'),
232
      '@import_on_create' => t('Import on submission'),
233
    )));
234
  }
235

    
236
  /**
237
   * Tests if the user is warned when having "Import on submission" turned off,
238
   * "Process in background" turned on and using the standalone form.
239
   */
240
  public function testWarningImportOnSubmissionTurnedOffAndProcessInBackgroundTurnedOn() {
241
    // Create an importer.
242
    $this->createImporterConfiguration('Test feed', 'test_feed');
243

    
244
    $this->setSettings('test_feed', NULL, array(
245
      'content_type' => '',
246
      'import_on_create' => FALSE,
247
      'process_in_background' => TRUE,
248
    ));
249

    
250
    // Assert error message.
251
    $this->assertText(t('Since "@import_on_create" is turned off and the importer is not attached to a content type, the "@process_in_background" setting may have no effect. When submitting the standalone form with the "@import_on_create" setting turned off, the feed is only scheduled for periodic import.', array(
252
      '@import_on_create' => t('Import on submission'),
253
      '@process_in_background' => t('Process in background'),
254
    )));
255
  }
256

    
257
  /**
258
   * Tests if the user is warned when the importer is attached to the same
259
   * content type as the one selected on the node processor.
260
   */
261
  public function testWarningWhenAttachImporterToContentTypeAlsoOnTheNodeProcessor() {
262
    // Create content type.
263
    $type = $this->drupalCreateContentType();
264
    $typename = $type->type;
265

    
266
    // Create an importer.
267
    $this->createImporterConfiguration('Test feed', 'test_feed');
268

    
269
    // Attach to content type.
270
    $this->setSettings('test_feed', NULL, array(
271
      'content_type' => $typename,
272
    ));
273

    
274
    // Select the same content type on the node processor.
275
    $this->setSettings('test_feed', 'FeedsNodeProcessor', array(
276
      'bundle' => $typename,
277
    ));
278

    
279
    $this->assertText('The importer is attached to the same content type as the content type selected on the node processor. Unless you have a very advanced use case, these two should never be the same.');
280
  }
281

    
282
  /**
283
   * Test the importer settings.
284
   */
285
  public function testImporterImport() {
286
    $name = $this->randomString();
287
    $id = drupal_strtolower($this->randomName());
288
    $this->createImporterConfiguration($name, $id);
289
    $this->setPlugin($id, 'FeedsCSVParser');
290
    $this->setPlugin($id, 'FeedsFileFetcher');
291
    $this->setPlugin($id, 'FeedsUserProcessor');
292

    
293
    $this->setSettings($id, 'FeedsFileFetcher', array('allowed_extensions' => 'xml'));
294
    $this->setSettings($id, 'FeedsCSVParser', array('delimiter' => '|'));
295
    $this->setSettings($id, 'FeedsUserProcessor', array('skip_hash_check' => TRUE));
296

    
297
    $this->drupalGet('admin/structure/feeds/' . $id . '/export');
298

    
299
    $export = $this->xpath('//textarea[1]/text()');
300
    $export = (string) $export[0];
301

    
302
    // Delete this importer.
303
    $this->drupalPost('admin/structure/feeds/' . $id . '/delete', array(), t('Delete'));
304

    
305
    // Try to import.
306
    $this->drupalPost('admin/structure/feeds/import', array('importer' => $export), t('Import'));
307

    
308
    $this->assertText("Successfully imported the $id feeds importer.");
309

    
310
    // Check that the settings are correct.
311
    $importer = feeds_importer($id);
312
    $this->assertEqual('FeedsFileFetcher', get_class($importer->fetcher));
313
    $this->assertEqual('FeedsCSVParser', get_class($importer->parser));
314
    $this->assertEqual('FeedsUserProcessor', get_class($importer->processor));
315

    
316
    $config = $importer->fetcher->getConfig();
317
    $this->assertEqual('xml', $config['allowed_extensions']);
318

    
319
    $config = $importer->parser->getConfig();
320
    $this->assertEqual('|', $config['delimiter']);
321

    
322
    $config = $importer->processor->getConfig();
323
    $this->assertTrue($config['skip_hash_check']);
324
  }
325

    
326
  /**
327
   * Tests if the user is warned when importing an importer with invalid configuration.
328
   */
329
  public function testInvalidConfigurationWhenImportingImporter() {
330
    $name = $this->randomString();
331
    $id = drupal_strtolower($this->randomName());
332
    $this->createImporterConfiguration($name, $id);
333
    $this->setPlugin($id, 'FeedsCSVParser');
334
    $this->setPlugin($id, 'FeedsFileFetcher');
335

    
336
    $this->drupalGet('admin/structure/feeds/' . $id . '/export');
337

    
338
    $export = $this->xpath('//textarea[1]/text()');
339
    $export = (string) $export[0];
340

    
341
    // Add in some invalid configuration in the export.
342
    $invalid_plugin = $this->randomName();
343
    $invalid_bundle = strtolower($this->randomName());
344
    $invalid_language = 'de';
345
    $export = str_replace('FeedsFileFetcher', $invalid_plugin, $export);
346
    $export = str_replace("'bundle' => 'article'", "'bundle' => '" . $invalid_bundle . "'", $export);
347
    $export = str_replace("'language' => 'und'", "'language' => '" . $invalid_language . "'", $export);
348

    
349
    // Delete this importer.
350
    $this->drupalPost('admin/structure/feeds/' . $id . '/delete', array(), t('Delete'));
351

    
352
    // Try to import.
353
    $edit = array(
354
      'importer' => $export,
355
    );
356
    $this->drupalPost('admin/structure/feeds/import', $edit, t('Import'));
357

    
358
    // Assert that the importer was not imported.
359
    $this->assertNoText("Successfully imported the $id feeds importer.");
360
    $this->assertFalse(feeds_importer_load($id), 'The importer was not created.');
361

    
362
    // Assert error messages.
363
    $this->assertText(format_string('The plugin @invalid_plugin is unavailable.', array(
364
      '@invalid_plugin' => $invalid_plugin,
365
    )));
366
    $this->assertText(format_string('Invalid value @invalid_bundle for config option Bundle.', array(
367
      '@invalid_bundle' => $invalid_bundle,
368
    )));
369
    $this->assertText(format_string('Invalid value @invalid_lang for config option Language.', array(
370
      '@invalid_lang' => $invalid_language,
371
    )));
372

    
373
    // Try if the importer is imported when ignoring validation.
374
    $edit['bypass_validation'] = 1;
375
    $this->drupalPost(NULL, $edit, t('Import'));
376

    
377
    // Assert that the importer has been imported now.
378
    drupal_static_reset();
379
    $this->assertTrue(feeds_importer_load($id) instanceof FeedsImporter, 'The importer was created.');
380

    
381
    // But the warnings should still be displayed.
382
    $this->drupalGet('admin/structure/feeds/' . $id);
383
    $this->assertText(format_string('The plugin @invalid_plugin is unavailable.', array(
384
      '@invalid_plugin' => $invalid_plugin,
385
    )));
386
    $this->assertText(format_string('Invalid value @invalid_bundle for config option Bundle.', array(
387
      '@invalid_bundle' => $invalid_bundle,
388
    )));
389
    $this->assertText(format_string('Invalid value @invalid_lang for config option Language.', array(
390
      '@invalid_lang' => $invalid_language,
391
    )));
392
  }
393

    
394
  /**
395
   * Edits an importer configuration.
396
   *
397
   * @param string $name
398
   *   The natural name of the feed.
399
   * @param string $id
400
   *   The persistent id of the feed.
401
   */
402
  protected function doEditFeedsConfiguration($name = 'Syndication', $id = 'syndication') {
403
    // Assert UI elements.
404
    $this->drupalGet('admin/structure/feeds/' . $id);
405
    $this->assertText($name);
406
    $this->assertText('Basic settings');
407
    $this->assertText('Fetcher');
408
    $this->assertText('HTTP Fetcher');
409
    $this->assertText('Parser');
410
    $this->assertText('Common syndication parser');
411
    $this->assertText('Processor');
412
    $this->assertText('Node processor');
413
    $this->assertText('Getting started');
414
    $this->assertRaw('admin/structure/feeds/' . $id . '/settings');
415
    $this->assertRaw('admin/structure/feeds/' . $id . '/settings/FeedsNodeProcessor');
416
    $this->assertRaw('admin/structure/feeds/' . $id . '/fetcher');
417
    $this->assertRaw('admin/structure/feeds/' . $id . '/parser');
418
    $this->assertRaw('admin/structure/feeds/' . $id . '/processor');
419
  }
420

    
421
}