You are here

class FeedsExamplesNodeTestCase in Feeds 8.2

Same name and namespace in other branches
  1. 6 feeds_import/feeds_import.test \FeedsExamplesNodeTestCase
  2. 7.2 feeds_import/feeds_import.test \FeedsExamplesNodeTestCase
  3. 7 feeds_import/feeds_import.test \FeedsExamplesNodeTestCase

Test Node import configuration.

Hierarchy

Expanded class hierarchy of FeedsExamplesNodeTestCase

File

feeds_import/feeds_import.test, line 11
Tests for feeds_import feature.

View source
class FeedsExamplesNodeTestCase extends FeedsWebTestCase {

  /**
   * Set up test.
   */
  public function setUp() {
    parent::setUp(array(
      'feeds_import',
    ));
  }
  public static function getInfo() {
    return array(
      'name' => 'Feature: Node import',
      'description' => 'Test "Node import" default configuration.',
      'group' => 'Feeds',
    );
  }

  /**
   * Run tests.
   */
  public function test() {

    // Import file.
    $this
      ->importFile('node', $this
      ->absolutePath() . '/tests/feeds/nodes.csv');

    // Assert returning page.
    $this
      ->assertText('Created 8 nodes');
    $this
      ->assertText('Import CSV files with one or more of these columns: title, body, published, guid.');
    $this
      ->assertText('Column guid is mandatory and considered unique: only one item per guid value will be created.');
    $this
      ->assertRaw('feeds/nodes.csv');

    // Assert created nodes.
    $this
      ->drupalGet('node');
    $this
      ->assertText('Typi non habent');
    $this
      ->assertText('Eodem modo typi');
    $this
      ->assertText('Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.');
    $this
      ->assertText('Lorem ipsum');
    $this
      ->assertText('Ut wisi enim ad minim veniam');
    $this
      ->assertText('1976');

    // Nam liber tempor has the same GUID as Lorem ipsum.
    $this
      ->assertNoText('Nam liber tempor');

    // Click through to one node.
    $this
      ->clickLink('Lorem ipsum');
    $this
      ->assertText('Lorem ipsum');
    $this
      ->assertText('Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.');
    $this
      ->assertText('Anonymous');

    // Assert DB status as is and again after an additional import.
    for ($i = 0; $i < 2; $i++) {
      $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")
        ->fetchField();
      $this
        ->assertEqual($count, 8, 'Found correct number of items.');
      $count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article' AND status = 1 AND uid = 0")
        ->fetchField();
      $this
        ->assertEqual($count, 8, 'Found correct number of items.');

      // Do not filter on type intentionally. There shouldn't be more than 8 nodes total.
      $count = db_query("SELECT COUNT(*) FROM {node_revision}")
        ->fetchField();
      $this
        ->assertEqual($count, 8, 'Found correct number of items.');

      // Import again. Feeds only updates items that haven't changed. However,
      // there are 2 different items with the same GUID in nodes.csv.
      // Therefore, feeds will show updates to 2 nodes.
      $this
        ->drupalPost('import/node/import', array(), 'Import');
      $this
        ->assertText('Updated 2 nodes');
    }

    // Remove all nodes.
    $this
      ->drupalPost('import/node/delete-items', array(), 'Delete');
    $this
      ->assertText('Deleted 8 nodes');

    // Import once again.
    $this
      ->drupalPost('import/node/import', array(), 'Import');
    $this
      ->assertText('Created 8 nodes');

    // Import a similar file with changes in 4 records. Feeds should report 6
    // Updated Article nodes (4 changed records, 2 records sharing a GUID
    // subsequently being updated).
    $this
      ->importFile('node', $this
      ->absolutePath() . '/tests/feeds/nodes_changes.csv');
    $this
      ->assertText('Updated 6 nodes');

    // Import a larger file with more records.
    $this
      ->importFile('node', $this
      ->absolutePath() . '/tests/feeds/many_nodes.csv');
    $this
      ->assertText('Created 71 nodes');

    // Remove all nodes.
    $this
      ->drupalPost('import/node/delete-items', array(), 'Delete');
    $this
      ->assertText('Deleted 79 nodes');

    // Import once again.
    $this
      ->drupalPost('import/node/import', array(), 'Import');
    $this
      ->assertText('Created 79 nodes');
    $this
      ->assertText('Updated 7 nodes');

    // Import a tab separated file.
    $this
      ->drupalPost('import/node/delete-items', array(), 'Delete');
    $edit = array(
      'files[feeds]' => $this
        ->absolutePath() . '/tests/feeds/nodes.tsv',
      'feeds[FeedsCSVParser][delimiter]' => "TAB",
    );
    $this
      ->drupalPost('import/node', $edit, 'Import');
    $this
      ->assertText('Created 8 nodes');
  }

}

Members