first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
<?php
/**
* @file
* feeds_import.features.inc
*/
/**
* Implements hook_ctools_plugin_api().
*/
function feeds_import_ctools_plugin_api() {
list($module, $api) = func_get_args();
if ($module == "feeds" && $api == "feeds_importer_default") {
return array("version" => "1");
}
}

View File

@@ -0,0 +1,125 @@
<?php
/**
* @file
* feeds_import.feeds_importer_default.inc
*/
/**
* Implements hook_feeds_importer_default().
*/
function feeds_import_feeds_importer_default() {
$export = array();
$feeds_importer = new stdClass();
$feeds_importer->disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */
$feeds_importer->api_version = 1;
$feeds_importer->id = 'node';
$feeds_importer->config = array(
'name' => 'Node import',
'description' => 'Import nodes from CSV file.',
'fetcher' => array(
'plugin_key' => 'FeedsFileFetcher',
'config' => array(
'direct' => FALSE,
),
),
'parser' => array(
'plugin_key' => 'FeedsCSVParser',
'config' => array(
'delimiter' => ',',
),
),
'processor' => array(
'plugin_key' => 'FeedsNodeProcessor',
'config' => array(
'content_type' => 'article',
'update_existing' => 1,
'expire' => '-1',
'mappings' => array(
0 => array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
1 => array(
'source' => 'body',
'target' => 'body',
'unique' => FALSE,
),
2 => array(
'source' => 'published',
'target' => 'created',
'unique' => FALSE,
),
3 => array(
'source' => 'guid',
'target' => 'guid',
'unique' => 1,
),
),
'input_format' => 'plain_text',
'author' => 0,
),
),
'content_type' => '',
'update' => 0,
'import_period' => '-1',
'expire_period' => 3600,
'import_on_create' => 1,
);
$export['node'] = $feeds_importer;
$feeds_importer = new stdClass();
$feeds_importer->disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */
$feeds_importer->api_version = 1;
$feeds_importer->id = 'user';
$feeds_importer->config = array(
'name' => 'User import',
'description' => 'Import users from CSV file.',
'fetcher' => array(
'plugin_key' => 'FeedsFileFetcher',
'config' => array(
'direct' => FALSE,
),
),
'parser' => array(
'plugin_key' => 'FeedsCSVParser',
'config' => array(
'delimiter' => ',',
),
),
'processor' => array(
'plugin_key' => 'FeedsUserProcessor',
'config' => array(
'roles' => array(),
'update_existing' => FALSE,
'status' => 1,
'mappings' => array(
0 => array(
'source' => 'name',
'target' => 'name',
'unique' => 0,
),
1 => array(
'source' => 'mail',
'target' => 'mail',
'unique' => 1,
),
2 => array(
'source' => 'created',
'target' => 'created',
'unique' => FALSE,
),
),
),
),
'content_type' => '',
'update' => 0,
'import_period' => '-1',
'expire_period' => 3600,
'import_on_create' => 1,
);
$export['user'] = $feeds_importer;
return $export;
}

View File

@@ -0,0 +1,14 @@
name = Feeds Import
description = An example of a node importer and a user importer.
core = 7.x
package = Feeds
php = 5.2.4
version = 7.x-2.0-alpha7
project = feeds
dependencies[] = feeds
datestamp = 1351111319
features[ctools][] = feeds:feeds_importer_default:1
features[features_api][] = api:1
features[feeds_importer][] = node
features[feeds_importer][] = user
files[] = feeds_import.test

View File

@@ -0,0 +1,8 @@
<?php
/**
* @file
* Empty module file.
*/
include_once('feeds_import.features.inc');

View File

