You are here

public function NodeImportTestCase::nodeImportCreateTask in Node import 6

Create an import task by going through the form.

Note that the user needs to be logged in. Also note that this will not start the import. You will need to run $this->nodeImportDoAllTasks() for this which will try to finish all import tasks.

$data['file'] needs to be a full real path to a file.

Parameters

$data: Array of data to submit.

Return value

Import task id or FALSE if it fails.

1 call to NodeImportTestCase::nodeImportCreateTask()
NodeImportNode::testBasicNode in tests/supported/node.test
Test import of basic node.

File

tests/NodeImportTestCase.php, line 98
DrupalWebTestCase wrapper with some extra functions to ease the development of node_import tests.

Class

NodeImportTestCase
@file DrupalWebTestCase wrapper with some extra functions to ease the development of node_import tests.

Code

public function nodeImportCreateTask($data) {
  $defaults = array(
    'type' => '',
    'file' => '',
    'file_options' => array(),
    'map' => array(),
    'options' => array(),
    'defaults' => array(),
  );
  $data = array_merge($defaults, $data);
  $step = 1;
  $steps = 8;
  $this
    ->drupalPost('admin/content/node_import/add', array(), t('Next'));
  $title = t('Select content type');
  $expect = t('@title (step @step of @steps)', array(
    '@title' => $title,
    '@step' => $step,
    '@steps' => $steps,
  ));
  if (!$this
    ->assertRaw($expect, t('%title found.', array(
    '%title' => $title,
  )), 'Node import')) {
    return FALSE;
  }
  $step++;
  $this
    ->drupalPost(NULL, array(
    'type' => $data['type'],
  ), t('Next'));
  $title = t('Select file');
  $expect = t('@title (step @step of @steps)', array(
    '@title' => $title,
    '@step' => $step,
    '@steps' => $steps,
  ));
  if (!$this
    ->assertRaw($expect, t('%title found.', array(
    '%title' => $title,
  )), 'Node import')) {
    return FALSE;
  }
  $step++;
  $this
    ->drupalPost(NULL, array(
    'files[file_upload]' => realpath($data['file']),
  ), t('Upload file'));
  $title = t('New file uploaded');
  $expect = t('New file %name uploaded to %path.', array(
    '%name' => basename($data['file']),
    '%path' => node_import_directory() . basename($data['file']),
  ));
  if (!$this
    ->assertRaw($expect, t('%title found.', array(
    '%title' => $title,
  )), 'Node import')) {
    return FALSE;
  }
  $this
    ->drupalPost(NULL, array(), t('Next'));
  $title = t('Set file options');
  $expect = t('@title (step @step of @steps)', array(
    '@title' => $title,
    '@step' => $step,
    '@steps' => $steps,
  ));
  if (!$this
    ->assertRaw($expect, t('%title found.', array(
    '%title' => $title,
  )), 'Node import')) {
    return FALSE;
  }
  $step++;
  $this
    ->drupalPost(NULL, $data['file_options'], t('Next'));
  $title = t('Map file columns');
  $expect = t('@title (step @step of @steps)', array(
    '@title' => $title,
    '@step' => $step,
    '@steps' => $steps,
  ));
  if (!$this
    ->assertRaw($expect, t('%title found.', array(
    '%title' => $title,
  )), 'Node import')) {
    return FALSE;
  }
  $step++;
  $this
    ->drupalPost(NULL, $data['map'], t('Next'));
  $title = t('Set import options');
  $expect = t('@title (step @step of @steps)', array(
    '@title' => $title,
    '@step' => $step,
    '@steps' => $steps,
  ));
  if (!$this
    ->assertRaw($expect, t('%title found.', array(
    '%title' => $title,
  )), 'Node import')) {
    return FALSE;
  }
  $step++;
  $this
    ->drupalPost(NULL, $data['options'], t('Next'));
  $title = t('Set default values');
  $expect = t('@title (step @step of @steps)', array(
    '@title' => $title,
    '@step' => $step,
    '@steps' => $steps,
  ));
  if (!$this
    ->assertRaw($expect, t('%title found.', array(
    '%title' => $title,
  )), 'Node import')) {
    return FALSE;
  }
  $step++;
  $this
    ->drupalPost(NULL, $data['defaults'], t('Next'));
  $title = t('Preview import');
  $expect = t('@title (step @step of @steps)', array(
    '@title' => $title,
    '@step' => $step,
    '@steps' => $steps,
  ));
  if (!$this
    ->assertRaw($expect, t('%title found.', array(
    '%title' => $title,
  )), 'Node import')) {
    return FALSE;
  }
  $step++;
  $this
    ->drupalPost(NULL, array(), t('Next'));
  $title = t('Start import');
  $expect = t('@title (step @step of @steps)', array(
    '@title' => $title,
    '@step' => $step,
    '@steps' => $steps,
  ));
  if (!$this
    ->assertRaw($expect, t('%title found.', array(
    '%title' => $title,
  )), 'Node import')) {
    return FALSE;
  }
  $step++;
  $this
    ->drupalPost(NULL, array(), t('Start import'));
  $url = url('admin/content/node_import/', array(
    'absolute' => TRUE,
  ));
  if (!$this
    ->assertTrue(strpos($this
    ->getUrl(), $url) === 0, t('Redirected to import progress page.'), 'Node import')) {
    return FALSE;
  }
  $taskid = substr($this
    ->getUrl(), strlen($url));
  $this
    ->pass(t('Import task %taskid created.', array(
    '%taskid' => $taskid,
  )), 'Node import');
  return $taskid;
}