Newer
Older
* Contains FeedsMapperPathTestCase.
* Test case for path alias mapper path.inc.
*/
class FeedsMapperPathTestCase extends FeedsMapperTestCase {
public static function getInfo() {
return array(
'name' => 'Mapper: Path',
'description' => 'Test Feeds Mapper support for path aliases.',
'group' => 'Feeds',
);
}
public function setUp() {
parent::setUp(array('path'));
}
/**
* Basic test loading a single entry CSV file.
*/
// Create importer configuration.
$this->createImporterConfiguration($this->randomName(), 'path_test');
$this->setPlugin('path_test', 'FeedsFileFetcher');
$this->setPlugin('path_test', 'FeedsCSVParser');
$this->addMappings('path_test', array(
niklas
committed
0 => array(
'source' => 'Title',
'target' => 'title',
),
niklas
committed
1 => array(
'source' => 'path',
'target' => 'path_alias',
),
niklas
committed
2 => array(
'source' => 'GUID',
'target' => 'guid',
'unique' => TRUE,
),
));
// Turn on update existing.
$this->setSettings('path_test', 'FeedsNodeProcessor', array('update_existing' => 2));
// Import RSS file.
$this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
$this->assertText('Created 9 nodes');
$aliases = array();
for ($i = 1; $i <= 9; $i++) {
$aliases[] = "path$i";
}
$this->assertAliasCount($aliases);
// Adding a mapping will force update.
$this->addMappings('path_test', array(
niklas
committed
3 => array(
'source' => 'fake',
'target' => 'body',
),
));
// Import RSS file.
$this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
$this->assertText('Updated 9 nodes');
// Check that duplicate aliases are not created.
$this->assertAliasCount($aliases);
}
/**
* Test support for term aliases.
*/
public function testTermAlias() {
// Create importer configuration.
$this->createImporterConfiguration($this->randomName(), 'path_test');
$this->setPlugin('path_test', 'FeedsFileFetcher');
$this->setPlugin('path_test', 'FeedsCSVParser');
$this->setPlugin('path_test', 'FeedsTermProcessor');
// Create vocabulary.
$edit = array(
'name' => 'Addams vocabulary',
'machine_name' => 'addams',
);
$this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
$this->setSettings('path_test', 'FeedsTermProcessor', array('bundle' => 'addams', 'update_existing' => 2));
$this->addMappings('path_test', array(
niklas
committed
0 => array(
'source' => 'Title',
'target' => 'name',
),
niklas
committed
1 => array(
'source' => 'path',
'target' => 'path_alias',
),
niklas
committed
2 => array(
'source' => 'GUID',
'target' => 'guid',
'unique' => TRUE,
),
));
// Import RSS file.
$this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
$this->assertText('Created 9 terms');
$aliases = array();
for ($i = 1; $i <= 9; $i++) {
$aliases[] = "path$i";
}
$this->assertAliasCount($aliases);
// Adding a mapping will force update.
$this->addMappings('path_test', array(
niklas
committed
3 => array(
'source' => 'fake',
'target' => 'description',
),
));
// Import RSS file.
$this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
$this->assertText('Updated 9 terms');
// Check that duplicate aliases are not created.
$this->assertAliasCount($aliases);
}
public function assertAliasCount($aliases) {
$in_db = db_select('url_alias', 'a')
->fields('a')
->condition('a.alias', $aliases)
->execute()
->fetchAll();
$this->assertEqual(count($in_db), count($aliases), 'Correct number of aliases in db.');
}
}
/**
* Class for testing Feeds <em>path</em> mapper with pathauto.module.
*/
class FeedsMapperPathPathautoTestCase extends FeedsMapperTestCase {
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
public static function getInfo() {
return array(
'name' => 'Mapper: Path with pathauto',
'description' => 'Test Feeds Mapper support for path aliases and pathauto.',
'group' => 'Feeds',
'dependencies' => array('pathauto'),
);
}
public function setUp() {
parent::setUp(array('pathauto'));
}
/**
* Basic for allowing pathauto to override the alias.
*/
public function test() {
// Create importer configuration.
$this->createImporterConfiguration($this->randomName(), 'path_test');
$this->setPlugin('path_test', 'FeedsFileFetcher');
$this->setPlugin('path_test', 'FeedsCSVParser');
$this->addMappings('path_test', array(
0 => array(
'source' => 'Title',
'target' => 'title',
'unique' => FALSE,
),
1 => array(
'source' => 'does_not_exist',
'target' => 'path_alias',
'pathauto_override' => TRUE,
),
2 => array(
'source' => 'GUID',
'target' => 'guid',
'unique' => TRUE,
),
));
// Turn on update existing.
$this->setSettings('path_test', 'FeedsNodeProcessor', array('update_existing' => 2));
// Import RSS file.
$this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
$this->assertText('Created 9 nodes');
$aliases = array();
for ($i = 1; $i <= 9; $i++) {
$aliases[] = "content/pathauto$i";
}
$this->assertAliasCount($aliases);
// Adding a mapping will force update.
$this->addMappings('path_test', array(
3 => array(
'source' => 'fake',
'target' => 'body',
),
));
// Import RSS file.
$this->importFile('path_test', $this->absolutePath() . '/tests/feeds/path_alias.csv');
$this->assertText('Updated 9 nodes');
// Check that duplicate aliases are not created.
$this->assertAliasCount($aliases);
}
public function assertAliasCount($aliases) {
$in_db = db_query("SELECT * FROM {url_alias} WHERE alias IN (:aliases)", array(':aliases' => $aliases))->fetchAll();
$this->assertEqual(count($in_db), count($aliases), 'Correct number of aliases in db.');
}