You are here

protected function FeedsParaMapperWebTestCase::import in Feeds Paragraphs 7

Starts importing.

  • Maps a paragraph field to a source.
  • Imports node to a Paragraphs field.

Parameters

string $path: The csv file path relative to the project root directory.

bool $updating: Whether we are updating nodes or creating new ones.

bool $map: Whether we should also map or just import.

3 calls to FeedsParaMapperWebTestCase::import()
FeedsParaMapperNestedImportTestCase::testNestedImport in tests/importing.test
Test importing nodes with nested paragraphs fields.
FeedsParaMapperSingleValueTestCase::testImport in tests/importing.test
Test importing nodes with paragraphs field value.
FeedsParaMapperWebTestCase::multiImport in tests/FeedsParaMapperWebTestCase.test
Tests Multi-valued fields importing.

File

tests/FeedsParaMapperWebTestCase.test, line 382
Common functionality for all Paragraphs Mapper tests.

Class

FeedsParaMapperWebTestCase
Test basic functionality via DrupalWebTestCase.

Code

protected function import($path = NULL, $updating = FALSE, $map = TRUE) {
  if ($map) {

    // Map the id field:
    $targets = array();
    $multi = $this->multiValued || $this->multiValuedParagraph;
    foreach ($this->bundles[0]['fields'] as $field) {
      if ($multi) {
        $targets = array_merge($targets, $field['mapping_multiple']);
      }
      else {
        $targets = array_merge($targets, $field['mapping']);
      }
    }
    $this
      ->map($targets);
    if ($multi) {
      foreach ($targets as $source => $target) {
        $this
          ->addTamperPlugins($source);
      }
    }
  }

  // Import content:
  $this
    ->drupalGet('import/' . $this->importer);
  if (!isset($path)) {
    $path = '/tests/assets/content.csv';
  }
  $file = $this
    ->getProjectPath() . $path;
  $edit = array(
    'files[feeds]' => $file,
  );
  $this
    ->drupalPost(NULL, $edit, "Import");
  $text = $updating ? 'Updated 1 node.' : 'Created 1 node.';
  $this
    ->assertText($text);
}