class UserImportNodeprofile in User Import 5
Same name and namespace in other branches
- 8 tests/user_import_nodeprofile.test \UserImportNodeprofile
Test import of user data into Profile module
Hierarchy
- class \DrupalTestCase extends \WebTestCase
- class \UserImportTest
- class \UserImportNodeprofile
- class \UserImportTest
Expanded class hierarchy of UserImportNodeprofile
File
- tests/
user_import_nodeprofile.test, line 6
View source
class UserImportNodeprofile extends UserImportTest {
var $modules = array(
'nodeprofile',
'nodefamily',
'subform_element',
'content',
'number',
'optionwidgets',
'text',
'link',
'date',
'date_api',
'node_import',
);
function get_info() {
return array(
'name' => t('Import Users (Nodeprofile)'),
'desc' => t('Test import of user data into Nodeprofile module.'),
'group' => t('User Import'),
);
}
/**
* User with right permissions creates import (with new settings)
* - test import of user data into Nodeprofile module
*/
function testCreateImport() {
$this
->enableModules($this->modules);
$this
->nodeprofileConfiguration();
// $html = $this->drupalGet('node/add/identity');
// var_dump($html);
// Prepare a user to do testing
$this
->get('logout');
// log out first
$this
->drupalLoginUser($this->user_importer);
//$html = $this->drupalGet('admin/user/access');
//var_dump($html);
// Select CSV file (the included example file)
$this
->settingsFileSelect();
// import settings
$this
->importID($this
->getUrl());
// store import ID for later
$settings = array();
$this
->settingsEmailMatch($settings);
$this
->settingsNodeprofileMatch($settings);
$this
->settingsIgnoreFirstLine($settings);
$this
->drupalPostRequest($this
->getUrl(), $settings, 'Import');
// check if users have been imported
$this
->checkNodeprofileExist();
}
/**
* Configure modules
*/
function nodeprofileConfiguration() {
$this->admin_user = $this
->drupalCreateUserRolePerm(array(
'administer users',
'access administration pages',
'administer access control',
'administer site configuration',
'administer content types',
'administer taxonomy',
));
$this
->drupalLoginUser($this->admin_user);
// create Identity content type
$edit = array(
'name' => 'Identity',
'type' => 'identity',
'title_label' => 'Title',
'body_label' => NULL,
'node_options[promote]' => 0,
'nodefamily_max' => 1,
'nodeprofile' => 1,
);
$this
->drupalPostRequest('admin/content/types/add', $edit, t('Save content type'));
// create First Name field
$edit = array(
'label' => 'first_name',
'field_widget_type' => 'text-text',
);
$this
->drupalPostRequest('admin/content/types/identity/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'First Name',
'required' => 1,
);
$this
->drupalPostRequest('admin/content/types/identity/fields/field_first_name', $edit, t('Save field settings'));
// create Last Name field
$edit = array(
'label' => 'last_name',
'field_widget_type' => 'text-text',
);
$this
->drupalPostRequest('admin/content/types/identity/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'Last Name',
'required' => 1,
);
$this
->drupalPostRequest('admin/content/types/identity/fields/field_last_name', $edit, t('Save field settings'));
// create Biography content type
$edit = array(
'name' => 'Biography',
'type' => 'biography',
'title_label' => 'Title',
'body_label' => NULL,
'node_options[promote]' => 0,
'nodefamily_max' => 1,
'nodeprofile' => 1,
);
$this
->drupalPostRequest('admin/content/types/add', $edit, t('Save content type'));
// create CV field
$edit = array(
'label' => 'cv',
'field_widget_type' => 'text-text',
);
$this
->drupalPostRequest('admin/content/types/biography/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'CV',
'required' => 1,
'rows' => 5,
);
$this
->drupalPostRequest('admin/content/types/biography/fields/field_cv', $edit, t('Save field settings'));
// create Interests Vocabulary - TO DO
$edit = array(
'name' => 'Interests',
'nodes[biography]' => 'biography',
'tags' => 1,
);
$this
->drupalPostRequest('admin/content/taxonomy/add/vocabulary', $edit, t('Submit'));
$vocabularies = taxonomy_get_vocabularies('biography');
foreach ($vocabularies as $vocabulary) {
$this->vocabulary_id = $vocabulary->vid;
}
// create Blog field (URL)
$edit = array(
'label' => 'blog',
'field_widget_type' => 'link-link',
);
$this
->drupalPostRequest('admin/content/types/biography/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'Blog',
);
$this
->drupalPostRequest('admin/content/types/biography/fields/field_blog', $edit, t('Save field settings'));
// create Birthday field (date)
$edit = array(
'label' => 'birthday',
'field_widget_type' => 'datestamp-date_text',
);
$this
->drupalPostRequest('admin/content/types/biography/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'Birthday',
);
$this
->drupalPostRequest('admin/content/types/biography/fields/field_birthday', $edit, t('Save field settings'));
// create Contact Details contact type
$edit = array(
'name' => 'Contact Details',
'type' => 'contact_details',
'title_label' => 'Title',
'body_label' => NULL,
'node_options[promote]' => 0,
'nodefamily_max' => 1,
'nodeprofile' => 1,
);
$this
->drupalPostRequest('admin/content/types/add', $edit, t('Save content type'));
// create Can Be Contacted field
$edit = array(
'label' => 'can_be_contacted',
'field_widget_type' => 'number_integer-options_onoff',
);
$this
->drupalPostRequest('admin/content/types/contact-details/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'Can Be Contacted',
'allowed_values' => "0\n\t\t1|Can be contacted",
);
$this
->drupalPostRequest('admin/content/types/contact-details/fields/field_can_be_contacted', $edit, t('Save field settings'));
// create Contact Preference field
$edit = array(
'label' => 'contact_preference',
'field_widget_type' => 'text-options_select',
);
$this
->drupalPostRequest('admin/content/types/contact-details/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'Contact Preference',
'allowed_values' => 'email|email
telephone|telephone
post|post',
);
$this
->drupalPostRequest('admin/content/types/contact-details/fields/field_contact_preference', $edit, t('Save field settings'));
// set access perm for authenticated users to creade profile nodes
$edit = array(
'2[create identity content]' => 'create identity content',
'2[create biography content]' => 'create biography content',
'2[create contact_details content]' => 'create contact_details content',
);
$this
->drupalPostRequest('admin/user/access', $edit, t('Save permissions'));
}
/**
* Match CSV columns to Profile fields
*/
function settingsNodeprofileMatch(&$edit) {
$edit['field_match[0][field_match]'] = 'nodeprofile-identity field_first_name_value';
// First Name
$edit['field_match[1][field_match]'] = 'nodeprofile-identity field_last_name_value';
// Last Name
$edit['field_match[10][field_match]'] = 'nodeprofile-biography field_cv_value';
// CV
$edit['field_match[7][field_match]'] = 'nodeprofile-contact_details field_can_be_contacted_value';
// Contact Permision
$edit['field_match[8][field_match]'] = 'nodeprofile-contact_details field_contact_preference_value';
// Contact Preference
$edit['field_match[9][field_match]'] = 'taxonomy-' . $this->vocabulary_id;
// Interests
$edit['field_match[6][field_match]'] = 'nodeprofile-biography field_blog_url';
// Blog
$edit['field_match[11][field_match]'] = 'nodeprofile-biography field_birthday_value';
// Birthday
}
/**
* Check data in CSV file matches data in profiles
*/
function checkNodeprofileExist() {
$file_path = drupal_get_path('module', 'user_import') . '/sample.txt';
$handle = @fopen($file_path, "r");
$row = 0;
while ($csv = fgetcsv($handle, 1000, ',')) {
if ($row > 0) {
$user = user_load(array(
'mail' => $csv[5],
));
// test each data cell against nodeprofile field content
$identity = node_load(array(
'type' => 'identity',
'uid' => $user->uid,
));
$biography = node_load(array(
'type' => 'biography',
'uid' => $user->uid,
));
$contact_details = node_load(array(
'type' => 'contact_details',
'uid' => $user->uid,
));
//if ($row == 1) var_dump($user);
$this
->assertEqual($identity->field_first_name[0]['value'], $csv[0], "[Compare CSV and Profile data] Row: {$row} Field: First Name");
$this
->assertEqual($identity->field_last_name[0]['value'], $csv[1], "[Compare CSV and Profile data] Row: {$row} Field: Last Name");
$this
->assertEqual($biography->field_blog[0]['url'], $csv[6], "[Compare CSV and Profile data] Row: {$row} Field: Blog");
$this
->assertEqual($contact_details->field_can_be_contacted[0]['value'], $csv[7], "[Compare CSV and Profile data] Row: {$row} Field: Contact Permission");
$this
->assertEqual($contact_details->field_contact_preference[0]['value'], $csv[8], "[Compare CSV and Profile data] Row: {$row} Field: Contact Preference");
$this
->assertEqual($user->profile_interests, $csv[9], "[Compare CSV and Profile data] Row: {$row} Field: Profile Interests");
$this
->assertEqual($biography->field_cv[0]['value'], $csv[10], "[Compare CSV and Profile data] Row: {$row} Field: CV");
$this
->assertEqual($biography->field_birthday[0]['value'], $csv[11], "[Compare CSV and Profile data] Row: {$row} Field: Birthday");
//test interests link on profile page
if (!empty($user->profile_interests)) {
$interests = explode(',', $user->profile_interests);
$this
->drupalGet('profile/profile_interests/' . $interests[0]);
$this
->assertWantedRaw('<a title="View user profile." href="/' . url('user/' . $user->uid) . '">' . $user->name . '</a>', '[Freeform List] User is listed on page about item in list');
}
}
$row++;
}
}
/**
* SimpleTest core method: code run after each and every test method.
*/
function tearDown() {
// delete accounts of users imported
$users_email = $this
->usersList();
foreach ($users_email as $mail) {
$account = user_load(array(
'mail' => $mail,
));
// delete node profile nodes
if (!empty($account)) {
$identity = node_load(array(
'type' => 'identity',
'uid' => $account->uid,
));
$biography = node_load(array(
'type' => 'biography',
'uid' => $account->uid,
));
$contact_details = node_load(array(
'type' => 'contact_details',
'uid' => $account->uid,
));
node_delete($identity->nid);
node_delete($biography->nid);
node_delete($contact_details->nid);
user_delete(array(), $account->uid);
}
}
// delete the import
$import_id = $this
->importID();
$this
->assertTrue(!empty($import_id), t('Import ID: !id', array(
'!id' => $import_id,
)));
_user_import_settings_deletion($import_id);
// delete vocabulary
taxonomy_del_vocabulary($this->vocabulary_id);
// uninstall modules
// - tear down disable doesn't seem to do this
foreach ($this->modules as $module) {
if (function_exists($module . '_uninstall')) {
$result = call_user_func_array($module . '_uninstall', array());
}
}
// delete nodeprofile content types
node_type_delete('dummy');
// (for some reason) the first node_type_delete is completely ignored
node_type_delete('identity');
node_type_delete('biography');
node_type_delete('contact_details');
// Always call the tearDown() function from the parent class.
parent::tearDown();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to different objects. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value only. Otherwise a fail. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and optionally that the error text matches exactly. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and that the error text matches a Perl regular expression. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail. | ||
DrupalTestCase:: |
function | Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct. | ||
DrupalTestCase:: |
function | Confirms that no errors have occurred so far in the test method. | ||
DrupalTestCase:: |
function | Type and class mismatch test. Will pass if class name or underling type does not match the one specified. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have a different value. Otherwise a fail. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the different value or different type. | ||
DrupalTestCase:: |
function | Will be true if the value is set. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Will be true if the value is null. | ||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to the same object. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does… | ||
DrupalTestCase:: |
function | @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site. | ||
DrupalTestCase:: |
function | Create a role / perm combination specified by permissions | ||
DrupalTestCase:: |
function | Creates a user / role / permissions combination specified by permissions | ||
DrupalTestCase:: |
function | @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | @TODO: needs documentation | ||
DrupalTestCase:: |
function | Logs in a user with the internal browser | ||
DrupalTestCase:: |
function | Disables a drupal module | ||
DrupalTestCase:: |
function | Enables a drupal module | ||
DrupalTestCase:: |
function | Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser | ||
DrupalTestCase:: |
function | @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | |||
DrupalTestCase:: |
function | Set a druapl variable and keep track of the changes for tearDown() | ||
DrupalTestCase:: |
function | Generates a random string, to be used as name or whatever | ||
DrupalTestCase:: |
function | Just some info for the reporter | ||
UserImportNodeprofile:: |
property | |||
UserImportNodeprofile:: |
function | * Check data in CSV file matches data in profiles | ||
UserImportNodeprofile:: |
function | |||
UserImportNodeprofile:: |
function | * Configure modules | ||
UserImportNodeprofile:: |
function | * Match CSV columns to Profile fields | ||
UserImportNodeprofile:: |
function |
SimpleTest core method: code run after each and every test method. Overrides UserImportTest:: |
||
UserImportNodeprofile:: |
function | * User with right permissions creates import (with new settings) * - test import of user data into Nodeprofile module | ||
UserImportTest:: |
property | |||
UserImportTest:: |
property | |||
UserImportTest:: |
function | |||
UserImportTest:: |
function | * enable necessary modules | ||
UserImportTest:: |
function | * Store import ID * - set on import settings page, retrieve on later tasks | ||
UserImportTest:: |
function | |||
UserImportTest:: |
function | * Select CSV file (the included example file) | ||
UserImportTest:: |
function | |||
UserImportTest:: |
function | |||
UserImportTest:: |
function | * List of users (email addresses) being imported * To Do - Generate this dynamically, bearing in mind it could be used for stress testing |