diff --git a/core/modules/tracker/lib/Drupal/tracker/Plugin/views/argument/TrackerUserUid.php b/core/modules/tracker/lib/Drupal/tracker/Plugin/views/argument/TrackerUserUid.php new file mode 100644 index 0000000..dbe0d09 --- /dev/null +++ b/core/modules/tracker/lib/Drupal/tracker/Plugin/views/argument/TrackerUserUid.php @@ -0,0 +1,36 @@ +query->ensure_table('tracker_user'); + $this->query->add_where(0, "$tracker_user_alias.uid", $this->argument); + } + +} diff --git a/core/modules/tracker/lib/Drupal/tracker/Plugin/views/filter/TrackerUserUid.php b/core/modules/tracker/lib/Drupal/tracker/Plugin/views/filter/TrackerUserUid.php new file mode 100644 index 0000000..81ae89b --- /dev/null +++ b/core/modules/tracker/lib/Drupal/tracker/Plugin/views/filter/TrackerUserUid.php @@ -0,0 +1,36 @@ +query->ensure_table('tracker_user'); + $this->query->add_where(0, "$tracker_user_alias.uid", $this->value); + } + +} diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/Views/TrackerTestBase.php b/core/modules/tracker/lib/Drupal/tracker/Tests/Views/TrackerTestBase.php new file mode 100644 index 0000000..7aff628 --- /dev/null +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/Views/TrackerTestBase.php @@ -0,0 +1,51 @@ +drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + + $permissions = array('access comments', 'create page content', 'post comments', 'skip comment approval'); + $this->user = $this->drupalCreateUser($permissions); + + $this->drupalLogin($this->user); + + $this->node = $this->drupalCreateNode(array( + 'title' => $this->randomName(8), + 'uid' => $this->user->uid, + 'status' => 1, + )); + + $this->comment = entity_create('comment', array( + 'nid' => $this->node->id(), + 'subject' => $this->randomName(), + 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this->randomName(20), + )); + + } + +} diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/Views/TrackerUserUidTest.php b/core/modules/tracker/lib/Drupal/tracker/Tests/Views/TrackerUserUidTest.php new file mode 100644 index 0000000..c165a71 --- /dev/null +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/Views/TrackerUserUidTest.php @@ -0,0 +1,77 @@ + 'Tracker: User UID tests', + 'description' => 'Tests the tracker comment user uid handlers.', + 'group' => 'Views module integration', + ); + } + + /** + * Tests the user uid filter and argument. + */ + public function testUserUid() { + $map = array( + 'nid' => 'nid', + 'node_title' => 'title', + ); + + $expected = array( + array( + 'nid' => $this->node->id(), + 'title' => $this->node->label(), + ) + ); + + $view = views_get_view('test_tracker_user_uid'); + $this->executeView($view); + + // We should have no results as the filter is set for uid 0. + $this->assertIdenticalResultSet($view, array(), $map); + $view->destroy(); + + // Change the filter value to our user. + $view->initHandlers(); + $view->filter['uid_touch_tracker']->value = $this->user->id(); + $this->executeView($view); + + // We should have one result as the filter is set for the created user. + $this->assertIdenticalResultSet($view, $expected, $map); + $view->destroy(); + + // Remove the filter now, so only the argument will affect the query. + $view->removeItem('default', 'filter', 'uid_touch_tracker'); + + // Test the incorrect argument UID. + $view->initHandlers(); + $this->executeView($view, array(rand())); + $this->assertIdenticalResultSet($view, array(), $map); + $view->destroy(); + + // Test the correct argument UID. + $view->initHandlers(); + $this->executeView($view, array($this->user->id())); + $this->assertIdenticalResultSet($view, $expected, $map); + } + +} diff --git a/core/modules/tracker/tests/modules/tracker_test_views/test_views/views.view.test_tracker_user_uid.yml b/core/modules/tracker/tests/modules/tracker_test_views/test_views/views.view.test_tracker_user_uid.yml new file mode 100644 index 0000000..9f6ee9b --- /dev/null +++ b/core/modules/tracker/tests/modules/tracker_test_views/test_views/views.view.test_tracker_user_uid.yml @@ -0,0 +1,178 @@ +base_field: nid +base_table: node +core: 8.x +description: '' +status: '1' +display: + default: + display_plugin: default + id: default + display_title: Master + position: '' + display_options: + access: + type: perm + cache: + type: none + query: + type: views_query + exposed_form: + type: basic + pager: + type: full + style: + type: table + options: + grouping: { } + row_class: '' + default_row_class: '1' + row_class_special: '1' + override: '1' + sticky: '0' + summary: '' + columns: + title: title + info: + title: + sortable: '1' + default_sort_order: asc + align: '' + separator: '' + empty_column: '0' + responsive: '' + default: '-1' + empty_table: '0' + row: + type: fields + fields: + title: + id: title + table: node + field: title + relationship: none + group_type: group + admin_label: '' + label: Title + exclude: '0' + alter: + alter_text: '0' + text: '' + make_link: '0' + path: '' + absolute: '0' + external: '0' + replace_spaces: '0' + path_case: none + trim_whitespace: '0' + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: '0' + max_length: '' + word_boundary: '0' + ellipsis: '0' + more_link: '0' + more_link_text: '' + more_link_path: '' + strip_tags: '0' + trim: '0' + preserve_tags: '' + html: '0' + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: '1' + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: '1' + empty: '' + hide_empty: '0' + empty_zero: '0' + hide_alter_empty: '1' + link_to_node: '1' + filters: + uid_touch_tracker: + id: uid_touch_tracker + table: node + field: uid_touch_tracker + relationship: none + group_type: group + admin_label: '' + operator: in + value: + - '0' + group: '1' + exposed: '0' + expose: + operator_id: '' + label: 'User posted or commented' + description: '' + use_operator: '0' + operator: uid_touch_tracker_op + identifier: uid_touch_tracker + required: '0' + remember: '0' + multiple: '0' + remember_roles: + authenticated: authenticated + anonymous: '0' + administrator: '0' + reduce: '0' + is_grouped: '0' + group_info: + label: '' + description: '' + identifier: '' + optional: '1' + widget: select + multiple: '0' + remember: '0' + default_group: All + default_group_multiple: { } + group_items: { } + plugin_id: tracker_user_uid + arguments: + uid_touch_tracker: + id: uid_touch_tracker + table: node + field: uid_touch_tracker + relationship: none + group_type: group + admin_label: '' + default_action: ignore + exception: + value: all + title_enable: '0' + title: All + title_enable: '0' + title: '' + breadcrumb_enable: '0' + breadcrumb: '' + default_argument_type: fixed + default_argument_options: + argument: '' + default_argument_skip_url: '0' + summary_options: + base_path: '' + count: '1' + items_per_page: '25' + override: '0' + summary: + sort_order: asc + number_of_records: '0' + format: default_summary + specify_validation: '0' + validate: + type: none + fail: 'not found' + validate_options: { } + plugin_id: tracker_user_uid +human_name: 'tracker test' +module: views +id: test_tracker_user_uid +tag: '' +langcode: en diff --git a/core/modules/tracker/tests/modules/tracker_test_views/tracker_test_views.info.yml b/core/modules/tracker/tests/modules/tracker_test_views/tracker_test_views.info.yml new file mode 100644 index 0000000..ad9bccc --- /dev/null +++ b/core/modules/tracker/tests/modules/tracker_test_views/tracker_test_views.info.yml @@ -0,0 +1,9 @@ +name: 'Tracker test views' +description: 'Provides default views for views tracker tests.' +package: Testing +version: VERSION +core: 8.x +dependencies: + - tracker + - views +hidden: true diff --git a/core/modules/tracker/tests/modules/tracker_test_views/tracker_test_views.module b/core/modules/tracker/tests/modules/tracker_test_views/tracker_test_views.module new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/core/modules/tracker/tests/modules/tracker_test_views/tracker_test_views.module @@ -0,0 +1 @@ + array( + 'type' => 'INNER', + 'left_field' => 'nid', + 'field' => 'nid', + ), + ); + $data['tracker_node']['nid'] = array( + 'title' => t('Nid'), + 'help' => t('The node ID of the node.'), + 'field' => array( + 'id' => 'node', + ), + 'argument' => array( + 'id' => 'node_nid', + 'name field' => 'title', + 'numeric' => TRUE, + 'validate type' => 'nid', + ), + 'filter' => array( + 'id' => 'numeric', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + $data['tracker_node']['published'] = array( + 'title' => t('Published'), + 'help' => t('Whether or not the node is published.'), + 'field' => array( + 'id' => 'boolean', + ), + 'filter' => array( + 'id' => 'boolean', + 'label' => t('Published'), + 'type' => 'yes-no', + 'accept null' => TRUE, + 'use_equal' => TRUE, + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + $data['tracker_node']['changed'] = array( + 'title' => t('Updated date'), + 'help' => t('The date the node was last updated.'), + 'field' => array( + 'id' => 'date', + ), + 'sort' => array( + 'id' => 'date', + ), + 'filter' => array( + 'id' => 'date', + ), + ); + + $data['tracker_user']['table']['group'] = t('Tracker - User'); + $data['tracker_user']['table']['join'] = array( + 'node' => array( + 'type' => 'INNER', + 'left_field' => 'nid', + 'field' => 'nid', + ), + 'user' => array( + 'type' => 'INNER', + 'left_field' => 'uid', + 'field' => 'uid', + ), + ); + $data['tracker_user']['nid'] = array( + 'title' => t('Nid'), + 'help' => t('The node ID of the node a user created or commented on. You must use an argument or filter on UID or you will get misleading results using this field.'), + 'field' => array( + 'id' => 'node', + ), + 'argument' => array( + 'id' => 'node_nid', + 'name field' => 'title', + 'numeric' => TRUE, + 'validate type' => 'nid', + ), + 'filter' => array( + 'id' => 'numeric', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + $data['tracker_user']['uid'] = array( + 'title' => t('Uid'), + 'help' => t('The user ID of a user who touched the node (either created or commented on it).'), + 'field' => array( + 'id' => 'user_name', + ), + 'argument' => array( + 'id' => 'user_uid', + 'name field' => 'name', + ), + 'filter' => array( + 'title' => t('Name'), + 'id' => 'user_name', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + $data['tracker_user']['published'] = array( + 'title' => t('Published'), + 'help' => t('Whether or not the node is published. You must use an argument or filter on UID or you will get misleading results using this field.'), + 'field' => array( + 'id' => 'boolean', + ), + 'filter' => array( + 'id' => 'boolean', + 'label' => t('Published'), + 'type' => 'yes-no', + 'accept null' => TRUE, + 'use_equal' => TRUE, + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + $data['tracker_user']['changed'] = array( + 'title' => t('Updated date'), + 'help' => t('The date the node was last updated or commented on. You must use an argument or filter on UID or you will get misleading results using this field.'), + 'field' => array( + 'id' => 'date', + ), + 'sort' => array( + 'id' => 'date', + ), + 'filter' => array( + 'id' => 'date', + ), + ); + + return $data; +} + +/** + * Implementation of hook_views_data_alter(). + */ +function tracker_views_data_alter(&$data) { + // Provide additional uid_touch handlers which are handled by tracker + $data['node']['uid_touch_tracker'] = array( + 'group' => t('Tracker - User'), + 'title' => t('User posted or commented'), + 'help' => t('Display nodes only if a user posted the node or commented on the node.'), + 'argument' => array( + 'field' => 'uid', + 'name table' => 'users', + 'name field' => 'name', + 'id' => 'tracker_user_uid', + 'no group by' => TRUE, + ), + 'filter' => array( + 'field' => 'uid', + 'name table' => 'users', + 'name field' => 'name', + 'id' => 'tracker_user_uid' + ), + ); +}