Projet

Général

Profil

Paste
Télécharger (6,18 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / tests / feeds_mapper_path.test @ 76df55b7

1
<?php
2

    
3
/**
4
 * @file
5
 * Test case for path alias mapper path.inc.
6
 */
7

    
8
/**
9
 * Class for testing Feeds <em>path</em> mapper.
10
 */
11
class FeedsMapperPathTestCase extends FeedsMapperTestCase {
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'Mapper: Path',
15
      'description' => 'Test Feeds Mapper support for path aliases.',
16
      'group' => 'Feeds',
17
    );
18
  }
19

    
20
  public function setUp() {
21
    parent::setUp(array('path'));
22
  }
23

    
24
  /**
25
   * Basic test loading a single entry CSV file.
26
   */
27
  public function testNodeAlias() {
28

    
29
    // Create importer configuration.
30
    $this->createImporterConfiguration($this->randomName(), 'path_test');
31
    $this->setPlugin('path_test', 'FeedsFileFetcher');
32
    $this->setPlugin('path_test', 'FeedsCSVParser');
33
    $this->addMappings('path_test', array(
34
      0 => array(
35
        'source' => 'Title',
36
        'target' => 'title',
37
      ),
38
      1 => array(
39
        'source' => 'path',
40
        'target' => 'path_alias',
41
      ),
42
      2 => array(
43
        'source' => 'GUID',
44
        'target' => 'guid',
45
        'unique' => TRUE,
46
      ),
47
    ));
48

    
49
    // Turn on update existing.
50
    $this->setSettings('path_test', 'FeedsNodeProcessor', array('update_existing' => 2));
51

    
52
    // Import RSS file.
53
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
54
    $this->assertText('Created 9 nodes');
55

    
56
    $aliases = array();
57

    
58
    for ($i = 1; $i <= 9; $i++) {
59
      $aliases[] = "path$i";
60
    }
61

    
62
    $this->assertAliasCount($aliases);
63

    
64
    // Adding a mapping will force update.
65
    $this->addMappings('path_test', array(
66
      3 => array(
67
        'source' => 'fake',
68
        'target' => 'body',
69
      ),
70
    ));
71
    // Import RSS file.
72
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
73
    $this->assertText('Updated 9 nodes');
74

    
75
    // Check that duplicate aliases are not created.
76
    $this->assertAliasCount($aliases);
77
  }
78

    
79
  /**
80
   * Test support for term aliases.
81
   */
82
  public function testTermAlias() {
83

    
84
    // Create importer configuration.
85
    $this->createImporterConfiguration($this->randomName(), 'path_test');
86
    $this->setPlugin('path_test', 'FeedsFileFetcher');
87
    $this->setPlugin('path_test', 'FeedsCSVParser');
88
    $this->setPlugin('path_test', 'FeedsTermProcessor');
89

    
90
    // Create vocabulary.
91
    $edit = array(
92
      'name' => 'Addams vocabulary',
93
      'machine_name' => 'addams',
94
    );
95
    $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
96

    
97
    $this->setSettings('path_test', 'FeedsTermProcessor', array('bundle' => 'addams', 'update_existing' => 2));
98

    
99
    // Add mappings.
100
    $this->addMappings('path_test', array(
101
      0 => array(
102
        'source' => 'Title',
103
        'target' => 'name',
104
      ),
105
      1 => array(
106
        'source' => 'path',
107
        'target' => 'path_alias',
108
      ),
109
      2 => array(
110
        'source' => 'GUID',
111
        'target' => 'guid',
112
        'unique' => TRUE,
113
      ),
114
    ));
115

    
116
    // Import RSS file.
117
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
118
    $this->assertText('Created 9 terms');
119

    
120
    $aliases = array();
121

    
122
    for ($i = 1; $i <= 9; $i++) {
123
      $aliases[] = "path$i";
124
    }
125

    
126
    $this->assertAliasCount($aliases);
127

    
128
    // Adding a mapping will force update.
129
    $this->addMappings('path_test', array(
130
      3 => array(
131
        'source' => 'fake',
132
        'target' => 'description',
133
      ),
134
    ));
135
    // Import RSS file.
136
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
137
    $this->assertText('Updated 9 terms');
138

    
139
    // Check that duplicate aliases are not created.
140
    $this->assertAliasCount($aliases);
141
  }
142

    
143
  public function assertAliasCount($aliases) {
144
    $in_db = db_select('url_alias', 'a')
145
      ->fields('a')
146
      ->condition('a.alias', $aliases)
147
      ->execute()
148
      ->fetchAll();
149

    
150
    $this->assertEqual(count($in_db), count($aliases), 'Correct number of aliases in db.');
151
  }
152
}
153

    
154
/**
155
 * Class for testing Feeds <em>path</em> mapper with pathauto.module.
156
 */
157
class FeedsMapperPathPathautoTestCase extends FeedsMapperTestCase {
158
  public static function getInfo() {
159
    return array(
160
      'name' => 'Mapper: Path with pathauto',
161
      'description' => 'Test Feeds Mapper support for path aliases and pathauto.',
162
      'group' => 'Feeds',
163
      'dependencies' => array('pathauto'),
164
    );
165
  }
166

    
167
  public function setUp() {
168
    parent::setUp(array('pathauto'));
169
  }
170

    
171
  /**
172
   * Basic for allowing pathauto to override the alias.
173
   */
174
  public function test() {
175

    
176
    // Create importer configuration.
177
    $this->createImporterConfiguration($this->randomName(), 'path_test');
178
    $this->setPlugin('path_test', 'FeedsFileFetcher');
179
    $this->setPlugin('path_test', 'FeedsCSVParser');
180
    $this->addMappings('path_test', array(
181
      0 => array(
182
        'source' => 'Title',
183
        'target' => 'title',
184
        'unique' => FALSE,
185
      ),
186
      1 => array(
187
        'source' => 'does_not_exist',
188
        'target' => 'path_alias',
189
        'pathauto_override' => TRUE,
190
      ),
191
      2 => array(
192
        'source' => 'GUID',
193
        'target' => 'guid',
194
        'unique' => TRUE,
195
      ),
196
    ));
197

    
198
    // Turn on update existing.
199
    $this->setSettings('path_test', 'FeedsNodeProcessor', array('update_existing' => 2));
200

    
201
    // Import RSS file.
202
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
203
    $this->assertText('Created 9 nodes');
204

    
205
    $aliases = array();
206

    
207
    for ($i = 1; $i <= 9; $i++) {
208
      $aliases[] = "content/pathauto$i";
209
    }
210

    
211
    $this->assertAliasCount($aliases);
212

    
213
    // Adding a mapping will force update.
214
    $this->addMappings('path_test', array(
215
      3 => array(
216
        'source' => 'fake',
217
        'target' => 'body',
218
      ),
219
    ));
220
    // Import RSS file.
221
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
222
    $this->assertText('Updated 9 nodes');
223

    
224
    // Check that duplicate aliases are not created.
225
    $this->assertAliasCount($aliases);
226
  }
227

    
228
  public function assertAliasCount($aliases) {
229
    $in_db = db_query("SELECT * FROM {url_alias} WHERE alias IN (:aliases)", array(':aliases' => $aliases))->fetchAll();
230
    $this->assertEqual(count($in_db), count($aliases), 'Correct number of aliases in db.');
231
  }
232
}