summaryrefslogtreecommitdiffstats
path: root/tests/feeds_processor_term.test
blob: 06eaa29521df5871bef2c3cd66b9d460fe6193ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php

/**
 * @file
 * Tests for plugins/FeedsTermProcessor.inc
 */

// Require FeedsWebTestCase class definition.
require_once(dirname(__FILE__) .'/feeds.test.inc');

/**
 * Test aggregating a feed as data records.
 */
class FeedsCSVtoTermsTest extends FeedsWebTestCase {

  /**
   * Describe this test.
   */
  public function getInfo() {
    return array(
      'name' => t('CSV import to taxonomy'),
      'description' => t('Tests a standalone import configuration that uses file fetcher and CSV parser to import taxonomy terms from a CSV file.'),
      'group' => t('Feeds'),
    );
  }

  /**
   * Set up test.
   */
  public function setUp() {
    parent::setUp('taxonomy', 'ctools', 'feeds', 'feeds_ui', 'job_scheduler');

    $this->drupalLogin(
      $this->drupalCreateUser(
        array(
          'administer feeds', 'administer taxonomy',
        )
      )
    );
  }

  /**
   * Test node creation, refreshing/deleting feeds and feed items.
   */
  public function test() {

    // Create an importer.
    $this->createImporterConfiguration('Term import', 'term_import');

    // Set and configure plugins and mappings.
    $this->setPlugin('term_import', 'FeedsFileFetcher');
    $this->setPlugin('term_import', 'FeedsCSVParser');
    $this->setPlugin('term_import', 'FeedsTermProcessor');
    $mappings = array(
      '0' => array(
        'source' => 'name',
        'target' => 'name',
        'unique' => 1,
      ),
    );
    $this->addMappings('term_import', $mappings);

    // Use standalone form.
    $edit = array(
      'content_type' => '',
    );
    $this->drupalPost('admin/structure/feeds/edit/term_import/settings', $edit, 'Save');

    $edit = array(
      'name' => 'Addams vocabulary',
      'machine_name' => 'addams',
    );
    $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));

    $edit = array(
      'vocabulary' => 'addams',
    );
    $this->drupalPost('admin/structure/feeds/edit/term_import/settings/FeedsTermProcessor', $edit, t('Save'));

    // Import and assert.
    $this->importFile('term_import', $this->absolutePath() .'/tests/feeds/users.csv');
    $this->assertText('Created 5 terms in Addams vocabulary.');
    $this->drupalGet('admin/structure/taxonomy/addams');
    $this->assertText('Morticia');
    $this->assertText('Fester');
    $this->assertText('Gomez');
    $this->assertText('Pugsley');

    // Import again.
    $this->importFile('term_import', $this->absolutePath() .'/tests/feeds/users.csv');
    $this->assertText('There are no new terms.');

    // Add a term manually, delete all terms, this term should still stand.
    $edit = array(
      'name' => 'Cousin Itt',
    );
    $this->drupalPost('admin/structure/taxonomy/addams/add', $edit, t('Save'));
    $this->drupalPost('import/term_import/delete-items', array(), t('Delete'));
    $this->drupalGet('admin/structure/taxonomy/addams');
    $this->assertText('Cousin Itt');
    $this->assertNoText('Morticia');
    $this->assertNoText('Fester');
    $this->assertNoText('Gomez');
    $this->assertNoText('Pugsley');
  }
}