Issue #2161845 by Gábor Hojtsy, vijaycs85 | YesCT: Fixed Node views (front page, admin) do not use the proper language filter.

8.0.x
Alex Pott 2014-08-05 12:24:54 +01:00
parent 19595c2472
commit fa9e8bbe50
7 changed files with 172 additions and 72 deletions

View File

@ -199,30 +199,4 @@ class LocaleContentTest extends WebTestBase {
$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');
}
}

View File

@ -39,7 +39,7 @@ class LocalePathTest extends WebTestBase {
*/
public function testPathLanguageConfiguration() {
// 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.
$this->drupalLogin($admin_user);
@ -135,11 +135,11 @@ class LocalePathTest extends WebTestBase {
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
// 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;
$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.');
$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.');
// Confirm that the custom path leads to the first node.

View File

@ -1,8 +1,18 @@
base_field: nid
base_table: node
core: 8.x
description: 'Find and manage content.'
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_field: nid
core: 8.x
display:
default:
display_options:
@ -459,8 +469,14 @@ display:
provider: views
langcode:
id: langcode
table: node_revision
table: node_field_data
field: langcode
relationship: none
group_type: group
admin_label: ''
dependencies:
module:
- views
operator: in
value: { }
group: 1
@ -468,12 +484,32 @@ display:
expose:
operator_id: langcode_op
label: Language
description: ''
use_operator: false
operator: langcode_op
identifier: langcode
required: false
remember: false
multiple: false
remember_roles:
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
provider: language
provider: views
sorts: { }
title: Content
empty:
@ -500,6 +536,8 @@ display:
operator: AND
groups:
1: AND
field_langcode: '***CURRENT_LANGUAGE***'
field_langcode_add_to_query: null
display_plugin: default
display_title: Master
id: default
@ -520,16 +558,9 @@ display:
description: 'Find and manage content'
name: admin
weight: -10
field_langcode: '***CURRENT_LANGUAGE***'
field_langcode_add_to_query: null
display_plugin: page
display_title: Page
id: page_1
position: 1
label: Content
module: node
id: content
tag: default
langcode: en
dependencies:
module:
- node
- user

View File

@ -1,8 +1,16 @@
base_field: nid
base_table: node
core: 8.x
description: 'All content promoted to the front page.'
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_field: nid
core: 8.x
display:
default:
display_options:
@ -110,6 +118,48 @@ display:
value: true
plugin_id: boolean
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:
type: full
options:
@ -190,6 +240,8 @@ display:
relationships: { }
fields: { }
arguments: { }
field_langcode: '***CURRENT_LANGUAGE***'
field_langcode_add_to_query: null
display_plugin: default
display_title: Master
id: default
@ -197,6 +249,8 @@ display:
page_1:
display_options:
path: node
field_langcode: '***CURRENT_LANGUAGE***'
field_langcode_add_to_query: null
display_plugin: page
display_title: Page
id: page_1
@ -232,11 +286,5 @@ display:
view_mode: rss
links: false
provider: views
label: Frontpage
module: node
id: frontpage
tag: default
langcode: en
dependencies:
module:
- node
field_langcode: '***CURRENT_LANGUAGE***'
field_langcode_add_to_query: null

View File

@ -245,13 +245,6 @@ class NodeTranslationUITest extends ContentTranslationUITest {
$display['display_options']['row']['options']['rendering_language'] = 'translation_language_renderer';
$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
// since the pattern for the default language might be a substring of
// the strings for other languages.
@ -261,6 +254,7 @@ class NodeTranslationUITest extends ContentTranslationUITest {
// See also assertTaxonomyPage() in NodeAccessBaseTableTest.
$node_href = 'node/' . $node->id();
foreach ($this->langcodes as $langcode) {
$this->drupalGet('node', array('language' => \Drupal::languageManager()->getLanguage($langcode)));
$num_match_found = 0;
if ($langcode == 'en') {
// Site default language does not have langcode prefix in the URL.
@ -282,6 +276,7 @@ class NodeTranslationUITest extends ContentTranslationUITest {
// language.
$comment_form_href = 'node/' . $node->id() . '#comment-form';
foreach ($this->langcodes as $langcode) {
$this->drupalGet('node', array('language' => \Drupal::languageManager()->getLanguage($langcode)));
$num_match_found = 0;
if ($langcode == 'en') {
// Site default language does not have langcode prefix in the URL.

View File

@ -70,23 +70,24 @@ class NodeLanguageTest extends NodeTestBase {
// "English", or "Spanish", as there is a language field in the view
// that prints out those words.
$this->node_titles = array(
'es' => array(
'Primero nodo es',
'Segundo nodo es',
'Tercera nodo es',
),
'en' => array(
'First node en',
'Second node en',
),
'es' => array(
'Primero nodo es',
'Segundo nodo es',
),
'fr' => array(
'Premier nodule fr',
'Premier nœud fr',
)
);
// Create nodes with translations.
foreach ($this->node_titles['en'] as $index => $title) {
$node = $this->drupalCreateNode(array('title' => $title, 'langcode' => 'en', 'type' => 'page'));
foreach (array('es', 'fr') as $langcode) {
foreach ($this->node_titles['es'] as $index => $title) {
$node = $this->drupalCreateNode(array('title' => $title, 'langcode' => 'es', 'type' => 'page', 'promote' => 1));
foreach (array('en', 'fr') as $langcode) {
if (isset($this->node_titles[$langcode][$index])) {
$translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode][$index]));
$translation->body->value = $this->randomName(32);
@ -94,6 +95,9 @@ class NodeLanguageTest extends NodeTestBase {
}
$node->save();
}
$user = $this->drupalCreateUser(array('access content overview', 'access content'));
$this->drupalLogin($user);
}
/**
@ -142,5 +146,43 @@ class NodeLanguageTest extends NodeTestBase {
$this->assertNoText('English', 'English 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);
// 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);
}
}
}
}
}
}

View File

@ -330,6 +330,16 @@ views_handler:
provider:
type: string
label: 'Provider'
dependencies:
type: mapping
label: 'Dependencies'
mapping:
module:
type: sequence
label: 'Modules'
sequence:
- type: string
label: 'Dependency'
views_argument:
type: views_handler