Commit fa9e8bbe authored by alexpott's avatar alexpott

Issue #2161845 by Gábor Hojtsy, vijaycs85 | YesCT: Fixed Node views (front...

Issue #2161845 by Gábor Hojtsy, vijaycs85 | YesCT: Fixed Node views (front page, admin) do not use the proper language filter.
parent 19595c24
...@@ -199,30 +199,4 @@ public function testContentTypeDirLang() { ...@@ -199,30 +199,4 @@ public function testContentTypeDirLang() {
$this->assertNoPattern($pattern, 'The dir tag has not been assigned to the Spanish node.'); $this->assertNoPattern($pattern, 'The dir tag has not been assigned to the Spanish node.');
} }
/**
* Test filtering Node content by language.
*/
public function testNodeAdminLanguageFilter() {
\Drupal::moduleHandler()->install(array('views'));
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'access content overview', 'administer nodes', 'bypass node access'));
// Log in as admin.
$this->drupalLogin($admin_user);
// Enable multiple languages.
$this->drupalPostForm('admin/config/regional/language/edit/en', array('locale_translate_english' => TRUE), t('Save language'));
$this->drupalPostForm('admin/config/regional/language/add', array('predefined_langcode' => 'zh-hant'), t('Add language'));
// Create two nodes: English and Chinese.
$node_en = $this->drupalCreateNode(array('langcode' => 'en'));
$node_zh_hant = $this->drupalCreateNode(array('langcode' => 'zh-hant'));
// Verify filtering by language.
$this->drupalGet('admin/content', array('query' => array('langcode' => 'zh-hant')));
$this->assertLinkByHref('node/' . $node_zh_hant->id() . '/edit');
$this->assertNoLinkByHref('node/' . $node_en->id() . '/edit');
}
} }
...@@ -39,7 +39,7 @@ public function setUp() { ...@@ -39,7 +39,7 @@ public function setUp() {
*/ */
public function testPathLanguageConfiguration() { public function testPathLanguageConfiguration() {
// User to add and remove language. // User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'create page content', 'administer url aliases', 'create url aliases', 'access administration pages')); $admin_user = $this->drupalCreateUser(array('administer languages', 'create page content', 'administer url aliases', 'create url aliases', 'access administration pages', 'access content overview'));
// Add custom language. // Add custom language.
$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
...@@ -135,11 +135,11 @@ public function testPathLanguageConfiguration() { ...@@ -135,11 +135,11 @@ public function testPathLanguageConfiguration() {
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']); $this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
// Test that both node titles link to our path alias. // Test that both node titles link to our path alias.
$this->drupalGet('<front>'); $this->drupalGet('admin/content');
$custom_path_url = base_path() . $GLOBALS['script_path'] . $custom_path; $custom_path_url = base_path() . $GLOBALS['script_path'] . $custom_path;
$elements = $this->xpath('//a[@href=:href]/span[normalize-space(text())=:title]', array(':href' => $custom_path_url, ':title' => $first_node->label())); $elements = $this->xpath('//a[@href=:href and normalize-space(text())=:title]', array(':href' => $custom_path_url, ':title' => $first_node->label()));
$this->assertTrue(!empty($elements), 'First node links to the path alias.'); $this->assertTrue(!empty($elements), 'First node links to the path alias.');
$elements = $this->xpath('//a[@href=:href]/span[normalize-space(text())=:title]', array(':href' => $custom_path_url, ':title' => $second_node->label())); $elements = $this->xpath('//a[@href=:href and normalize-space(text())=:title]', array(':href' => $custom_path_url, ':title' => $second_node->label()));
$this->assertTrue(!empty($elements), 'Second node links to the path alias.'); $this->assertTrue(!empty($elements), 'Second node links to the path alias.');
// Confirm that the custom path leads to the first node. // Confirm that the custom path leads to the first node.
......
base_field: nid langcode: en
status: true
dependencies:
module:
- history
- node
- user
id: content
label: Content
module: node
description: 'Find and manage content.'
tag: default
base_table: node base_table: node
base_field: nid
core: 8.x core: 8.x
description: 'Find and manage content.'
status: true
display: display:
default: default:
display_options: display_options:
...@@ -459,8 +469,14 @@ display: ...@@ -459,8 +469,14 @@ display:
provider: views provider: views
langcode: langcode:
id: langcode id: langcode
table: node_revision table: node_field_data
field: langcode field: langcode
relationship: none
group_type: group
admin_label: ''
dependencies:
module:
- views
operator: in operator: in
value: { } value: { }
group: 1 group: 1
...@@ -468,12 +484,32 @@ display: ...@@ -468,12 +484,32 @@ display:
expose: expose:
operator_id: langcode_op operator_id: langcode_op
label: Language label: Language
description: ''
use_operator: false
operator: langcode_op operator: langcode_op
identifier: langcode identifier: langcode
required: false
remember: false
multiple: false
remember_roles: remember_roles:
authenticated: authenticated authenticated: authenticated
anonymous: '0'
administrator: '0'
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: language plugin_id: language
provider: language provider: views
sorts: { } sorts: { }
title: Content title: Content
empty: empty:
...@@ -500,6 +536,8 @@ display: ...@@ -500,6 +536,8 @@ display:
operator: AND operator: AND
groups: groups:
1: AND 1: AND
field_langcode: '***CURRENT_LANGUAGE***'
field_langcode_add_to_query: null
display_plugin: default display_plugin: default
display_title: Master display_title: Master
id: default id: default
...@@ -520,16 +558,9 @@ display: ...@@ -520,16 +558,9 @@ display:
description: 'Find and manage content' description: 'Find and manage content'
name: admin name: admin
weight: -10 weight: -10
field_langcode: '***CURRENT_LANGUAGE***'
field_langcode_add_to_query: null
display_plugin: page display_plugin: page
display_title: Page display_title: Page
id: page_1 id: page_1
position: 1 position: 1
label: Content
module: node
id: content
tag: default
langcode: en
dependencies:
module:
- node
- user
base_field: nid langcode: en
status: true
dependencies:
module:
- node
id: frontpage
label: Frontpage
module: node
description: 'All content promoted to the front page.'
tag: default
base_table: node base_table: node
base_field: nid
core: 8.x core: 8.x
description: 'All content promoted to the front page.'
status: true
display: display:
default: default:
display_options: display_options:
...@@ -110,6 +118,48 @@ display: ...@@ -110,6 +118,48 @@ display:
value: true value: true
plugin_id: boolean plugin_id: boolean
provider: views provider: views
langcode:
id: langcode
table: node_field_data
field: langcode
relationship: none
group_type: group
admin_label: ''
dependencies:
module:
- views
operator: in
value:
'***CURRENT_LANGUAGE***': '***CURRENT_LANGUAGE***'
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: language
provider: views
pager: pager:
type: full type: full
options: options:
...@@ -190,6 +240,8 @@ display: ...@@ -190,6 +240,8 @@ display:
relationships: { } relationships: { }
fields: { } fields: { }
arguments: { } arguments: { }
field_langcode: '***CURRENT_LANGUAGE***'
field_langcode_add_to_query: null
display_plugin: default display_plugin: default
display_title: Master display_title: Master
id: default id: default
...@@ -197,6 +249,8 @@ display: ...@@ -197,6 +249,8 @@ display:
page_1: page_1:
display_options: display_options:
path: node path: node
field_langcode: '***CURRENT_LANGUAGE***'
field_langcode_add_to_query: null
display_plugin: page display_plugin: page
display_title: Page display_title: Page
id: page_1 id: page_1
...@@ -232,11 +286,5 @@ display: ...@@ -232,11 +286,5 @@ display:
view_mode: rss view_mode: rss
links: false links: false
provider: views provider: views
label: Frontpage field_langcode: '***CURRENT_LANGUAGE***'
module: node field_langcode_add_to_query: null
id: frontpage
tag: default
langcode: en
dependencies:
module:
- node
...@@ -245,13 +245,6 @@ function testTranslationRendering() { ...@@ -245,13 +245,6 @@ function testTranslationRendering() {
$display['display_options']['row']['options']['rendering_language'] = 'translation_language_renderer'; $display['display_options']['row']['options']['rendering_language'] = 'translation_language_renderer';
$view->save(); $view->save();
// Test that the frontpage view displays all translated nodes correctly by
// checking that the title for each translation is present.
$this->drupalGet('node');
foreach ($this->langcodes as $langcode) {
$this->assertText($values[$langcode]['title'][0]['value']);
}
// Need to check from the beginning, including the base_path, in the url // Need to check from the beginning, including the base_path, in the url
// since the pattern for the default language might be a substring of // since the pattern for the default language might be a substring of
// the strings for other languages. // the strings for other languages.
...@@ -261,6 +254,7 @@ function testTranslationRendering() { ...@@ -261,6 +254,7 @@ function testTranslationRendering() {
// See also assertTaxonomyPage() in NodeAccessBaseTableTest. // See also assertTaxonomyPage() in NodeAccessBaseTableTest.
$node_href = 'node/' . $node->id(); $node_href = 'node/' . $node->id();
foreach ($this->langcodes as $langcode) { foreach ($this->langcodes as $langcode) {
$this->drupalGet('node', array('language' => \Drupal::languageManager()->getLanguage($langcode)));
$num_match_found = 0; $num_match_found = 0;
if ($langcode == 'en') { if ($langcode == 'en') {
// Site default language does not have langcode prefix in the URL. // Site default language does not have langcode prefix in the URL.
...@@ -282,6 +276,7 @@ function testTranslationRendering() { ...@@ -282,6 +276,7 @@ function testTranslationRendering() {
// language. // language.
$comment_form_href = 'node/' . $node->id() . '#comment-form'; $comment_form_href = 'node/' . $node->id() . '#comment-form';
foreach ($this->langcodes as $langcode) { foreach ($this->langcodes as $langcode) {
$this->drupalGet('node', array('language' => \Drupal::languageManager()->getLanguage($langcode)));
$num_match_found = 0; $num_match_found = 0;
if ($langcode == 'en') { if ($langcode == 'en') {
// Site default language does not have langcode prefix in the URL. // Site default language does not have langcode prefix in the URL.
......
...@@ -70,23 +70,24 @@ function setUp() { ...@@ -70,23 +70,24 @@ function setUp() {
// "English", or "Spanish", as there is a language field in the view // "English", or "Spanish", as there is a language field in the view
// that prints out those words. // that prints out those words.
$this->node_titles = array( $this->node_titles = array(
'en' => array(
'First node en',
'Second node en',
),
'es' => array( 'es' => array(
'Primero nodo es', 'Primero nodo es',
'Segundo nodo es', 'Segundo nodo es',
'Tercera nodo es',
),
'en' => array(
'First node en',
'Second node en',
), ),
'fr' => array( 'fr' => array(
'Premier nodule fr', 'Premier nœud fr',
) )
); );
// Create nodes with translations. // Create nodes with translations.
foreach ($this->node_titles['en'] as $index => $title) { foreach ($this->node_titles['es'] as $index => $title) {
$node = $this->drupalCreateNode(array('title' => $title, 'langcode' => 'en', 'type' => 'page')); $node = $this->drupalCreateNode(array('title' => $title, 'langcode' => 'es', 'type' => 'page', 'promote' => 1));
foreach (array('es', 'fr') as $langcode) { foreach (array('en', 'fr') as $langcode) {
if (isset($this->node_titles[$langcode][$index])) { if (isset($this->node_titles[$langcode][$index])) {
$translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode][$index])); $translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode][$index]));
$translation->body->value = $this->randomName(32); $translation->body->value = $this->randomName(32);
...@@ -94,6 +95,9 @@ function setUp() { ...@@ -94,6 +95,9 @@ function setUp() {
} }
$node->save(); $node->save();
} }
$user = $this->drupalCreateUser(array('access content overview', 'access content'));
$this->drupalLogin($user);
} }
/** /**
...@@ -142,5 +146,43 @@ public function testLanguages() { ...@@ -142,5 +146,43 @@ public function testLanguages() {
$this->assertNoText('English', 'English language is not shown on ' . $message); $this->assertNoText('English', 'English language is not shown on ' . $message);
$this->assertNoText('French', 'French language is not shown on ' . $message); $this->assertNoText('French', 'French language is not shown on ' . $message);
$this->assertText('Spanish', 'Spanish language is shown on ' . $message); $this->assertText('Spanish', 'Spanish language is shown on ' . $message);
// Test the front page view filter. Only node titles in the current language
// should be displayed on the front page by default.
foreach ($this->node_titles as $langcode => $titles) {
$this->drupalGet(($langcode == 'en' ? '' : "$langcode/") . 'node');
foreach ($titles as $title) {
$this->assertText($title);
}
foreach ($this->node_titles as $control_langcode => $control_titles) {
if ($langcode != $control_langcode) {
foreach ($control_titles as $title) {
$this->assertNoText($title);
}
}
}
}
// Test the node admin view filter. By default all translations should show.
$this->drupalGet('admin/content');
foreach ($this->node_titles as $titles) {
foreach ($titles as $title) {
$this->assertText($title);
}
}
// When filtered, only the specific languages should show.
foreach ($this->node_titles as $langcode => $titles) {
$this->drupalGet('admin/content', array('query' => array('langcode' => $langcode)));
foreach ($titles as $title) {
$this->assertText($title);
}
foreach ($this->node_titles as $control_langcode => $control_titles) {
if ($langcode != $control_langcode) {
foreach ($control_titles as $title) {
$this->assertNoText($title);
}
}
}
}
} }
} }
...@@ -330,6 +330,16 @@ views_handler: ...@@ -330,6 +330,16 @@ views_handler:
provider: provider:
type: string type: string
label: 'Provider' label: 'Provider'
dependencies:
type: mapping
label: 'Dependencies'
mapping:
module:
type: sequence
label: 'Modules'
sequence:
- type: string
label: 'Dependency'
views_argument: views_argument:
type: views_handler type: views_handler
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment