Projet

Général

Profil

Paste
Télécharger (3,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / tests / feeds_mapper_profile.test @ ed9a13f1

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains FeedsMapperProfileTestCase.
6
 */
7

    
8
/**
9
 * Test suite for profile mapper mappers/profile.inc.
10
 */
11
class FeedsMapperProfileTestCase extends FeedsMapperTestCase {
12

    
13
  /**
14
   * {@inheritdoc}
15
   */
16
  public static function getInfo() {
17
    return array(
18
      'name' => 'Mapper: Profile',
19
      'description' => 'Test Feeds Mapper support for profile fields.',
20
      'group' => 'Feeds',
21
    );
22
  }
23

    
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function setUp() {
28
    // Call parent setup with required modules.
29
    parent::setUp(array('profile'));
30
  }
31

    
32
  /**
33
   * Basic test loading a double entry CSV file.
34
   */
35
  public function test() {
36
    // Create profile fields.
37
    $edit = array(
38
      'category' => 'test',
39
      'title' => 'color',
40
      'name' => 'profile_textfield_test',
41
      'register' => 1,
42
    );
43
    $name = $this->drupalPost('admin/config/people/profile/add/textfield', $edit, t('Save field'));
44
    $edit = array(
45
      'category' => 'test',
46
      'title' => 'letter',
47
      'name' => 'profile_select_test',
48
      'options' => 'alpha' . "\n" . 'beta' . "\n" . 'gamma',
49
      'register' => 1,
50
    );
51
    $name = $this->drupalPost('admin/config/people/profile/add/selection', $edit, t('Save field'));
52

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

    
56
    // Set and configure plugins.
57
    $this->setPlugin('profile_import', 'FeedsFileFetcher');
58
    $this->setPlugin('profile_import', 'FeedsCSVParser');
59
    $this->setPlugin('profile_import', 'FeedsUserProcessor');
60

    
61
    // Go to mapping page and create a couple of mappings.
62
    $mappings = array(
63
      '0' => array(
64
        'source' => 'name',
65
        'target' => 'name',
66
        'unique' => 0,
67
      ),
68
      '1' => array(
69
        'source' => 'mail',
70
        'target' => 'mail',
71
        'unique' => 1,
72
      ),
73
      '2' => array(
74
        'source' => 'color',
75
        'target' => 'profile_textfield_test',
76
      ),
77
      '3' => array(
78
        'source' => 'letter',
79
        'target' => 'profile_select_test',
80
      ),
81
    );
82
    $this->addMappings('profile_import', $mappings);
83

    
84
    // Change some of the basic configuration.
85
    $edit = array(
86
      'content_type' => '',
87
      'import_period' => FEEDS_SCHEDULE_NEVER,
88
    );
89
    $this->drupalPost('admin/structure/feeds/profile_import/settings', $edit, 'Save');
90

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

    
95
    // Check the two imported users.
96
    $this->drupalGet('admin/people');
97
    $this->assertText('magna');
98
    $this->assertText('rhoncus');
99

    
100
    $account = user_load_by_name('magna');
101
    $this->assertEqual($account->profile_textfield_test, 'red', 'User profile_textfield_test is correct');
102
    $this->assertEqual($account->profile_select_test, 'alpha', 'User profile_select_test is correct');
103

    
104
    $account = user_load_by_name('rhoncus');
105
    $this->assertEqual($account->profile_textfield_test, 'blue', 'User profile_textfield_test is correct');
106
    $this->assertEqual($account->profile_select_test, 'beta', 'User profile_select_test is correct');
107
  }
108

    
109
}