feeds_ui.test in Feeds 7.2
Same filename and directory in other branches
Tests for Feeds Admin UI module.
File
feeds_ui/feeds_ui.testView source
<?php
/**
* @file
* Tests for Feeds Admin UI module.
*/
/**
* Test basic Feeds UI functionality.
*/
class FeedsUIUserInterfaceTestCase extends FeedsWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Feeds UI user interface',
'description' => 'Tests Feeds Admin UI module\'s GUI.',
'group' => 'Feeds',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp(array(
'php',
'locale',
), array(
'use PHP for settings',
'administer languages',
));
}
/**
* UI functionality tests on disabled feeds.
*/
public function testEditDisabledImporter() {
// Create an importer.
$this
->createImporterConfiguration('Test feed', 'test_feed');
// Disable the importer.
$edit = array(
'test_feed' => FALSE,
);
$this
->drupalPost('admin/structure/feeds', $edit, t('Save'));
// Try to edit the importer.
$this
->doEditFeedsConfiguration('Test feed', 'test_feed');
}
/**
* UI functionality tests on
* feeds_ui_overview(),
* feeds_ui_create_form(),
* Change plugins on feeds_ui_edit_page().
*/
public function testEditFeedConfiguration() {
// Create an importer.
$this
->createImporterConfiguration('Test feed', 'test_feed');
// Try to edit the importer.
$this
->doEditFeedsConfiguration('Test feed', 'test_feed');
// Check if importer is available on /import.
$this
->drupalGet('import');
$this
->assertText('Basic page');
// Select some other plugins.
$this
->drupalGet('admin/structure/feeds/test_feed');
$this
->clickLink('Change', 0);
$this
->assertText('Select a fetcher');
$edit = array(
'plugin_key' => 'FeedsFileFetcher',
);
$this
->drupalPost('admin/structure/feeds/test_feed/fetcher', $edit, 'Save');
$this
->clickLink('Change', 1);
$this
->assertText('Select a parser');
$edit = array(
'plugin_key' => 'FeedsCSVParser',
);
$this
->drupalPost('admin/structure/feeds/test_feed/parser', $edit, 'Save');
$this
->clickLink('Change', 2);
$this
->assertText('Select a processor');
$edit = array(
'plugin_key' => 'FeedsUserProcessor',
);
$this
->drupalPost('admin/structure/feeds/test_feed/processor', $edit, 'Save');
// Assert changed configuration.
$this
->assertPlugins('test_feed', 'FeedsFileFetcher', 'FeedsCSVParser', 'FeedsUserProcessor');
// Delete importer.
$this
->drupalPost('admin/structure/feeds/test_feed/delete', array(), 'Delete');
$this
->drupalGet('import');
$this
->assertNoText('Test feed');
// Create the same importer again.
$this
->createImporterConfiguration('Test feed', 'test_feed');
// Test basic settings settings.
$edit = array(
'name' => 'Syndication feed',
'content_type' => 'page',
'import_period' => 3600,
);
$this
->setSettings('test_feed', NULL, $edit);
// Assert results of change.
$this
->assertText('Syndication feed');
$this
->assertText('Your changes have been saved.');
$this
->assertText('Attached to: Basic page');
$this
->assertText('Periodic import: every 1 hour');
$this
->drupalGet('admin/structure/feeds');
$this
->assertLink('Basic page');
// Configure processor.
$this
->setSettings('test_feed', 'FeedsNodeProcessor', array(
'bundle' => 'article',
));
$this
->assertFieldByName('bundle', 'article');
// Create a feed node.
$edit = array(
'title' => 'Development Seed',
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
);
$this
->drupalPost('node/add/page', $edit, 'Save');
$this
->assertText('Basic page Development Seed has been created.');
// @todo Refreshing/deleting feed items. Needs to live in feeds.test
}
/**
* Tests if the user is warned when an invalid plugin is used.
*/
public function testInvalidPlugin() {
// Create an importer.
$this
->createImporterConfiguration('Test feed', 'test_feed');
// Assert that there is no error message yet.
$this
->drupalGet('admin/structure/feeds/test_feed');
$this
->assertNoText('There are some issues with the importer configuration');
// Add invalid fetcher plugin.
$invalid_plugin = $this
->randomName();
$importer = feeds_importer('test_feed');
$importer
->addConfig(array(
'fetcher' => array(
'plugin_key' => $invalid_plugin,
'config' => array(),
),
));
$importer
->save();
// Assert error message on importer page.
$this
->drupalGet('admin/structure/feeds/test_feed');
$this
->assertText(format_string('The plugin @invalid_plugin is unavailable.', array(
'@invalid_plugin' => $invalid_plugin,
)));
}
/**
* Tests if the user is warned when an invalid bundle is selected.
*/
public function testInvalidBundle() {
// Create an importer.
$this
->createImporterConfiguration('Test feed', 'test_feed');
// Set invalid bundle.
$invalid_bundle = drupal_strtolower($this
->randomName());
$importer = feeds_importer('test_feed');
$importer->processor
->addConfig(array(
'bundle' => $invalid_bundle,
));
$importer
->save();
// Assert error message on processor settings page.
$this
->drupalGet('admin/structure/feeds/test_feed/settings/FeedsNodeProcessor');
$this
->assertText(format_string('Invalid value @invalid_bundle for config option Bundle.', array(
'@invalid_bundle' => $invalid_bundle,
)));
// But the option should still be selected.
$this
->assertFieldByName('bundle', $invalid_bundle);
}
/**
* Tests if the user is warned when an invalid language is selected.
*/
public function testInvalidLanguage() {
// Add the Dutch language.
$edit = array(
'langcode' => 'nl',
);
$this
->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
// Create an importer.
$this
->createImporterConfiguration('Test feed', 'test_feed');
// Change processor's language to Dutch.
$this
->setSettings('test_feed', 'FeedsNodeProcessor', array(
'language' => 'nl',
));
// Assert that there is no error message yet.
$this
->assertNoText('There are some issues with the importer configuration');
// Now remove the Dutch language.
$path = 'admin/config/regional/language/delete/nl';
$this
->drupalPost($path, array(), t('Delete'));
// Assert error message on processor settings page.
$this
->drupalGet('admin/structure/feeds/test_feed/settings/FeedsNodeProcessor');
$this
->assertText(format_string('Invalid value @invalid_lang for config option Language.', array(
'@invalid_lang' => 'nl',
)));
// But the option should still be selected.
$this
->assertFieldByName('language', 'nl');
}
/**
* Tests if the user is warned when having both "Import on submission" and
* "Periodic import" turned off.
*/
public function testWarningPeriodicImportAndImportOnSubmissionTurnedOff() {
// Create an importer.
$this
->createImporterConfiguration('Test feed', 'test_feed');
$this
->setSettings('test_feed', NULL, array(
'content_type' => '',
'import_period' => FEEDS_SCHEDULE_NEVER,
'import_on_create' => FALSE,
));
// Assert error message.
$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(
'@import_period' => t('Periodic import'),
'@import_on_create' => t('Import on submission'),
)));
}
/**
* Tests if the user is warned when having "Import on submission" turned off,
* "Process in background" turned on and using the standalone form.
*/
public function testWarningImportOnSubmissionTurnedOffAndProcessInBackgroundTurnedOn() {
// Create an importer.
$this
->createImporterConfiguration('Test feed', 'test_feed');
$this
->setSettings('test_feed', NULL, array(
'content_type' => '',
'import_on_create' => FALSE,
'process_in_background' => TRUE,
));
// Assert error message.
$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(
'@import_on_create' => t('Import on submission'),
'@process_in_background' => t('Process in background'),
)));
}
/**
* Tests if the user is warned when the importer is attached to the same
* content type as the one selected on the node processor.
*/
public function testWarningWhenAttachImporterToContentTypeAlsoOnTheNodeProcessor() {
// Create content type.
$type = $this
->drupalCreateContentType();
$typename = $type->type;
// Create an importer.
$this
->createImporterConfiguration('Test feed', 'test_feed');
// Attach to content type.
$this
->setSettings('test_feed', NULL, array(
'content_type' => $typename,
));
// Select the same content type on the node processor.
$this
->setSettings('test_feed', 'FeedsNodeProcessor', array(
'bundle' => $typename,
));
$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.');
}
/**
* Test the importer settings.
*/
public function testImporterImport() {
$name = $this
->randomString();
$id = drupal_strtolower($this
->randomName());
$this
->createImporterConfiguration($name, $id);
$this
->setPlugin($id, 'FeedsCSVParser');
$this
->setPlugin($id, 'FeedsFileFetcher');
$this
->setPlugin($id, 'FeedsUserProcessor');
$this
->setSettings($id, 'FeedsFileFetcher', array(
'allowed_extensions' => 'xml',
));
$this
->setSettings($id, 'FeedsCSVParser', array(
'delimiter' => '|',
));
$this
->setSettings($id, 'FeedsUserProcessor', array(
'skip_hash_check' => TRUE,
));
$this
->drupalGet('admin/structure/feeds/' . $id . '/export');
$export = $this
->xpath('//textarea[1]/text()');
$export = (string) $export[0];
// Delete this importer.
$this
->drupalPost('admin/structure/feeds/' . $id . '/delete', array(), t('Delete'));
// Try to import.
$this
->drupalPost('admin/structure/feeds/import', array(
'importer' => $export,
), t('Import'));
$this
->assertText("Successfully imported the {$id} feeds importer.");
// Check that the settings are correct.
$importer = feeds_importer($id);
$this
->assertEqual('FeedsFileFetcher', get_class($importer->fetcher));
$this
->assertEqual('FeedsCSVParser', get_class($importer->parser));
$this
->assertEqual('FeedsUserProcessor', get_class($importer->processor));
$config = $importer->fetcher
->getConfig();
$this
->assertEqual('xml', $config['allowed_extensions']);
$config = $importer->parser
->getConfig();
$this
->assertEqual('|', $config['delimiter']);
$config = $importer->processor
->getConfig();
$this
->assertTrue($config['skip_hash_check']);
}
/**
* Tests if the user is warned when importing an importer with invalid configuration.
*/
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,
)));
}
/**
* Edits an importer configuration.
*
* @param string $name
* The natural name of the feed.
* @param string $id
* The persistent id of the feed.
*/
protected function doEditFeedsConfiguration($name = 'Syndication', $id = 'syndication') {
// Assert UI elements.
$this
->drupalGet('admin/structure/feeds/' . $id);
$this
->assertText($name);
$this
->assertText('Basic settings');
$this
->assertText('Fetcher');
$this
->assertText('HTTP Fetcher');
$this
->assertText('Parser');
$this
->assertText('Common syndication parser');
$this
->assertText('Processor');
$this
->assertText('Node processor');
$this
->assertText('Getting started');
$this
->assertRaw('admin/structure/feeds/' . $id . '/settings');
$this
->assertRaw('admin/structure/feeds/' . $id . '/settings/FeedsNodeProcessor');
$this
->assertRaw('admin/structure/feeds/' . $id . '/fetcher');
$this
->assertRaw('admin/structure/feeds/' . $id . '/parser');
$this
->assertRaw('admin/structure/feeds/' . $id . '/processor');
}
}
Classes
Name | Description |
---|---|
FeedsUIUserInterfaceTestCase | Test basic Feeds UI functionality. |