-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #1829734 by dawehner, damiankloip, cam8001, dww: Expose tracker…
… data to views.
- Loading branch information
Nathaniel Catchpole
committed
May 5, 2013
1 parent
d9da0cc
commit a54b1c5
Showing
8 changed files
with
563 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\tracker\Plugin\views\argument\UserUid | ||
*/ | ||
|
||
namespace Drupal\tracker\Plugin\views\argument; | ||
|
||
use Drupal\Component\Annotation\PluginID; | ||
use Drupal\comment\Plugin\views\argument\UserUid as CommentUserUid; | ||
|
||
/** | ||
* UID argument to check for nodes that user posted or commented on. | ||
* | ||
* @ingroup views_argument_handlers | ||
* | ||
* @PluginID("tracker_user_uid") | ||
*/ | ||
class UserUid extends CommentUserUid { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function query($group_by = FALSE) { | ||
// Because this handler thinks it's an argument for a field on the {node} | ||
// table, we need to make sure {tracker_user} is JOINed and use its alias | ||
// for the WHERE clause. | ||
$tracker_user_alias = $this->query->ensure_table('tracker_user'); | ||
$this->query->add_where(0, "$tracker_user_alias.uid", $this->argument); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\tracker\Plugin\views\filter\UserUid. | ||
*/ | ||
|
||
namespace Drupal\tracker\Plugin\views\filter; | ||
|
||
use Drupal\Component\Annotation\PluginID; | ||
use Drupal\user\Plugin\views\filter\Name; | ||
|
||
/** | ||
* UID filter to check for nodes that a user posted or commented on. | ||
* | ||
* @ingroup views_filter_handlers | ||
* | ||
* @PluginID("tracker_user_uid") | ||
*/ | ||
class UserUid extends Name { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function query() { | ||
// Because this handler thinks it's an argument for a field on the {node} | ||
// table, we need to make sure {tracker_user} is JOINed and use its alias | ||
// for the WHERE clause. | ||
$tracker_user_alias = $this->query->ensure_table('tracker_user'); | ||
$this->query->add_where(0, "$tracker_user_alias.uid", $this->value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\tracker\Tests\Views\TrackerTestBase. | ||
*/ | ||
|
||
namespace Drupal\tracker\Tests\Views; | ||
|
||
use Drupal\views\Tests\ViewTestBase; | ||
use Drupal\views\Tests\ViewTestData; | ||
|
||
/** | ||
* Base class for all tracker tests. | ||
*/ | ||
abstract class TrackerTestBase extends ViewTestBase { | ||
|
||
/** | ||
* Modules to enable. | ||
* | ||
* @var array | ||
*/ | ||
public static $modules = array('comment', 'tracker', 'tracker_test_views'); | ||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
ViewTestData::importTestViews(get_class($this), array('tracker_test_views')); | ||
|
||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); | ||
|
||
$permissions = array('access comments', 'create page content', 'post comments', 'skip comment approval'); | ||
$account = $this->drupalCreateUser($permissions); | ||
|
||
$this->drupalLogin($account); | ||
|
||
$this->node = $this->drupalCreateNode(array( | ||
'title' => $this->randomName(8), | ||
'uid' => $account->id(), | ||
'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), | ||
)); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\tracker\Tests\Views\TrackerUserUidTest. | ||
*/ | ||
|
||
namespace Drupal\tracker\Tests\Views; | ||
|
||
/** | ||
* Tests the tracker user uid handlers. | ||
*/ | ||
class TrackerUserUidTest extends TrackerTestBase { | ||
|
||
/** | ||
* Views used by this test. | ||
* | ||
* @var array | ||
*/ | ||
public static $testViews = array('test_tracker_user_uid'); | ||
|
||
public static function getInfo() { | ||
return array( | ||
'name' => '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->node->uid; | ||
$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->node->uid)); | ||
$this->assertIdenticalResultSet($view, $expected, $map); | ||
} | ||
|
||
} |
178 changes: 178 additions & 0 deletions
178
tests/modules/tracker_test_views/test_views/views.view.test_tracker_user_uid.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
Oops, something went wrong.