You are here

public function FeedsMapperPathTest::testNodeAlias in Feeds 8.2

Basic test loading a single entry CSV file.

File

lib/Drupal/feeds/Tests/FeedsMapperPathTest.php, line 39
Test case for path alias mapper path.inc.

Class

FeedsMapperPathTest
Class for testing Feeds <em>path</em> mapper.

Namespace

Drupal\feeds\Tests

Code

public function testNodeAlias() {

  // Create importer configuration.
  $this
    ->createImporterConfiguration($this
    ->randomName(), 'path_test');
  $this
    ->setPlugin('path_test', 'file');
  $this
    ->setPlugin('path_test', 'csv');
  $this
    ->addMappings('path_test', array(
    0 => array(
      'source' => 'Title',
      'target' => 'title',
    ),
    1 => array(
      'source' => 'path',
      'target' => 'path_alias',
    ),
    2 => array(
      'source' => 'GUID',
      'target' => 'guid',
      'unique' => TRUE,
    ),
  ));

  // Turn on update existing.
  $this
    ->setSettings('path_test', 'node', 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(
    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);
}