Projet

Général

Profil

Paste
Télécharger (5,06 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / feeds_import / feeds_import.test @ ed9a13f1

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for feeds_import feature.
6
 */
7

    
8
/**
9
 * Test Node import configuration.
10
 */
11
class FeedsExamplesNodeTestCase extends FeedsWebTestCase {
12

    
13
  /**
14
   * {@inheritdoc}
15
   */
16
  public static function getInfo() {
17
    return array(
18
      'name' => 'Feature: Node import',
19
      'description' => 'Test "Node import" default configuration.',
20
      'group' => 'Feeds',
21
    );
22
  }
23

    
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function setUp() {
28
    parent::setUp(array('feeds_import'));
29
  }
30

    
31
  /**
32
   * Run tests.
33
   */
34
  public function test() {
35
    // Import file.
36
    $this->importFile('node', $this->absolutePath() . '/tests/feeds/nodes.csv');
37

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

    
44
    // Assert created nodes.
45
    $this->drupalGet('node');
46
    $this->assertText('Typi non habent');
47
    $this->assertText('Eodem modo typi');
48
    $this->assertText('Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.');
49
    $this->assertText('Lorem ipsum');
50
    $this->assertText('Ut wisi enim ad minim veniam');
51
    $this->assertText('1976');
52
    // Nam liber tempor has the same GUID as Lorem ipsum.
53
    $this->assertNoText('Nam liber tempor');
54

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

    
61
    // Assert DB status as is and again after an additional import.
62
    for ($i = 0; $i < 2; $i++) {
63
      $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
64
      $this->assertEqual($count, 8, 'Found correct number of items.');
65
      $count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article' AND status = 1 AND uid = 0")->fetchField();
66
      $this->assertEqual($count, 8, 'Found correct number of items.');
67
      // Do not filter on type intentionally. There shouldn't be more than 8
68
      // nodes total.
69
      $count = db_query("SELECT COUNT(*) FROM {node_revision}")->fetchField();
70
      $this->assertEqual($count, 8, 'Found correct number of items.');
71

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

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

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

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

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

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

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

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

    
116
}
117

    
118
/**
119
 * Test User import configuration.
120
 */
121
class FeedsExamplesUserTestCase extends FeedsWebTestCase {
122

    
123
  /**
124
   * {@inheritdoc}
125
   */
126
  public static function getInfo() {
127
    return array(
128
      'name' => 'Feature: User import',
129
      'description' => 'Test "User import" default configuration.',
130
      'group' => 'Feeds',
131
    );
132
  }
133

    
134
  /**
135
   * {@inheritdoc}
136
   */
137
  public function setUp() {
138
    parent::setUp(array('feeds_import'));
139
  }
140

    
141
  /**
142
   * Run tests.
143
   */
144
  public function test() {
145
    // Import CSV file.
146
    $this->importFile('user', $this->absolutePath() . '/tests/feeds/users.csv');
147

    
148
    // Assert result.
149
    $this->assertText('Created 3 users');
150
    // 1 user has an invalid email address.
151
    $this->assertText('Failed importing 2 users');
152
    $this->drupalGet('admin/people');
153
    $this->assertText('Morticia');
154
    $this->assertText('Fester');
155
    $this->assertText('Gomez');
156
  }
157

    
158
}