Projet

Général

Profil

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

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

1
<?php
2

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

    
8
/**
9
 * Test case for path alias mapper path.inc.
10
 */
11
class FeedsMapperPathTestCase extends FeedsMapperTestCase {
12

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

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

    
31
  /**
32
   * Basic test loading a single entry CSV file.
33
   */
34
  public function testNodeAlias() {
35
    // Create importer configuration.
36
    $this->createImporterConfiguration($this->randomName(), 'path_test');
37
    $this->setPlugin('path_test', 'FeedsFileFetcher');
38
    $this->setPlugin('path_test', 'FeedsCSVParser');
39
    $this->addMappings('path_test', array(
40
      0 => array(
41
        'source' => 'Title',
42
        'target' => 'title',
43
      ),
44
      1 => array(
45
        'source' => 'path',
46
        'target' => 'path_alias',
47
      ),
48
      2 => array(
49
        'source' => 'GUID',
50
        'target' => 'guid',
51
        'unique' => TRUE,
52
      ),
53
    ));
54

    
55
    // Turn on update existing.
56
    $this->setSettings('path_test', 'FeedsNodeProcessor', array('update_existing' => 2));
57

    
58
    // Import RSS file.
59
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
60
    $this->assertText('Created 9 nodes');
61

    
62
    $aliases = array();
63

    
64
    for ($i = 1; $i <= 9; $i++) {
65
      $aliases[] = "path$i";
66
    }
67

    
68
    $this->assertAliasCount($aliases);
69

    
70
    // Adding a mapping will force update.
71
    $this->addMappings('path_test', array(
72
      3 => array(
73
        'source' => 'fake',
74
        'target' => 'body',
75
      ),
76
    ));
77
    // Import RSS file.
78
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
79
    $this->assertText('Updated 9 nodes');
80

    
81
    // Check that duplicate aliases are not created.
82
    $this->assertAliasCount($aliases);
83
  }
84

    
85
  /**
86
   * Test support for term aliases.
87
   */
88
  public function testTermAlias() {
89
    // Create importer configuration.
90
    $this->createImporterConfiguration($this->randomName(), 'path_test');
91
    $this->setPlugin('path_test', 'FeedsFileFetcher');
92
    $this->setPlugin('path_test', 'FeedsCSVParser');
93
    $this->setPlugin('path_test', 'FeedsTermProcessor');
94

    
95
    // Create vocabulary.
96
    $edit = array(
97
      'name' => 'Addams vocabulary',
98
      'machine_name' => 'addams',
99
    );
100
    $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
101

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

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

    
121
    // Import RSS file.
122
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
123
    $this->assertText('Created 9 terms');
124

    
125
    $aliases = array();
126

    
127
    for ($i = 1; $i <= 9; $i++) {
128
      $aliases[] = "path$i";
129
    }
130

    
131
    $this->assertAliasCount($aliases);
132

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

    
144
    // Check that duplicate aliases are not created.
145
    $this->assertAliasCount($aliases);
146
  }
147

    
148
  /**
149
   * {@inheritdoc}
150
   */
151
  public function assertAliasCount($aliases) {
152
    $in_db = db_select('url_alias', 'a')
153
      ->fields('a')
154
      ->condition('a.alias', $aliases)
155
      ->execute()
156
      ->fetchAll();
157

    
158
    $this->assertEqual(count($in_db), count($aliases), 'Correct number of aliases in db.');
159
  }
160

    
161
}
162

    
163
/**
164
 * Class for testing Feeds <em>path</em> mapper with pathauto.module.
165
 */
166
class FeedsMapperPathPathautoTestCase extends FeedsMapperTestCase {
167

    
168
  /**
169
   * {@inheritdoc}
170
   */
171
  public static function getInfo() {
172
    return array(
173
      'name' => 'Mapper: Path with pathauto',
174
      'description' => 'Test Feeds Mapper support for path aliases and pathauto.',
175
      'group' => 'Feeds',
176
      'dependencies' => array('pathauto'),
177
    );
178
  }
179

    
180
  /**
181
   * {@inheritdoc}
182
   */
183
  public function setUp() {
184
    parent::setUp(array('pathauto'));
185
  }
186

    
187
  /**
188
   * Basic for allowing pathauto to override the alias.
189
   */
190
  public function test() {
191
    // Create importer configuration.
192
    $this->createImporterConfiguration($this->randomName(), 'path_test');
193
    $this->setPlugin('path_test', 'FeedsFileFetcher');
194
    $this->setPlugin('path_test', 'FeedsCSVParser');
195
    $this->addMappings('path_test', array(
196
      0 => array(
197
        'source' => 'Title',
198
        'target' => 'title',
199
        'unique' => FALSE,
200
      ),
201
      1 => array(
202
        'source' => 'does_not_exist',
203
        'target' => 'path_alias',
204
        'pathauto_override' => TRUE,
205
      ),
206
      2 => array(
207
        'source' => 'GUID',
208
        'target' => 'guid',
209
        'unique' => TRUE,
210
      ),
211
    ));
212

    
213
    // Turn on update existing.
214
    $this->setSettings('path_test', 'FeedsNodeProcessor', array('update_existing' => 2));
215

    
216
    // Import RSS file.
217
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
218
    $this->assertText('Created 9 nodes');
219

    
220
    $aliases = array();
221

    
222
    for ($i = 1; $i <= 9; $i++) {
223
      $aliases[] = "content/pathauto$i";
224
    }
225

    
226
    $this->assertAliasCount($aliases);
227

    
228
    // Adding a mapping will force update.
229
    $this->addMappings('path_test', array(
230
      3 => array(
231
        'source' => 'fake',
232
        'target' => 'body',
233
      ),
234
    ));
235
    // Import RSS file.
236
    $this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
237
    $this->assertText('Updated 9 nodes');
238

    
239
    // Check that duplicate aliases are not created.
240
    $this->assertAliasCount($aliases);
241
  }
242

    
243
  /**
244
   * {@inheritdoc}
245
   */
246
  public function assertAliasCount($aliases) {
247
    $in_db = db_query("SELECT * FROM {url_alias} WHERE alias IN (:aliases)", array(':aliases' => $aliases))->fetchAll();
248
    $this->assertEqual(count($in_db), count($aliases), 'Correct number of aliases in db.');
249
  }
250

    
251
}