1 |
41cc1b08
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Contains FeedsMapperUniqueTestCase.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Class for testing Feeds unique callbacks.
|
10 |
|
|
*/
|
11 |
|
|
class FeedsMapperUniqueTestCase extends FeedsMapperTestCase {
|
12 |
|
|
|
13 |
|
|
public static function getInfo() {
|
14 |
|
|
return array(
|
15 |
|
|
'name' => 'Unique target callbacks',
|
16 |
|
|
'description' => 'Test unique target callbacks in mappers.',
|
17 |
|
|
'group' => 'Feeds',
|
18 |
|
|
);
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
/**
|
22 |
|
|
* Test mapping target "unique_callbacks".
|
23 |
|
|
*/
|
24 |
|
|
public function test() {
|
25 |
|
|
// Create content type.
|
26 |
|
|
$typename = $this->createContentType(array(), array('alpha' => 'text'));
|
27 |
|
|
|
28 |
|
|
// Create two nodes. Put unique value into field field_alpha.
|
29 |
|
|
$node1 = $this->drupalCreateNode(array(
|
30 |
|
|
'type' => $typename,
|
31 |
|
|
'field_alpha' => array(
|
32 |
|
|
LANGUAGE_NONE => array(
|
33 |
|
|
0 => array(
|
34 |
|
|
'value' => 'Ut wisi',
|
35 |
|
|
),
|
36 |
|
|
),
|
37 |
|
|
),
|
38 |
|
|
));
|
39 |
|
|
$node2 = $this->drupalCreateNode(array(
|
40 |
|
|
'type' => $typename,
|
41 |
|
|
'field_alpha' => array(
|
42 |
|
|
LANGUAGE_NONE => array(
|
43 |
|
|
0 => array(
|
44 |
|
|
'value' => 'Lorem',
|
45 |
|
|
),
|
46 |
|
|
),
|
47 |
|
|
),
|
48 |
|
|
));
|
49 |
|
|
|
50 |
|
|
// Create and configure importer.
|
51 |
|
|
$this->createImporterConfiguration('Syndication', 'syndication');
|
52 |
|
|
$this->setPlugin('syndication', 'FeedsFileFetcher');
|
53 |
|
|
$this->setPlugin('syndication', 'FeedsCSVParser');
|
54 |
|
|
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $typename, 'update_existing' => 2));
|
55 |
|
|
$this->addMappings('syndication', array(
|
56 |
|
|
0 => array(
|
57 |
|
|
'source' => 'title',
|
58 |
|
|
'target' => 'title',
|
59 |
|
|
),
|
60 |
|
|
1 => array(
|
61 |
|
|
'source' => 'alpha',
|
62 |
|
|
'target' => 'test_unique_target',
|
63 |
|
|
'unique' => TRUE,
|
64 |
|
|
),
|
65 |
|
|
));
|
66 |
|
|
|
67 |
|
|
// Import CSV file.
|
68 |
|
|
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/content.csv');
|
69 |
|
|
$this->assertText('Updated 2 nodes');
|
70 |
|
|
|
71 |
|
|
// Ensure the updated nodes have the expected title now.
|
72 |
|
|
$node1 = node_load($node1->nid, NULL, TRUE);
|
73 |
|
|
$this->assertEqual('Ut wisi enim ad minim veniam', $node1->title, 'Node 1 has the expected title.');
|
74 |
|
|
$node2 = node_load($node2->nid, NULL, TRUE);
|
75 |
|
|
$this->assertEqual('Lorem ipsum', $node2->title, 'Node 2 has the expected title.');
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
} |