From 1a27f91fae0df90b7f261e9924a856495e05a020 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Sat, 7 Aug 2010 02:41:26 -0500 Subject: [PATCH] display project name on the project issue to link filter --- project_issue.module | 37 ++++++++++++++------ project_issue.test | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 11 deletions(-) diff --git project_issue.module project_issue.module index 32c2428..481fd3d 100644 --- project_issue.module +++ project_issue.module @@ -398,6 +398,7 @@ function project_issue_theme() { 'comment_id' => NULL, 'comment_number' => NULL, 'include_assigned' => FALSE, + 'include_project_name' => FALSE, ), ), 'project_issue_issue_cockpit' => array( @@ -1127,9 +1128,15 @@ function project_issue_link_alter(&$links, $node) { * The comment's number, as visible to users, optional. * @param $include_assigned * Optional boolean to include the user the issue is assigned to. + * @param $include_project_name + * Optional boolean to include the name of the project the issue belongs to. */ -function theme_project_issue_issue_link($node, $comment_id = NULL, $comment_number = NULL, $include_assigned = FALSE) { +function theme_project_issue_issue_link($node, $comment_id = NULL, $comment_number = NULL, $include_assigned = FALSE, $include_project_name = FALSE) { $path = "node/$node->nid"; + if ($include_project_name) { + $project_node = node_load($node->project_issue['pid']); + $project_name = $project_node->project['uri']; + } // See if the issue is assigned to anyone. If so, we'll include it either // in the title attribute on hover, or next to the issue link if there was @@ -1152,14 +1159,17 @@ function theme_project_issue_issue_link($node, $comment_id = NULL, $comment_numb $attributes = array('title' => t('Status: !status', array('!status' => project_issue_state($node->project_issue['sid'])))); } + $title = "#$node->nid"; + $options = array('attributes' => $attributes); if (isset($comment_id)) { - $title = "#$node->nid-$comment_number: $node->title"; - $link = l($title, $path, array('attributes' => $attributes, 'fragment' => "comment-$comment_id")); + $title .= "-$comment_number"; + $options['fragment'] = "comment-$comment_id"; } - else { - $title = "#$node->nid: $node->title"; - $link = l($title, $path, array('attributes' => $attributes)); + if ($include_project_name) { + $title .= " [$project_name]"; } + $title .= ": $node->title"; + $link = l($title, $path, $options); $output = ''. $link; if ($include_assigned && !empty($username)) { $output .= ' '. t('Assigned to: @username', array('@username' => $username)) .''; @@ -1196,7 +1206,7 @@ function project_issue_filter($op, $delta = 0, $format = -1, $text = '') { case 'prepare': return $text; case 'process': - $regex = '(?:(?.*?<\/pre>|.*?<\/code>|"\']|"[^"]*"|\'[^\']*\')*>.*?<\/a>'; + $regex = '(?:(?.*?<\/pre>|.*?<\/code>|"\']|"[^"]*"|\'[^\']*\')*>.*?<\/a>'; $text = preg_replace_callback("/$regex/", 'project_issue_link_filter_callback', $text); return $text; @@ -1205,21 +1215,26 @@ function project_issue_filter($op, $delta = 0, $format = -1, $text = '') { function project_issue_link_filter_callback($matches) { $parts = array(); - if (preg_match('/^\[#(\d+)(?:-(\d+))?(@)?\]$/', $matches[0], $parts)) { + if (preg_match('/^\[#(\d+)(?:-(\d+))?([@P]{1,2})?\]$/', $matches[0], $parts)) { $nid = $parts[1]; $node = node_load($nid); - $include_assigned = isset($parts[3]); + $include_assigned = FALSE; + $include_project_name = FALSE; + if (isset($parts[3])) { + $include_assigned = strpos($parts[3], '@') !== FALSE; + $include_project_name = strpos($parts[3], 'P') !== FALSE; + } if (is_object($node) && node_access('view', $node) && $node->type == 'project_issue') { if (isset($parts[2])) { // Pull comment id based on the comment number if we have one. $comment_number = $parts[2]; if ($comment_id = db_result(db_query("SELECT pic.cid FROM {project_issue_comments} pic INNER JOIN {comments} c ON pic.cid = c.cid WHERE pic.nid = %d AND pic.comment_number = %d AND c.status = %d", $nid, $comment_number, COMMENT_PUBLISHED))) { - return theme('project_issue_issue_link', $node, $comment_id, $comment_number, $include_assigned); + return theme('project_issue_issue_link', $node, $comment_id, $comment_number, $include_assigned, $include_project_name); } } // If we got this far there wasn't a valid comment number, so just link // to the node instead. - return theme('project_issue_issue_link', $node, NULL, NULL, $include_assigned); + return theme('project_issue_issue_link', $node, NULL, NULL, $include_assigned, $include_project_name); } } // If we haven't already returned a replacement, return the original text. diff --git project_issue.test project_issue.test index 7e7334e..ed66368 100644 --- project_issue.test +++ project_issue.test @@ -375,3 +375,96 @@ class ProjectIssuePriorityTestCase extends ProjectIssueWebTestCase { // $this->assertEqual((string)$rows[2], $critical_issue->title); } } + +class ProjectIssueLinkFilterTestCase extends ProjectIssueWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Project issue link filter', + 'description' => 'Test issue link filter functionality.', + 'group' => 'Project Issue', + ); + } + + function setUp() { + parent::setUp(); + $this->maintain_user = $this->drupalCreateUser(array('administer filters', 'administer projects', 'maintain projects', 'create project issues', 'access project issues', 'access projects')); + $this->drupalLogin($this->maintain_user); + } + + /** + * Test the issue link filter. + */ + function testLinkFilter() { + // Add an input filter that will be used to test. + $settings = array( + 'name' => 'Issue link', + 'filters[project_issue/0]' => TRUE, + ); + $this->drupalPost('admin/settings/filters/add', $settings, t('Save configuration')); + + // Create basic data. + $project = $this->createProject(); + $refered_issue = $this->createIssue($project); + // FIXME get the right value on creation instead of assuming the two + // default drupal input formats + $edit['format'] = '3'; + + // simple case + $edit['body'] = "[#$refered_issue->nid]"; + $this->createIssue($project, $edit); + $this->assertText("#$refered_issue->nid: $refered_issue->title"); + + // simple case with comment + $this->createIssueComment($refered_issue); + $edit['body'] = "[#$refered_issue->nid-1]"; + $this->createIssue($project, $edit); + $this->assertText("#$refered_issue->nid-1: $refered_issue->title"); + + // including assigned + $this->createIssueComment($refered_issue, array('project_info[assigned]' => $this->maintain_user->uid)); + $edit['body'] = "[#$refered_issue->nid@]"; + $this->createIssue($project, $edit); + $this->assertText("#$refered_issue->nid: $refered_issue->title"); + $this->assertText("Assigned to: {$this->maintain_user->name}"); + + // with comment including assigned + $edit['body'] = "[#$refered_issue->nid-1@]"; + $this->createIssue($project, $edit); + $this->assertText("#$refered_issue->nid-1: $refered_issue->title"); + $this->assertText("Assigned to: {$this->maintain_user->name}"); + + // including project name + $edit['body'] = "[#{$refered_issue->nid}P]"; + $this->createIssue($project, $edit); + $this->assertText("#$refered_issue->nid [{$project->project['uri']}]: $refered_issue->title"); + + // with comment including project name + $edit['body'] = "[#$refered_issue->nid-1P]"; + $this->createIssue($project, $edit); + $this->assertText("#$refered_issue->nid-1 [{$project->project['uri']}]: $refered_issue->title"); + + // including both assigned and project name, way 1 + $edit['body'] = "[#{$refered_issue->nid}@P]"; + $this->createIssue($project, $edit); + $this->assertText("#$refered_issue->nid [{$project->project['uri']}]: $refered_issue->title"); + $this->assertText("Assigned to: {$this->maintain_user->name}"); + + // including both assigned and project name, way 2 + $edit['body'] = "[#{$refered_issue->nid}P@]"; + $this->createIssue($project, $edit); + $this->assertText("#$refered_issue->nid [{$project->project['uri']}]: $refered_issue->title"); + $this->assertText("Assigned to: {$this->maintain_user->name}"); + + // with comment including both assigned and project name way 1 + $edit['body'] = "[#{$refered_issue->nid}-1@P]"; + $this->createIssue($project, $edit); + $this->assertText("#$refered_issue->nid-1 [{$project->project['uri']}]: $refered_issue->title"); + $this->assertText("Assigned to: {$this->maintain_user->name}"); + + // with comment including both assigned and project name way 2 + $edit['body'] = "[#{$refered_issue->nid}-1P@]"; + $this->createIssue($project, $edit); + $this->assertText("#$refered_issue->nid-1 [{$project->project['uri']}]: $refered_issue->title"); + $this->assertText("Assigned to: {$this->maintain_user->name}"); + } +} -- 1.7.1