You are here

feeds_mapper_profile.test in Feeds 6

Same filename and directory in other branches
  1. 7.2 tests/feeds_mapper_profile.test
  2. 7 tests/feeds_mapper_profile.test

Test suite for profile mapper mappers/profile.inc.

File

tests/feeds_mapper_profile.test
View source
<?php

module_load_include('test', 'feeds', 'tests/feeds_mapper');

/**
 * @file
 * Test suite for profile mapper mappers/profile.inc.
 */

/**
 * Class for testing Feeds <em>content</em> mapper.
 */
class FeedsMapperProfileTestCase extends FeedsMapperTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Mapper: Profile',
      'description' => 'Test Feeds Mapper support for profile fields.',
      'group' => 'Feeds',
    );
  }
  function setUp() {

    // Call parent setup with required modules.
    parent::setUp(array(
      'profile',
    ));
  }

  /**
   * Basic test loading a doulbe entry CSV file.
   */
  function test() {

    // Create profile fields.
    $edit = array(
      'category' => 'test',
      'title' => 'color',
      'name' => 'profile_textfield_test',
    );
    $name = $this
      ->drupalPost('admin/user/profile/add/textfield', $edit, t('Save field'));
    $edit = array(
      'category' => 'test',
      'title' => 'letter',
      'name' => 'profile_select_test',
      'options' => 'alpha' . "\n" . 'beta' . "\n" . 'gamma',
    );
    $name = $this
      ->drupalPost('admin/user/profile/add/selection', $edit, t('Save field'));

    // Create an importer.
    $this
      ->createImporterConfiguration('Profile import', 'profile_import');

    // Set and configure plugins.
    $this
      ->setPlugin('profile_import', 'FeedsFileFetcher');
    $this
      ->setPlugin('profile_import', 'FeedsCSVParser');
    $this
      ->setPlugin('profile_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' => 'color',
        'target' => 'profile_textfield_test',
        'unique' => FALSE,
      ),
      '3' => array(
        'source' => 'letter',
        'target' => 'profile_select_test',
        'unique' => FALSE,
      ),
    );
    $this
      ->addMappings('profile_import', $mappings);

    // Change some of the basic configuration.
    $edit = array(
      'content_type' => '',
      'import_period' => FEEDS_SCHEDULE_NEVER,
    );
    $this
      ->drupalPost('admin/build/feeds/edit/profile_import/settings', $edit, 'Save');

    // Import CSV file.
    $this
      ->importFile('profile_import', $this
      ->absolutePath() . '/tests/feeds/profile.csv');
    $this
      ->assertText('Created 2 users.');

    // Check the two imported users.
    $this
      ->drupalGet('admin/user/user');
    $this
      ->assertText('magna');
    $this
      ->assertText('rhoncus');
    $account = user_load(array(
      'name' => 'magna',
    ));
    $this
      ->assertEqual($account->profile_textfield_test, 'red', 'User profile_textfield_test is correct');
    $this
      ->assertEqual($account->profile_select_test, 'alpha', 'User profile_select_test is correct');
    $account = user_load(array(
      'name' => 'rhoncus',
    ));
    $this
      ->assertEqual($account->profile_textfield_test, 'blue', 'User profile_textfield_test is correct');
    $this
      ->assertEqual($account->profile_select_test, 'beta', 'User profile_select_test is correct');
  }

}

Classes

Namesort descending Description
FeedsMapperProfileTestCase Class for testing Feeds <em>content</em> mapper.