@@ -0,0 +1,145 @@
<?php
/**
* @file
* Tests for feeds_import feature.
*/
/**
* Test Node import configuration.
*/
class FeedsExamplesNodeTestCase extends FeedsWebTestCase {
/**
* Set up test.
*/
public function setUp() {
parent::setUp(array('feeds_import'));
}
public static function getInfo() {
return array(
'name' => 'Feature: Node import',
'description' => 'Test "Node import" default configuration.',
'group' => 'Feeds',
);
}
/**
* Run tests.
*/
public function test() {
// Import file.
$this->importFile('node', $this->absolutePath() . '/tests/feeds/nodes.csv');
// Assert returning page.
$this->assertText('Created 8 nodes');
$this->assertText('Import CSV files with one or more of these columns: title, body, published, guid.');
$this->assertText('Column guid is mandatory and considered unique: only one item per guid value will be created.');
$this->assertRaw('feeds/nodes.csv');
// Assert created nodes.
$this->drupalGet('node');
$this->assertText('Typi non habent');
$this->assertText('Eodem modo typi');
$this->assertText('Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.');
$this->assertText('Lorem ipsum');
$this->assertText('Ut wisi enim ad minim veniam');
$this->assertText('1976');
// Nam liber tempor has the same GUID as Lorem ipsum.
$this->assertNoText('Nam liber tempor');
// Click through to one node.
$this->clickLink('Lorem ipsum');
$this->assertText('Lorem ipsum');
$this->assertText('Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.');
$this->assertText('Anonymous');
// Assert DB status as is and again after an additional import.
for ($i = 0; $i < 2; $i++) {
$count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
$this->assertEqual($count, 8, 'Found correct number of items.');
$count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article' AND status = 1 AND uid = 0")->fetchField();
$this->assertEqual($count, 8, 'Found correct number of items.');
// Do not filter on type intentionally. There shouldn't be more than 8 nodes total.
$count = db_query("SELECT COUNT(*) FROM {node_revision}")->fetchField();
$this->assertEqual($count, 8, 'Found correct number of items.');
// Import again. Feeds only updates items that haven't changed. However,
// there are 2 different items with the same GUID in nodes.csv.
// Therefore, feeds will show updates to 2 nodes.
$this->drupalPost('import/node/import', array(), 'Import');
$this->assertText('Updated 2 nodes');
}
// Remove all nodes.
$this->drupalPost('import/node/delete-items', array(), 'Delete');
$this->assertText('Deleted 8 nodes');
// Import once again.
$this->drupalPost('import/node/import', array(), 'Import');
$this->assertText('Created 8 nodes');
// Import a similar file with changes in 4 records. Feeds should report 6
// Updated Article nodes (4 changed records, 2 records sharing a GUID
// subsequently being updated).
$this->importFile('node', $this->absolutePath() . '/tests/feeds/nodes_changes.csv');
$this->assertText('Updated 6 nodes');
// Import a larger file with more records.
$this->importFile('node', $this->absolutePath() . '/tests/feeds/many_nodes.csv');
$this->assertText('Created 71 nodes');
// Remove all nodes.
$this->drupalPost('import/node/delete-items', array(), 'Delete');
$this->assertText('Deleted 79 nodes');
// Import once again.
$this->drupalPost('import/node/import', array(), 'Import');
$this->assertText('Created 79 nodes');
$this->assertText('Updated 7 nodes');
// Import a tab separated file.
$this->drupalPost('import/node/delete-items', array(), 'Delete');
$edit = array(
'files[feeds]' => $this->absolutePath() . '/tests/feeds/nodes.tsv',
'feeds[FeedsCSVParser][delimiter]' => "TAB",
);
$this->drupalPost('import/node', $edit, 'Import');
$this->assertText('Created 8 nodes');
}
}
/**
* Test User import configuration.
*/
class FeedsExamplesUserTestCase extends FeedsWebTestCase {
public static function getInfo() {
return array(
'name' => 'Feature: User import',
'description' => 'Test "User import" default configuration.',
'group' => 'Feeds',
);
}
public function setUp() {
parent::setUp(array('feeds_import'));
}
/**
* Run tests.
*/
public function test() {
// Import CSV file.
$this->importFile('user', $this->absolutePath() . '/tests/feeds/users.csv');
// Assert result.
$this->assertText('Created 3 users');
// 1 user has an invalid email address.
$this->assertText('Failed importing 2 users');
$this->drupalGet('admin/people');
$this->assertText('Morticia');
$this->assertText('Fester');
$this->assertText('Gomez');
}
}