1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Test language selection modes
|
5
|
*/
|
6
|
|
7
|
class i18nSelectTestCase extends Drupali18nTestCase {
|
8
|
|
9
|
public static function getInfo() {
|
10
|
return array(
|
11
|
'name' => 'Content Selection',
|
12
|
'group' => 'Internationalization',
|
13
|
'description' => 'Internationalization Content Selection'
|
14
|
);
|
15
|
}
|
16
|
|
17
|
function setUp() {
|
18
|
parent::setUp('translation', 'i18n_variable', 'i18n_select');
|
19
|
parent::setUpLanguages();
|
20
|
parent::setUpContentTranslation();
|
21
|
}
|
22
|
|
23
|
function testIi18nSelect() {
|
24
|
drupal_static_reset('language_list');
|
25
|
$language_list = language_list();
|
26
|
$language_count = count($language_list);
|
27
|
// Set site name for each language and check pages later
|
28
|
variable_set('i18n_variable_list', array('site_name'));
|
29
|
foreach (i18n_language_list() as $langcode => $name) {
|
30
|
i18n_variable_set('site_name', "Drupal-$name", $langcode);
|
31
|
}
|
32
|
|
33
|
// Enable tags field for page content type.
|
34
|
$edit = array(
|
35
|
'fields[_add_existing_field][label]' => t('Tags'),
|
36
|
'fields[_add_existing_field][field_name]' => 'field_tags',
|
37
|
'fields[_add_existing_field][widget_type]' => 'taxonomy_autocomplete',
|
38
|
);
|
39
|
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
|
40
|
$this->drupalPost(NULL, array(), t('Save settings'));
|
41
|
|
42
|
// Create some content and check selection modes
|
43
|
$this->drupalLogin($this->content_editor);
|
44
|
|
45
|
// variable_set('language_content_type_story', 1);
|
46
|
$neutral = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1));
|
47
|
$source = $this->createNode('page', $this->randomName(), $this->randomString(20), language_default('language'), array('field_tags[und]' => $tag_name = $this->randomName()));
|
48
|
$translations = $this->createNodeTranslationSet($source);
|
49
|
|
50
|
drupal_static_reset('translation_node_get_translations');
|
51
|
$this->assertEqual(count(translation_node_get_translations($source->tnid)), $language_count, "Created $language_count $source->type translations.");
|
52
|
|
53
|
// Log in user with access content permission
|
54
|
$user = $this->drupalCreateUser(array('access comments', 'access content'));
|
55
|
$this->drupalLogin($user);
|
56
|
// Default selection mode, only language neutral and current
|
57
|
variable_set('i18n_select_nodes', TRUE);
|
58
|
foreach (i18n_language_list() as $langcode => $name) {
|
59
|
$this->i18nGet($langcode);
|
60
|
$this->assertText("Drupal-$name", 'Checked translated site name: Drupal-' . $name);
|
61
|
$display = array($translations[$langcode], $neutral);
|
62
|
$hide = $translations;
|
63
|
unset($hide[$langcode]);
|
64
|
$this->assertContent($display, $hide);
|
65
|
// Visit the taxonomy page of that node and try again. Only the translated
|
66
|
// pages are tagged.
|
67
|
unset($display[1]);
|
68
|
$this->i18nGet($langcode, 'taxonomy/term/' . $source->field_tags[LANGUAGE_NONE][0]['tid']);
|
69
|
$this->assertContent($display, $hide);
|
70
|
}
|
71
|
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Check some nodes are displayed, some are not
|
76
|
*/
|
77
|
function assertContent($display, $hide = array()) {
|
78
|
$languages = language_list();
|
79
|
foreach ($display as $node) {
|
80
|
$this->assertText($node->title, 'Content displayed for ' . i18n_language_name($node->language));
|
81
|
}
|
82
|
foreach ($hide as $node) {
|
83
|
$this->assertNoText($node->title, 'Content not displayed for ' . i18n_language_name($node->language));
|
84
|
}
|
85
|
}
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* Test case for AJAX queries on "views/ajax" when view on admin page.
|
90
|
*/
|
91
|
class I18NSelectAdminViewsAjax extends Drupali18nTestCase {
|
92
|
|
93
|
/**
|
94
|
* {@inheritdoc}
|
95
|
*/
|
96
|
public static function getInfo() {
|
97
|
return array(
|
98
|
'name' => t('I18N select Admin Views (AJAX)'),
|
99
|
'group' => 'Internationalization',
|
100
|
'description' => t('Test AJAX requests to the "views/ajax" when view located on "admin/*" and list of skipping tags is empty.'),
|
101
|
// Skip this test when "admin_views" module does not exists.
|
102
|
'dependencies' => array('admin_views'),
|
103
|
);
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* {@inheritdoc}
|
108
|
*/
|
109
|
protected function setUp() {
|
110
|
parent::setUp('translation', 'i18n_variable', 'i18n_select', 'admin_views');
|
111
|
parent::setUpLanguages(array('access content overview'));
|
112
|
parent::setUpContentTranslation();
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* Test AJAX of a view without skipping tags for selection.
|
117
|
*
|
118
|
* @see i18n_select_page()
|
119
|
*/
|
120
|
public function testViewsAjaxWithoutSkippingTags() {
|
121
|
// If this variable will have the "views" value then this test will not
|
122
|
// have sense. For instance, we want apply language selection filter
|
123
|
// for views and remove "views" from "i18n_select_skip_tags" variable.
|
124
|
// In this case all AJAX for views, on administration part of the site,
|
125
|
// will be broken because the "i18n_select_page()" function will work
|
126
|
// with "views/ajax" path instead of, for example, "admin/content".
|
127
|
variable_set('i18n_select_skip_tags', '');
|
128
|
|
129
|
// Create one hundred of nodes.
|
130
|
for ($i = 1; $i <= 100; $i++) {
|
131
|
// Create every second node on Spanish language and
|
132
|
// every first - on English.
|
133
|
$node = $this->createNode('page', "Node $i", '', $i % 2 ? $this->default_language : $this->secondary_language);
|
134
|
|
135
|
// Update "changed" in order to sort the content by updating date. In
|
136
|
// other case all nodes will be with the same date and not arranged in
|
137
|
// order.
|
138
|
db_update('node')
|
139
|
->fields(array('changed' => strtotime("+ $i minute")))
|
140
|
->condition('nid', $node->nid)
|
141
|
->execute();
|
142
|
}
|
143
|
|
144
|
$this->drupalGet('admin/content');
|
145
|
|
146
|
// Check that latest node exists at the top.
|
147
|
$this->assertText('Node 100');
|
148
|
// Check that our page contains fifty nodes (the latest must be 51).
|
149
|
$this->assertNoText('Node 50');
|
150
|
|
151
|
// Test $_REQUEST['view_path']. There's no form to submit to, so
|
152
|
// drupalPost() won't work here. This just tests a direct $_POST
|
153
|
// request instead.
|
154
|
$this->curlExec(array(
|
155
|
CURLOPT_URL => $this->getAbsoluteUrl('views/ajax'),
|
156
|
CURLOPT_POST => TRUE,
|
157
|
CURLOPT_POSTFIELDS => http_build_query(array(
|
158
|
'page' => 1,
|
159
|
'view_path' => 'admin/content',
|
160
|
'view_name' => 'admin_views_node',
|
161
|
'view_display_id' => 'system_1',
|
162
|
)),
|
163
|
));
|
164
|
|
165
|
// Check that we are successfully switched to a new page of content.
|
166
|
$this->assertText('Node 50');
|
167
|
$this->assertNoText('Node 100');
|
168
|
}
|
169
|
|
170
|
}
|