pjs/webtools/testopia/tr_new_case.cgi

191 строка
6.6 KiB
Plaintext
Исходник Обычный вид История

2006-06-13 19:09:54 +04:00
#!/usr/bin/perl -wT
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Test Runner System.
#
# The Initial Developer of the Original Code is Maciej Maczynski.
# Portions created by Maciej Maczynski are Copyright (C) 2001
# Maciej Maczynski. All Rights Reserved.
#
# Contributor(s): Greg Hendricks <ghendricks@novell.com>
use strict;
use lib ".";
use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Util;
2007-02-26 22:06:35 +03:00
use Bugzilla::User;
2006-06-13 19:09:54 +04:00
use Bugzilla::Testopia::Util;
use Bugzilla::Testopia::TestCase;
2006-10-06 01:11:04 +04:00
use JSON;
2006-06-13 19:09:54 +04:00
###############################################################################
# tr_new_case.cgi
# Presents a webform to the user for the creation of a new test case.
#
# INTERFACE:
# plan_id: list - list of plans that the newly created test case will
# be attached to. If no plan_id is found, the user will first
# be presented with a form to select a plan.
#
# action: undef - Present form for new case creation
# "Add" - Form has been submitted with case data. Create the test
# case.
#
################################################################################
2007-05-24 00:42:27 +04:00
my $vars = {};
2006-06-13 19:09:54 +04:00
Bugzilla->login(LOGIN_REQUIRED);
my $cgi = Bugzilla->cgi;
2007-02-26 22:06:35 +03:00
my $template = Bugzilla->template;
print $cgi->header;
2006-06-13 19:09:54 +04:00
my $action = $cgi->param('action') || '';
my @plan_id = $cgi->param('plan_id');
2006-06-13 19:09:54 +04:00
2006-10-06 01:11:04 +04:00
unless ($plan_id[0]){
2007-01-05 01:45:11 +03:00
$vars->{'product'} = Bugzilla::Testopia::Product->new({'name' => $cgi->param('product')}) if ($cgi->param('product'));
$vars->{'bug_id'} = $cgi->param('bug');
2006-06-13 19:09:54 +04:00
$vars->{'form_action'} = 'tr_new_case.cgi';
$template->process("testopia/plan/choose.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
exit;
}
my %seen;
my @plans;
my @plan_ids;
my @categories;
# Weed out duplicates.
foreach my $entry (@plan_id){
foreach my $id (split(/[\s,]+/, $entry)){
detaint_natural($id);
validate_test_id($id, 'plan');
$seen{$id} = 1;
}
}
# Users need write permission on the plan in order to create a test case against
# that plan. See tr_plan_access.cgi
foreach my $id (keys %seen){
my $plan = Bugzilla::Testopia::TestPlan->new($id);
2007-03-14 01:26:53 +03:00
ThrowUserError("testopia-create-denied", {'object' => 'Test Case', 'plan' => $plan}) unless $plan->canedit;
push @plan_ids, $id;
push @plans, $plan;
2006-12-01 21:06:58 +03:00
push @categories, @{$plan->product->categories};
}
2006-06-13 19:09:54 +04:00
# We need at least one category in the list.
ThrowUserError('testopia-create-category', {'plan' => $plans[0] }) if scalar @categories < 1;
2006-06-13 19:09:54 +04:00
if ($action eq 'Add'){
my @comps = $cgi->param("components");
my $case = Bugzilla::Testopia::TestCase->create({
'alias' => $cgi->param('alias'),
'case_status_id' => $cgi->param('status'),
'category_id' => $cgi->param('category'),
'priority_id' => $cgi->param('priority'),
'isautomated' => $cgi->param("isautomated"),
'estimated_time' => $cgi->param("estimated_time"),
'script' => $cgi->param("script"),
'arguments' => $cgi->param("arguments"),
'summary' => $cgi->param("summary"),
'requirement' => $cgi->param("requirement"),
'default_tester_id' => $cgi->param("tester"),
'author_id' => Bugzilla->user->id,
'action' => $cgi->param("tcaction"),
'effect' => $cgi->param("tceffect"),
'setup' => $cgi->param("tcsetup"),
'breakdown' => $cgi->param("tcbreakdown"),
'dependson' => $cgi->param("tcdependson"),
'blocks' => $cgi->param("tcblocks"),
'tags' => $cgi->param('addtags'),
'runs' => $cgi->param('addruns'),
'bugs' => $cgi->param('bugs'),
'plans' => \@plans,
'components' => \@comps,
2006-06-13 19:09:54 +04:00
});
2006-10-06 01:11:04 +04:00
$vars->{'action'} = "Commit";
2006-06-13 19:09:54 +04:00
$vars->{'form_action'} = "tr_show_case.cgi";
$vars->{'case'} = $case;
$vars->{'tr_message'} = "Case ". $case->id ." Created.
<a href=\"tr_new_case.cgi?plan_id=" . join(",", @plan_ids) . "\">Add another</a>";
$vars->{'backlink'} = $case;
2006-06-13 19:09:54 +04:00
$template->process("testopia/case/show.html.tmpl", $vars) ||
ThrowTemplateError($template->error());
}
2006-10-06 01:11:04 +04:00
2006-06-13 19:09:54 +04:00
####################
### Display Form ###
####################
else {
2007-01-05 01:45:11 +03:00
my $summary;
my $text;
if( $cgi->param('bug')){
my $bug;
2007-01-05 01:45:11 +03:00
$bug = Bugzilla::Bug->new($cgi->param('bug'),Bugzilla->user->id);
my $bug_id = $bug->bug_id;
my $description = ${$bug->GetComments}[0];
my $short_desc = $bug->short_desc;
$summary = Bugzilla->params->{"bug-to-test-case-summary"};
my $action = Bugzilla->params->{"bug-to-test-case-action"};
my $effect = Bugzilla->params->{"bug-to-test-case-results"};
2007-01-05 01:45:11 +03:00
$summary =~ s/%id%/$bug_id/g;
$summary =~ s/%summary%/$short_desc/g;
$action =~ s/%id%/<a href="show_bug.cgi?id=$bug_id">$bug_id<\/a>/g;
2007-01-05 01:45:11 +03:00
$action =~ s/%description%/$description/g;
$effect =~ s/%id%/<a href="show_bug.cgi?id=$bug_id">$bug_id<\/a>/g;
2007-01-05 01:45:11 +03:00
$text = {'action' => $action, 'effect' => $effect};
$vars->{'bugs'} = $bug->bug_id;
2007-01-05 01:45:11 +03:00
}
else {
$text = {'action' => Bugzilla->params->{"new-case-action-template"},
'effect' => Bugzilla->params->{"new-case-results-template"}};
2007-01-05 01:45:11 +03:00
}
2006-10-06 01:11:04 +04:00
my $case = Bugzilla::Testopia::TestCase->new(
{'plans' => \@plans,
'category' => {name => '--default--'},
2007-01-05 01:45:11 +03:00
'summary' => $summary,
'text' => $text,
2006-06-13 19:09:54 +04:00
});
2006-10-06 01:11:04 +04:00
my @comps;
foreach my $comp (@{$case->get_selectable_components(1)}){
push @comps, $comp->default_qa_contact->login;
}
2007-01-05 01:45:11 +03:00
2006-10-06 01:11:04 +04:00
$vars->{'case'} = $case;
2006-10-06 01:11:04 +04:00
$vars->{'components'} = objToJson(\@comps);
$vars->{'action'} = "Add";
$vars->{'form_action'} = "tr_new_case.cgi";
2006-06-13 19:09:54 +04:00
$template->process("testopia/case/add.html.tmpl", $vars) ||
ThrowTemplateError($template->error());
}