You are here

class FeedsTamperCSVTestCase in Feeds Tamper 7

Same name and namespace in other branches
  1. 6 tests/feeds_tamper.test \FeedsTamperCSVTestCase

Tests the special case that is FeedsCSVParser.

Hierarchy

Expanded class hierarchy of FeedsTamperCSVTestCase

File

tests/feeds_tamper.test, line 238
Tests for feeds_tamper.module.

View source
class FeedsTamperCSVTestCase extends FeedsTamperWebTestHelper {
  public static function getInfo() {
    return array(
      'name' => 'Special case: CSV parser',
      'description' => 'Tests the special case that is FeedsCSVParser. See <a href="http://drupal.org/node/1133724" target="_blank">#1133724</a>.',
      'group' => 'Feeds Tamper',
    );
  }
  public function test() {
    $importer_name = $this
      ->randomName();
    $importer_id = drupal_strtolower($importer_name);

    // Set up an importer.
    $this
      ->createImporterConfiguration($importer_name, $importer_id);

    // Set and configure plugins and mappings.
    $this
      ->setPlugin($importer_id, 'FeedsCSVParser');

    // We have a space in the source cause that was a problem at one point.
    $mappings = array(
      0 => array(
        'source' => 'a /T~!@#$%^&*()_+`<>;:itle✈',
        'target' => 'title',
      ),
      1 => array(
        'source' => 'a Body.',
        'target' => 'body',
      ),
      2 => array(
        'source' => 'a GUID',
        'target' => 'guid',
        'unique' => TRUE,
      ),
      3 => array(
        'source' => 'Blank source 1',
        'target' => 'uid',
      ),
    );
    $this
      ->addMappings($importer_id, $mappings);

    // Set update existing.
    $this
      ->setSettings($importer_id, 'FeedsNodeProcessor', array(
      'update_existing' => 1,
    ));

    // Test basic plugin adding.
    $settings = array(
      'mode' => 0,
    );
    $id = $this
      ->addTamperPlugin($importer_id, 'a /T~!@#$%^&*()_+`<>;:itle✈', 'convert_case', $settings);
    $id2 = $this
      ->addTamperPlugin($importer_id, 'a Body.', 'convert_case', $settings);

    // Verify that Blank source works for CSV parser.
    $this
      ->addTamperPlugin($importer_id, 'Blank source 1', 'default_value', array(
      'default_value' => $this->admin_user->uid,
    ));
    $path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_tamper') . '/tests/feeds_tamper/';
    $nid = $this
      ->createFeedNode($importer_id, $path . 'csv_test.csv', 'Testing CSV Parser');
    $this
      ->assertText('Basic page Testing CSV Parser has been created.');
    $this
      ->assertText('Created 2 nodes.');
    $this
      ->drupalGet('node');
    $this
      ->assertText('HELLO WORLD');
    $this
      ->assertText('THIS IS A GREAT BODY.');
    $this
      ->assertText('WORLD DOES NOT RESPOND');
    $this
      ->assertText('THIS IS A SAD BODY.');
    $this
      ->disableTamperPlugin($id);
    $this
      ->disableTamperPlugin($id2);
    $this
      ->drupalPost('node/' . $nid . '/import', array(), 'Import');
    $this
      ->assertText('Updated 2 nodes.');
    $this
      ->drupalGet('node');
    $this
      ->assertText('Hello world');
    $this
      ->assertText('This is a great body.');
    $this
      ->assertText('World does not respond');
    $this
      ->assertText('This is a sad body.');
    $this
      ->drupalGet('node/2/edit');
    $this
      ->assertFieldByName('name', $this->admin_user->name);
  }
  public function testRewrite() {
    $importer_name = $this
      ->randomName();
    $importer_id = drupal_strtolower($importer_name);

    // Set up an importer.
    $this
      ->createImporterConfiguration($importer_name, $importer_id);

    // Set and configure plugins and mappings.
    $this
      ->setPlugin($importer_id, 'FeedsCSVParser');

    // We have a space in the source cause that was a problem at one point.
    $mappings = array(
      0 => array(
        'source' => 'a /T~!@#$%^&*()_+`<>;:itle✈',
        'target' => 'title',
      ),
      1 => array(
        'source' => 'a Body.',
        'target' => 'Temporary target 1',
      ),
      2 => array(
        'source' => 'Blank source 1',
        'target' => 'body',
      ),
    );
    $this
      ->addMappings($importer_id, $mappings);

    // Copy the field to the node's body field.
    $this
      ->addTamperPlugin($importer_id, 'Blank source 1', 'rewrite', array(
      'text' => '[a body.]',
    ));
    $path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_tamper') . '/tests/feeds_tamper/';
    $nid = $this
      ->createFeedNode($importer_id, $path . 'csv_test.csv', 'Testing CSV Parser');
    $this
      ->assertText('Basic page Testing CSV Parser has been created.');
    $this
      ->assertText('Created 2 nodes.');
    $this
      ->drupalGet('node');
    $this
      ->assertText('Hello world');
    $this
      ->assertText('This is a great body.');
    $this
      ->assertText('World does not respond');
    $this
      ->assertText('This is a sad body.');
  }

}

Members