1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains Feedsi18nNodeTestCase.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Tests importing nodes in a language.
|
10
|
*/
|
11
|
class Feedsi18nNodeTestCase extends Feedsi18nTestCase {
|
12
|
|
13
|
/**
|
14
|
* Name of created content type.
|
15
|
*
|
16
|
* @var string
|
17
|
*/
|
18
|
private $contentType;
|
19
|
|
20
|
public static function getInfo() {
|
21
|
return array(
|
22
|
'name' => 'Multilingual content',
|
23
|
'description' => 'Tests Feeds multilingual support for nodes.',
|
24
|
'group' => 'Feeds',
|
25
|
'dependencies' => array('locale'),
|
26
|
);
|
27
|
}
|
28
|
|
29
|
public function setUp($modules = array(), $permissions = array()) {
|
30
|
$this->entityType = 'node';
|
31
|
$this->processorName = 'FeedsNodeProcessor';
|
32
|
|
33
|
parent::setUp($modules, $permissions);
|
34
|
|
35
|
// Create content type.
|
36
|
$this->contentType = $this->createContentType();
|
37
|
|
38
|
// Configure importer.
|
39
|
$this->setSettings('i18n', $this->processorName, array(
|
40
|
'bundle' => $this->contentType,
|
41
|
'language' => 'de',
|
42
|
'update_existing' => FEEDS_UPDATE_EXISTING,
|
43
|
'skip_hash_check' => TRUE,
|
44
|
));
|
45
|
$this->addMappings('i18n', array(
|
46
|
0 => array(
|
47
|
'source' => 'guid',
|
48
|
'target' => 'guid',
|
49
|
'unique' => '1',
|
50
|
),
|
51
|
1 => array(
|
52
|
'source' => 'title',
|
53
|
'target' => 'title',
|
54
|
),
|
55
|
));
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Tests if the language setting is available on the processor.
|
60
|
*/
|
61
|
public function testAvailableProcessorLanguageSetting() {
|
62
|
// Check if the language setting is available when the locale module is enabled.
|
63
|
$this->drupalGet('admin/structure/feeds/i18n/settings/FeedsNodeProcessor');
|
64
|
$this->assertField('language', 'Language field is available on the node processor settings when the locale module is enabled.');
|
65
|
|
66
|
// Disable the locale module and check if the language setting is no longer available.
|
67
|
module_disable(array('locale'));
|
68
|
$this->drupalGet('admin/structure/feeds/i18n/settings/FeedsNodeProcessor');
|
69
|
$this->assertNoField('language', 'Language field is not available on the node processor settings when the locale module is disabled.');
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Tests processor language setting in combination with language mapping target.
|
74
|
*/
|
75
|
public function testWithLanguageMappingTarget() {
|
76
|
$this->addMappings('i18n', array(
|
77
|
2 => array(
|
78
|
'source' => 'language',
|
79
|
'target' => 'language',
|
80
|
),
|
81
|
));
|
82
|
|
83
|
// Import csv file. The first item has a language specified (Dutch), the second
|
84
|
// one has no language specified and should be imported in the processor's language (German).
|
85
|
$this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content_i18n.csv');
|
86
|
|
87
|
// The first node should be Dutch.
|
88
|
$node = node_load(1);
|
89
|
$this->assertEqual('nl', entity_language('node', $node), 'Item 1 has the Dutch language assigned.');
|
90
|
|
91
|
// The second node should be German.
|
92
|
$node = node_load(2);
|
93
|
$this->assertEqual('de', entity_language('node', $node), 'Item 2 has the German language assigned.');
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* Tests if nodes get imported in LANGUAGE_NONE when the locale module gets disabled.
|
98
|
*/
|
99
|
public function testDisabledLocaleModule() {
|
100
|
module_disable(array('locale'));
|
101
|
// Make sure that entity info is reset.
|
102
|
drupal_flush_all_caches();
|
103
|
drupal_static_reset();
|
104
|
|
105
|
// Import content.
|
106
|
$this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
|
107
|
|
108
|
// Assert that the content has no language assigned.
|
109
|
for ($i = 1; $i <= 2; $i++) {
|
110
|
$node = node_load($i);
|
111
|
$language = entity_language('node', $node);
|
112
|
$this->assertEqual(LANGUAGE_NONE, $language, format_string('The node is language neutral (actual: !language).', array('!language' => $language)));
|
113
|
}
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Tests if nodes get imported in LANGUAGE_NONE when the locale module gets uninstalled.
|
118
|
*/
|
119
|
public function testUninstalledLocaleModule() {
|
120
|
module_disable(array('locale'));
|
121
|
drupal_uninstall_modules(array('locale'));
|
122
|
// Make sure that entity info is reset.
|
123
|
drupal_flush_all_caches();
|
124
|
drupal_static_reset();
|
125
|
|
126
|
// Import content.
|
127
|
$this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
|
128
|
|
129
|
// Assert that the content has no language assigned.
|
130
|
for ($i = 1; $i <= 2; $i++) {
|
131
|
$node = node_load($i);
|
132
|
$language = entity_language('node', $node);
|
133
|
$this->assertEqual(LANGUAGE_NONE, $language, format_string('The node is language neutral (actual: !language).', array('!language' => $language)));
|
134
|
}
|
135
|
}
|
136
|
}
|