Newer
Older
<?php
// $Id$
/**
* @file
* Tests for plugins/FeedsUserProcessor.inc
*/
// Require FeedsWebTestCase class definition.
require_once(dirname(__FILE__) .'/feeds.test.inc');
/**
* Test aggregating a feed as data records.
*/
class FeedsCSVtoUsersTest extends FeedsWebTestCase {
/**
* Describe this test.
*/
public function getInfo() {
return array(
'name' => t('CSV import to users'),
'description' => t('Tests a standalone import configuration that uses file fetcher and CSV parser to import users from a CSV file.'),
'group' => t('Feeds'),
);
}
/**
* Set up test.
*/
public function setUp() {
Alex Barth
committed
parent::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler');
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
$this->drupalLogin(
$this->drupalCreateUser(
array(
'administer feeds', 'administer users',
)
)
);
}
/**
* Test node creation, refreshing/deleting feeds and feed items.
*/
public function test() {
// Create an importer.
$this->createImporterConfiguration('User import', 'user_import');
// Set and configure plugins.
$this->setPlugin('user_import', 'FeedsFileFetcher');
$this->setPlugin('user_import', 'FeedsCSVParser');
$this->setPlugin('user_import', 'FeedsUserProcessor');
// Go to mapping page and create a couple of mappings.
$mappings = array(
'0' => array(
'source' => 'name',
'target' => 'name',
'unique' => 0,
),
'1' => array(
'source' => 'mail',
'target' => 'mail',
'unique' => 1,
),
'2' => array(
'source' => 'since',
'target' => 'created',
'unique' => FALSE,
),
);
$this->addMappings('user_import', $mappings);
// Use standalone form.
$edit = array(
'content_type' => '',
);
$this->drupalPost('admin/structure/feeds/edit/user_import/settings', $edit, 'Save');
// Create roles and assign one of them to the users to be imported.
$manager_rid = $this->drupalCreateRole(array('access content'), 'manager');
$admin_rid = $this->drupalCreateRole(array('access content'), 'administrator');
$edit = array(
"roles[$manager_rid]" => TRUE,
"roles[$admin_rid]" => FALSE,
);
$this->setSettings('user_import', 'FeedsUserProcessor', $edit);
// Import CSV file.
$this->importFile('user_import', $this->absolutePath() .'/tests/feeds/users.csv');
// Assert result.
$this->assertText('Created 4 users.');
// 1 user has an invalid email address, all users should be assigned
// the manager role.
$this->assertText('There was 1 user that could not be imported because either their name or their email was empty or not valid. Check import data and mapping settings on User processor.');
$this->drupalGet('admin/user/user');
$this->assertText('Morticia');
$this->assertText('Fester');
$this->assertText('Gomez');
$this->assertText('Pugsley');
$count = db_query("SELECT count(*) FROM {users_roles} WHERE rid = :rid", array(':rid' => $manager_rid))->fetchField();
$this->assertEqual($count, 4, t('All imported users were assigned the manager role.'));
$count = db_query("SELECT count(*) FROM {users_roles} WHERE rid = :rid", array(':rid' => $admin_rid))->fetchField();
$this->assertEqual($count, 0, t('No imported user was assigned the administrator role.'));
// @todo Test status setting, update existing and role settings.
}
}