1 |
41cc1b08
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Contains FeedsMapperFormatConfig.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Class for testing "Text format" mapping configuration on text fields.
|
10 |
|
|
*/
|
11 |
|
|
class FeedsMapperFormatConfig extends FeedsMapperTestCase {
|
12 |
|
|
|
13 |
|
|
public static function getInfo() {
|
14 |
|
|
return array(
|
15 |
|
|
'name' => 'Mapper: Text format mapping configuration',
|
16 |
|
|
'description' => 'Test text format mapping configuration for text fields.',
|
17 |
|
|
'group' => 'Feeds',
|
18 |
|
|
);
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
public function setUp() {
|
22 |
|
|
parent::setUp(array('list', 'taxonomy'));
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
/**
|
26 |
|
|
* Basic test for setting mapping configuration.
|
27 |
|
|
*/
|
28 |
|
|
public function test() {
|
29 |
|
|
// Create content type with three fields. Two that support text formats
|
30 |
|
|
// and one that doesn't.
|
31 |
|
|
$typename = $this->createContentType(array(), array(
|
32 |
|
|
'alpha' => array(
|
33 |
|
|
'type' => 'text',
|
34 |
|
|
'instance_settings' => array(
|
35 |
|
|
'instance[settings][text_processing]' => 1,
|
36 |
|
|
),
|
37 |
|
|
),
|
38 |
|
|
'beta' => array(
|
39 |
|
|
'type' => 'text_long',
|
40 |
|
|
'instance_settings' => array(
|
41 |
|
|
'instance[settings][text_processing]' => 1,
|
42 |
|
|
),
|
43 |
|
|
),
|
44 |
|
|
'gamma' => array(
|
45 |
|
|
'type' => 'text',
|
46 |
|
|
'instance_settings' => array(
|
47 |
|
|
'instance[settings][text_processing]' => 0,
|
48 |
|
|
),
|
49 |
|
|
),
|
50 |
|
|
));
|
51 |
|
|
|
52 |
|
|
// Create a new filter format.
|
53 |
|
|
$format = drupal_strtolower($this->randomName());
|
54 |
|
|
$edit = array(
|
55 |
|
|
'format' => $format,
|
56 |
|
|
'name' => $this->randomName(),
|
57 |
|
|
// Authenticated users.
|
58 |
|
|
'roles[2]' => TRUE,
|
59 |
|
|
);
|
60 |
|
|
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
|
61 |
|
|
|
62 |
|
|
// Create and configure importer.
|
63 |
|
|
$this->createImporterConfiguration();
|
64 |
|
|
$this->setSettings('syndication', NULL, array('content_type' => ''));
|
65 |
|
|
|
66 |
|
|
$this->setPlugin('syndication', 'FeedsFileFetcher');
|
67 |
|
|
$this->setPlugin('syndication', 'FeedsCSVParser');
|
68 |
|
|
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $typename));
|
69 |
|
|
|
70 |
|
|
$this->addMappings('syndication', array(
|
71 |
|
|
0 => array(
|
72 |
|
|
'source' => 'title',
|
73 |
|
|
'target' => 'title',
|
74 |
|
|
),
|
75 |
|
|
1 => array(
|
76 |
|
|
'source' => 'created',
|
77 |
|
|
'target' => 'created',
|
78 |
|
|
),
|
79 |
|
|
2 => array(
|
80 |
|
|
'source' => 'body',
|
81 |
|
|
'target' => 'body',
|
82 |
|
|
'format' => $format,
|
83 |
|
|
),
|
84 |
|
|
3 => array(
|
85 |
|
|
'source' => 'alpha',
|
86 |
|
|
'target' => 'field_alpha',
|
87 |
|
|
'format' => $format,
|
88 |
|
|
),
|
89 |
|
|
4 => array(
|
90 |
|
|
'source' => 'beta',
|
91 |
|
|
'target' => 'field_beta',
|
92 |
|
|
'format' => $format,
|
93 |
|
|
),
|
94 |
|
|
5 => array(
|
95 |
|
|
'source' => 'gamma',
|
96 |
|
|
'target' => 'field_gamma',
|
97 |
|
|
),
|
98 |
|
|
));
|
99 |
|
|
// Assert that for the gamma field no format can be chosen.
|
100 |
|
|
$this->assertNoText('Text format: Plain text');
|
101 |
|
|
|
102 |
|
|
// Import csv file.
|
103 |
|
|
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/content.csv');
|
104 |
|
|
$this->assertText('Created 2 nodes');
|
105 |
|
|
|
106 |
|
|
// Assert that fields body, alpha and beta got the expected text format.
|
107 |
|
|
$node = node_load(1);
|
108 |
|
|
$this->assertEqual($format, $node->body[LANGUAGE_NONE][0]['format'], 'The body field got the expected format.');
|
109 |
|
|
$this->assertEqual($format, $node->field_alpha[LANGUAGE_NONE][0]['format'], 'The alpha field got the expected format.');
|
110 |
|
|
$this->assertEqual($format, $node->field_beta[LANGUAGE_NONE][0]['format'], 'The beta field got the expected format.');
|
111 |
|
|
$this->assertEqual(filter_fallback_format(), $node->field_gamma[LANGUAGE_NONE][0]['format'], 'The gama field got the expected format.');
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
/**
|
115 |
|
|
* Tests the filter formats a user has access to.
|
116 |
|
|
*/
|
117 |
|
|
public function testWithLimitedPrivileges() {
|
118 |
|
|
// Create content type with a field that uses a text format.
|
119 |
|
|
$typename = $this->createContentType(array(), array(
|
120 |
|
|
'alpha' => array(
|
121 |
|
|
'type' => 'text',
|
122 |
|
|
'instance_settings' => array(
|
123 |
|
|
'instance[settings][text_processing]' => 1,
|
124 |
|
|
),
|
125 |
|
|
),
|
126 |
|
|
));
|
127 |
|
|
|
128 |
|
|
// Create a new user with limited privileges.
|
129 |
|
|
$account = $this->drupalCreateUser(array('administer feeds'));
|
130 |
|
|
|
131 |
|
|
// Create filter format the user may use.
|
132 |
|
|
$format1 = drupal_strtolower($this->randomName());
|
133 |
|
|
$edit1 = array(
|
134 |
|
|
'format' => $format1,
|
135 |
|
|
'name' => $this->randomName(),
|
136 |
|
|
// Authenticated users.
|
137 |
|
|
'roles[2]' => TRUE,
|
138 |
|
|
);
|
139 |
|
|
$this->drupalPost('admin/config/content/formats/add', $edit1, t('Save configuration'));
|
140 |
|
|
|
141 |
|
|
// Create filter format the user may NOT use.
|
142 |
|
|
$rid = $this->drupalCreateRole(array());
|
143 |
|
|
$format2 = drupal_strtolower($this->randomName());
|
144 |
|
|
$edit2 = array(
|
145 |
|
|
'format' => $format2,
|
146 |
|
|
'name' => $this->randomName(),
|
147 |
|
|
'roles[' . $rid . ']' => TRUE,
|
148 |
|
|
);
|
149 |
|
|
$this->drupalPost('admin/config/content/formats/add', $edit2, t('Save configuration'));
|
150 |
|
|
|
151 |
|
|
// Login as the user that may only use certain formats.
|
152 |
|
|
$this->drupalLogin($account);
|
153 |
|
|
|
154 |
|
|
// Create importer and ensure the user can use the first format.
|
155 |
|
|
$this->createImporterConfiguration();
|
156 |
|
|
$this->setSettings('syndication', NULL, array(
|
157 |
|
|
'content_type' => '',
|
158 |
|
|
'import_period' => FEEDS_SCHEDULE_NEVER,
|
159 |
|
|
));
|
160 |
|
|
$this->setPlugin('syndication', 'FeedsFileFetcher');
|
161 |
|
|
$this->setPlugin('syndication', 'FeedsCSVParser');
|
162 |
|
|
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $typename));
|
163 |
|
|
$this->addMappings('syndication', array(
|
164 |
|
|
0 => array(
|
165 |
|
|
'source' => 'alpha',
|
166 |
|
|
'target' => 'field_alpha',
|
167 |
|
|
'format' => $format1,
|
168 |
|
|
),
|
169 |
|
|
));
|
170 |
|
|
|
171 |
|
|
// Check user can choose first, but not second format as an option.
|
172 |
|
|
$this->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_0');
|
173 |
|
|
$xpath = $this->constructFieldXpath('name', 'config[0][settings][format]');
|
174 |
|
|
$fields = $this->xpath($xpath);
|
175 |
|
|
$field = reset($fields);
|
176 |
|
|
$format_options = $this->getAllOptions($field);
|
177 |
|
|
$format1_found = FALSE;
|
178 |
|
|
$format2_found = FALSE;
|
179 |
|
|
foreach ($format_options as $option) {
|
180 |
|
|
if ($option['value'] == $format1) {
|
181 |
|
|
$format1_found = TRUE;
|
182 |
|
|
}
|
183 |
|
|
if ($option['value'] == $format2) {
|
184 |
|
|
$format2_found = TRUE;
|
185 |
|
|
}
|
186 |
|
|
}
|
187 |
|
|
// Assert first format can be chosen.
|
188 |
|
|
$this->assertTrue($format1_found, format_string('Text format %format can be chosen.', array('%format' => $format1)));
|
189 |
|
|
// Assert second format can NOT be chosen.
|
190 |
|
|
$this->assertFalse($format2_found, format_string('Text format %format can NOT be chosen.', array('%format' => $format2)));
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
/**
|
194 |
|
|
* Tests if text format can be set for taxonomy descriptions.
|
195 |
|
|
*/
|
196 |
|
|
public function testTaxonomyDescriptionTextFormat() {
|
197 |
|
|
// Create a vocabulary.
|
198 |
|
|
$edit = array(
|
199 |
|
|
'name' => 'Tags',
|
200 |
|
|
'machine_name' => 'tags',
|
201 |
|
|
);
|
202 |
|
|
$this->drupalPost('admin/structure/taxonomy/add', $edit, 'Save');
|
203 |
|
|
|
204 |
|
|
// Create a new filter format.
|
205 |
|
|
$format = drupal_strtolower($this->randomName());
|
206 |
|
|
$edit = array(
|
207 |
|
|
'format' => $format,
|
208 |
|
|
'name' => $this->randomName(),
|
209 |
|
|
// Authenticated users.
|
210 |
|
|
'roles[2]' => TRUE,
|
211 |
|
|
);
|
212 |
|
|
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
|
213 |
|
|
|
214 |
|
|
// Create a taxonomy term importer.
|
215 |
|
|
$this->createImporterConfiguration();
|
216 |
|
|
$this->setSettings('syndication', NULL, array(
|
217 |
|
|
'content_type' => '',
|
218 |
|
|
'import_period' => FEEDS_SCHEDULE_NEVER,
|
219 |
|
|
));
|
220 |
|
|
$this->setPlugin('syndication', 'FeedsFileFetcher');
|
221 |
|
|
$this->setPlugin('syndication', 'FeedsCSVParser');
|
222 |
|
|
$this->setPlugin('syndication', 'FeedsTermProcessor');
|
223 |
|
|
$this->setSettings('syndication', 'FeedsTermProcessor', array('bundle' => 'tags'));
|
224 |
|
|
$this->addMappings('syndication', array(
|
225 |
|
|
0 => array(
|
226 |
|
|
'source' => 'title',
|
227 |
|
|
'target' => 'name',
|
228 |
|
|
),
|
229 |
|
|
1 => array(
|
230 |
|
|
'source' => 'body',
|
231 |
|
|
'target' => 'description',
|
232 |
|
|
'format' => $format,
|
233 |
|
|
),
|
234 |
|
|
));
|
235 |
|
|
|
236 |
|
|
// Import csv file.
|
237 |
|
|
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/content.csv');
|
238 |
|
|
$this->assertText('Created 2 terms');
|
239 |
|
|
|
240 |
|
|
// Assert that the term description got the expected text format.
|
241 |
|
|
$term = taxonomy_term_load(1);
|
242 |
|
|
$this->assertEqual($format, $term->format, 'The taxonomy term got the expected format.');
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
} |