Projet

Général

Profil

Paste
Télécharger (4,16 ko) Statistiques
| Branche: | Révision:

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

1
<?php
2

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

    
8
/**
9
 * Test cases for Feeds mapping configuration form.
10
 */
11
class FeedsMapperConfigTestCase extends FeedsMapperTestCase {
12

    
13
  /**
14
   * {@inheritdoc}
15
   */
16
  public static function getInfo() {
17
    return array(
18
      'name' => 'Mapper: Config',
19
      'description' => 'Test the mapper configuration UI.',
20
      'group' => 'Feeds',
21
    );
22
  }
23

    
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function setUp() {
28
    parent::setUp(array('feeds_tests'));
29
  }
30

    
31
  /**
32
   * Basic test of mapping configuration.
33
   */
34
  public function test() {
35
    // Create importer configuration.
36
    $this->createImporterConfiguration();
37
    $this->addMappings('syndication', array(
38
      array(
39
        'source' => 'url',
40
        'target' => 'test_target',
41
      ),
42
    ));
43

    
44
    // Click gear to get form.
45
    $this->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_0');
46

    
47
    $second_callback_value = $this->randomString();
48

    
49
    // Set some settings.
50
    $edit = array(
51
      'config[0][settings][checkbox]' => 1,
52
      'config[0][settings][textfield]' => 'Some text',
53
      'config[0][settings][textarea]' => 'Textarea value: Didery dofffffffffffffffffffffffffffffffffffff',
54
      'config[0][settings][radios]' => 'option1',
55
      'config[0][settings][select]' => 'option4',
56
      'config[0][settings][second_value]' => $second_callback_value,
57
    );
58
    $this->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_0');
59
    $this->assertText(t('* Changes made to target configuration are stored temporarily. Click Save to make your changes permanent.'));
60

    
61
    // Click Save.
62
    $this->drupalPost(NULL, array(), t('Save'));
63

    
64
    // Reload.
65
    $this->drupalGet('admin/structure/feeds/syndication/mapping');
66

    
67
    // See if our settings were saved.
68
    $this->assertText('Checkbox active.');
69
    $this->assertText('Textfield value: Some text');
70
    $this->assertText('Textarea value: Didery dofffffffffffffffffffffffffffffffffffff');
71
    $this->assertText('Radios value: Option 1');
72
    $this->assertText('Select value: Another One');
73
    $this->assertText(t('Second summary: @value', array('@value' => $second_callback_value)));
74

    
75
    // Check that settings are in db.
76
    $config = unserialize(db_query("SELECT config FROM {feeds_importer} WHERE id='syndication'")->fetchField());
77

    
78
    $settings = $config['processor']['config']['mappings'][0];
79
    $this->assertEqual($settings['checkbox'], 1);
80
    $this->assertEqual($settings['textfield'], 'Some text');
81
    $this->assertEqual($settings['textarea'], 'Textarea value: Didery dofffffffffffffffffffffffffffffffffffff');
82
    $this->assertEqual($settings['radios'], 'option1');
83
    $this->assertEqual($settings['select'], 'option4');
84
    $this->assertEqual($settings['second_value'], $second_callback_value);
85

    
86
    // Check that form validation works.
87
    // Click gear to get form.
88
    $this->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_0');
89

    
90
    // Set some settings.
91
    $edit = array(
92
      // Required form item.
93
      'config[0][settings][textfield]' => '',
94
    );
95
    $this->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_0');
96
    $this->assertText('A text field field is required.');
97
    $this->drupalPost(NULL, array(), t('Save'));
98
    // Reload.
99
    $this->drupalGet('admin/structure/feeds/syndication/mapping');
100
    // Value has not changed.
101
    $this->assertText('Textfield value: Some text');
102

    
103
    // Check that multiple mappings work.
104
    $this->addMappings('syndication', array(
105
      1 => array(
106
        'source' => 'url',
107
        'target' => 'test_target',
108
      ),
109
    ));
110
    $this->assertText('Checkbox active.');
111
    $this->assertText('Checkbox inactive.');
112
    // Click gear to get form.
113
    $this->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_1');
114
    // Set some settings.
115
    $edit = array(
116
      'config[1][settings][textfield]' => 'Second mapping text',
117
    );
118
    $this->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_1');
119
    // Click Save.
120
    $this->drupalPost(NULL, array(), t('Save'));
121
    // Reload.
122
    $this->drupalGet('admin/structure/feeds/syndication/mapping');
123
    $this->assertText('Checkbox active.');
124
    $this->assertText('Checkbox inactive.');
125
    $this->assertText('Second mapping text');
126
  }
127

    
128
}