You are here

public function FeedsUIUserInterfaceTestCase::testInvalidConfigurationWhenImportingImporter in Feeds 7.2

Tests if the user is warned when importing an importer with invalid configuration.

File

feeds_ui/feeds_ui.test, line 329
Tests for Feeds Admin UI module.

Class

FeedsUIUserInterfaceTestCase
Test basic Feeds UI functionality.

Code

public function testInvalidConfigurationWhenImportingImporter() {
  $name = $this
    ->randomString();
  $id = drupal_strtolower($this
    ->randomName());
  $this
    ->createImporterConfiguration($name, $id);
  $this
    ->setPlugin($id, 'FeedsCSVParser');
  $this
    ->setPlugin($id, 'FeedsFileFetcher');
  $this
    ->drupalGet('admin/structure/feeds/' . $id . '/export');
  $export = $this
    ->xpath('//textarea[1]/text()');
  $export = (string) $export[0];

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

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

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

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

  // Assert error messages.
  $this
    ->assertText(format_string('The plugin @invalid_plugin is unavailable.', array(
    '@invalid_plugin' => $invalid_plugin,
  )));
  $this
    ->assertText(format_string('Invalid value @invalid_bundle for config option Bundle.', array(
    '@invalid_bundle' => $invalid_bundle,
  )));
  $this
    ->assertText(format_string('Invalid value @invalid_lang for config option Language.', array(
    '@invalid_lang' => $invalid_language,
  )));

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

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

  // But the warnings should still be displayed.
  $this
    ->drupalGet('admin/structure/feeds/' . $id);
  $this
    ->assertText(format_string('The plugin @invalid_plugin is unavailable.', array(
    '@invalid_plugin' => $invalid_plugin,
  )));
  $this
    ->assertText(format_string('Invalid value @invalid_bundle for config option Bundle.', array(
    '@invalid_bundle' => $invalid_bundle,
  )));
  $this
    ->assertText(format_string('Invalid value @invalid_lang for config option Language.', array(
    '@invalid_lang' => $invalid_language,
  )));
}