From fa9e8bbe5068097314f94511963a6503b6027dfb Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 5 Aug 2014 12:24:54 +0100 Subject: [PATCH] =?UTF-8?q?Issue=20#2161845=20by=20G=C3=A1bor=20Hojtsy,=20?= =?UTF-8?q?vijaycs85=20|=20YesCT:=20Fixed=20Node=20views=20(front=20page,?= =?UTF-8?q?=20admin)=20do=20not=20use=20the=20proper=20language=20filter.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../locale/src/Tests/LocaleContentTest.php | 26 ------- .../locale/src/Tests/LocalePathTest.php | 8 +-- .../config/install/views.view.content.yml | 61 ++++++++++++---- .../config/install/views.view.frontpage.yml | 72 +++++++++++++++---- .../node/src/Tests/NodeTranslationUITest.php | 9 +-- .../node/src/Tests/Views/NodeLanguageTest.php | 58 ++++++++++++--- .../config/schema/views.data_types.schema.yml | 10 +++ 7 files changed, 172 insertions(+), 72 deletions(-) diff --git a/core/modules/locale/src/Tests/LocaleContentTest.php b/core/modules/locale/src/Tests/LocaleContentTest.php index c0ffd60b6b0..0c3d4765b53 100644 --- a/core/modules/locale/src/Tests/LocaleContentTest.php +++ b/core/modules/locale/src/Tests/LocaleContentTest.php @@ -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'); - } - } diff --git a/core/modules/locale/src/Tests/LocalePathTest.php b/core/modules/locale/src/Tests/LocalePathTest.php index 4876043cd0d..4a87f123957 100644 --- a/core/modules/locale/src/Tests/LocalePathTest.php +++ b/core/modules/locale/src/Tests/LocalePathTest.php @@ -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(''); + $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. diff --git a/core/modules/node/config/install/views.view.content.yml b/core/modules/node/config/install/views.view.content.yml index 3ea06e7b166..855b44a4742 100644 --- a/core/modules/node/config/install/views.view.content.yml +++ b/core/modules/node/config/install/views.view.content.yml @@ -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 diff --git a/core/modules/node/config/install/views.view.frontpage.yml b/core/modules/node/config/install/views.view.frontpage.yml index 23931d3b82a..a7f8a281d35 100644 --- a/core/modules/node/config/install/views.view.frontpage.yml +++ b/core/modules/node/config/install/views.view.frontpage.yml @@ -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 diff --git a/core/modules/node/src/Tests/NodeTranslationUITest.php b/core/modules/node/src/Tests/NodeTranslationUITest.php index ea4cb9f5a83..85e2933344c 100644 --- a/core/modules/node/src/Tests/NodeTranslationUITest.php +++ b/core/modules/node/src/Tests/NodeTranslationUITest.php @@ -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. diff --git a/core/modules/node/src/Tests/Views/NodeLanguageTest.php b/core/modules/node/src/Tests/Views/NodeLanguageTest.php index fa394b23a2c..9ad8c988770 100644 --- a/core/modules/node/src/Tests/Views/NodeLanguageTest.php +++ b/core/modules/node/src/Tests/Views/NodeLanguageTest.php @@ -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); + } + } + } + } } } diff --git a/core/modules/views/config/schema/views.data_types.schema.yml b/core/modules/views/config/schema/views.data_types.schema.yml index 3cef2658a01..8ebcea01c6c 100644 --- a/core/modules/views/config/schema/views.data_types.schema.yml +++ b/core/modules/views/config/schema/views.data_types.schema.yml @@ -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