You are here

location_feeds.node.test in Location Feeds 6

Same filename and directory in other branches
  1. 7 tests/location_feeds.node.test

File

tests/location_feeds.node.test
View source
<?php

/**
 *  @file
 *
 * Test case for location node imports
 *
 * @author: Elliott Foster
 */
module_load_include('inc', 'location_feeds', 'tests/location_feeds.test');
class NodeFeedsMapperLocationTestCase extends FeedsMapperLocationTestCase {
  public static function getInfo() {
    return array(
      'name' => t('Node Locations'),
      'description' => t('Test Feeds Mapper support for Node Location.'),
      'group' => t('Location Feeds'),
    );
  }

  /**
   * Set up the test.
   */
  public function setUp() {

    // Call parent setup with required modules.
    parent::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler', 'location', 'location_node', 'location_feeds', 'content');

    // Create user and login.
    $this
      ->drupalLogin($this
      ->drupalCreateUser(array(
      'administer content types',
      'administer feeds',
      'administer nodes',
      'administer site configuration',
    )));
  }

  /**
   * Basic test loading an RSS feed for nodes with locations.
   */
  public function test() {
    $settings = array();
    $type = $this
      ->createLocationType($settings);

    // Test constants
    $loc = array(
      0 => array(
        'street' => "93 Rue de Rivoli",
        'city' => "Paris",
        'province' => "",
        'country' => "fr",
        'postal_code' => 75001,
      ),
      1 => array(
        'street' => "1600 Amphitheatre Parkway",
        'city' => "Mountain View",
        'province' => "CA",
        'country' => "us",
        'postal_code' => 94043,
      ),
      2 => array(
        'street' => "93 Rue de Rivoli",
        'city' => "Paris",
        'province' => "",
        'country' => "fr",
        'postal_code' => 75001,
      ),
      3 => array(
        'street' => "1600 Amphitheatre Parkway",
        'city' => "Mountain View",
        'province' => "CA",
        'country' => "us",
        'postal_code' => 94043,
      ),
    );

    // Create and configure importer.
    // Create a feed.
    $this
      ->createImporterConfiguration('Location import', 'location_import');

    // Set and configure plugins.
    $this
      ->setSettings('location_import', NULL, array(
      'content_type' => '',
      'import_period' => FEEDS_SCHEDULE_NEVER,
    ));
    $this
      ->setPlugin('location_import', 'FeedsFileFetcher');
    $this
      ->setPlugin('location_import', 'FeedsCSVParser');
    $this
      ->setSettings('location_import', 'FeedsNodeProcessor', array(
      'content_type' => $type,
    ));

    // Go to mapping page and create a couple of mappings.
    $mappings = array(
      array(
        'source' => 'title',
        'target' => 'title',
        'unique' => FALSE,
      ),
      array(
        'source' => 'description',
        'target' => 'body',
        'unique' => FALSE,
      ),
      array(
        'source' => 'timestamp',
        'target' => 'created',
        'unique' => FALSE,
      ),
      array(
        'source' => 'guid',
        'target' => 'guid',
        'unique' => TRUE,
      ),
      array(
        'source' => 'street',
        'target' => 'locations:street',
      ),
      array(
        'source' => 'city',
        'target' => 'locations:city',
      ),
      array(
        'source' => 'state',
        'target' => 'locations:province',
      ),
      array(
        'source' => 'zip',
        'target' => 'locations:postal_code',
      ),
      array(
        'source' => 'country',
        'target' => 'locations:country',
      ),
    );
    $this
      ->addMappings('location_import', $mappings);

    // Import CSV file.
    $this
      ->importFile('location_import', drupal_get_path('module', 'location_feeds') . '/tests/feeds/location_nodes.csv');
    $this
      ->assertText('Created 4 ' . $type . ' nodes.');

    // Check the imported locations
    $x = 0;
    $res = db_query("SELECT nid FROM {node} WHERE type='%s'", $type);
    while ($node = db_fetch_object($res)) {
      $node = node_load($node->nid);
      $this
        ->assertEqual($loc[$x]['street'], $node->locations[0]['street'], t('Testing street import, expected: @e, found: @f', array(
        '@e' => $loc[$x]['street'],
        '@f' => $node->locations[0]['street'],
      )));
      $this
        ->assertEqual($loc[$x]['city'], $node->locations[0]['city'], t('Testing city import, expected: @e, found: @f', array(
        '@e' => $loc[$x]['city'],
        '@f' => $node->locations[0]['city'],
      )));
      $this
        ->assertEqual($loc[$x]['province'], $node->locations[0]['province'], t('Testing province import, expected: @e, found: @f', array(
        '@e' => $loc[$x]['province'],
        '@f' => $node->locations[0]['province'],
      )));
      $this
        ->assertEqual($loc[$x]['country'], $node->locations[0]['country'], t('Testing country import, expected: @e, found: @f', array(
        '@e' => $loc[$x]['country'],
        '@f' => $node->locations[0]['country'],
      )));
      $this
        ->assertEqual($loc[$x]['postal_code'], $node->locations[0]['postal_code'], t('Testing country import, expected: @e, found: @f', array(
        '@e' => $loc[$x]['postal_code'],
        '@f' => $node->locations[0]['postal_code'],
      )));
      $x++;
    }
  }

}