Projet

Général

Profil

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

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

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
  public static function getInfo() {
14
    return array(
15
      'name' => 'Mapper: Path',
16
      'description' => 'Test Feeds Mapper support for path aliases.',
17
      'group' => 'Feeds',
18
    );
19
  }
20

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

    
25
  /**
26
   * Basic test loading a single entry CSV file.
27
   */
28
  public function testNodeAlias() {
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
    // Create importer configuration.
84
    $this->createImporterConfiguration($this->randomName(), 'path_test');
85
    $this->setPlugin('path_test', 'FeedsFileFetcher');
86
    $this->setPlugin('path_test', 'FeedsCSVParser');
87
    $this->setPlugin('path_test', 'FeedsTermProcessor');
88

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

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

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

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

    
119
    $aliases = array();
120

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

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

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

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

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

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

    
153
/**
154
 * Class for testing Feeds <em>path</em> mapper with pathauto.module.
155
 */
156
class FeedsMapperPathPathautoTestCase extends FeedsMapperTestCase {
157

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

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

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

    
204
    $aliases = array();
205

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

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

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

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

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

    
232
}