1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Test case for CCK link mapper mappers/date.inc.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Class for testing Feeds <em>link</em> mapper.
|
10
|
*/
|
11
|
class FeedsMapperLinkTestCase extends FeedsMapperTestCase {
|
12
|
public static function getInfo() {
|
13
|
return array(
|
14
|
'name' => 'Mapper: Link',
|
15
|
'description' => 'Test Feeds Mapper support for Link fields.',
|
16
|
'group' => 'Feeds',
|
17
|
'dependencies' => array('link'),
|
18
|
);
|
19
|
}
|
20
|
|
21
|
public function setUp() {
|
22
|
parent::setUp(array('link'));
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* Basic test loading a single entry CSV file.
|
27
|
*/
|
28
|
public function test() {
|
29
|
$static_title = $this->randomName();
|
30
|
|
31
|
// Create content type.
|
32
|
$typename = $this->createContentType(array(), array(
|
33
|
'alpha' => array(
|
34
|
'type' => 'link_field',
|
35
|
'instance_settings' => array(
|
36
|
'instance[settings][title]' => 'required',
|
37
|
),
|
38
|
),
|
39
|
'beta' => array(
|
40
|
'type' => 'link_field',
|
41
|
'instance_settings' => array(
|
42
|
'instance[settings][title]' => 'none',
|
43
|
),
|
44
|
),
|
45
|
'gamma' => array(
|
46
|
'type' => 'link_field',
|
47
|
'instance_settings' => array(
|
48
|
'instance[settings][title]' => 'optional',
|
49
|
),
|
50
|
),
|
51
|
'omega' => array(
|
52
|
'type' => 'link_field',
|
53
|
'instance_settings' => array(
|
54
|
'instance[settings][title]' => 'value',
|
55
|
'instance[settings][title_value]' => $static_title,
|
56
|
),
|
57
|
),
|
58
|
));
|
59
|
|
60
|
// Create importer configuration.
|
61
|
$this->createImporterConfiguration(); //Create a default importer configuration
|
62
|
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $typename)); //Processor settings
|
63
|
$this->addMappings('syndication', array(
|
64
|
0 => array(
|
65
|
'source' => 'title',
|
66
|
'target' => 'title'
|
67
|
),
|
68
|
1 => array(
|
69
|
'source' => 'timestamp',
|
70
|
'target' => 'created'
|
71
|
),
|
72
|
2 => array(
|
73
|
'source' => 'description',
|
74
|
'target' => 'body'
|
75
|
),
|
76
|
3 => array(
|
77
|
'source' => 'url',
|
78
|
'target' => 'field_alpha:url'
|
79
|
),
|
80
|
4 => array(
|
81
|
'source' => 'title',
|
82
|
'target' => 'field_alpha:title'
|
83
|
),
|
84
|
5 => array(
|
85
|
'source' => 'url',
|
86
|
'target' => 'field_beta:url'
|
87
|
),
|
88
|
6 => array(
|
89
|
'source' => 'url',
|
90
|
'target' => 'field_gamma:url'
|
91
|
),
|
92
|
7 => array(
|
93
|
'source' => 'title',
|
94
|
'target' => 'field_gamma:title'
|
95
|
),
|
96
|
8 => array(
|
97
|
'source' => 'url',
|
98
|
'target' => 'field_omega:url'
|
99
|
),
|
100
|
));
|
101
|
|
102
|
// Import RSS file.
|
103
|
$nid = $this->createFeedNode();
|
104
|
// Assert 10 items aggregated after creation of the node.
|
105
|
$this->assertText('Created 10 nodes');
|
106
|
|
107
|
// Edit the imported node.
|
108
|
$this->drupalGet('node/2/edit');
|
109
|
|
110
|
$url = 'http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating';
|
111
|
$title = 'Open Atrium Translation Workflow: Two Way Translation Updates';
|
112
|
$this->assertNodeFieldValue('alpha', array('url' => $url, 'static' => $title));
|
113
|
$this->assertNodeFieldValue('beta', array('url' => $url));
|
114
|
$this->assertNodeFieldValue('gamma', array('url' => $url, 'static' => $title));
|
115
|
$this->assertNodeFieldValue('omega', array('url' => $url, 'static' => $static_title));
|
116
|
|
117
|
// Test the static title.
|
118
|
$this->drupalGet('node/2');
|
119
|
$this->assertText($static_title, 'Static title link found.');
|
120
|
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* Override parent::getFormFieldsNames().
|
125
|
*/
|
126
|
protected function getFormFieldsNames($field_name, $index) {
|
127
|
if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
|
128
|
$fields = array("field_{$field_name}[und][{$index}][url]");
|
129
|
if (in_array($field_name, array('alpha', 'gamma'))) {
|
130
|
$fields[] = "field_{$field_name}[und][{$index}][title]";
|
131
|
}
|
132
|
return $fields;
|
133
|
}
|
134
|
else {
|
135
|
return parent::getFormFieldsNames($field_name, $index);
|
136
|
}
|
137
|
}
|
138
|
|
139
|
/**
|
140
|
* Override parent::getFormFieldsValues().
|
141
|
*/
|
142
|
protected function getFormFieldsValues($field_name, $value) {
|
143
|
if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
|
144
|
if (!is_array($value)) {
|
145
|
$value = array('url' => $value);
|
146
|
}
|
147
|
$values = array($value['url']);
|
148
|
if (in_array($field_name, array('alpha', 'gamma'))) {
|
149
|
$values[] = isset($value['title']) ? $value['title'] : '';
|
150
|
}
|
151
|
return $values;
|
152
|
}
|
153
|
else {
|
154
|
return parent::getFormFieldsValues($field_name, $index);
|
155
|
}
|
156
|
}
|
157
|
}
|