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
|
|
|
|
2007-08-24 03:00:21 +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') || '';
|
2006-07-18 21:38:13 +04:00
|
|
|
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;
|
|
|
|
}
|
2006-07-18 21:38:13 +04:00
|
|
|
my %seen;
|
|
|
|
my @plans;
|
|
|
|
my @plan_ids;
|
|
|
|
my @categories;
|
2007-08-24 03:00:21 +04:00
|
|
|
|
|
|
|
# Weed out duplicates.
|
2006-07-18 21:38:13 +04:00
|
|
|
foreach my $entry (@plan_id){
|
|
|
|
foreach my $id (split(/[\s,]+/, $entry)){
|
|
|
|
detaint_natural($id);
|
|
|
|
validate_test_id($id, 'plan');
|
|
|
|
$seen{$id} = 1;
|
|
|
|
}
|
|
|
|
}
|
2007-08-24 03:00:21 +04:00
|
|
|
|
|
|
|
# Users need write permission on the plan in order to create a test case against
|
|
|
|
# that plan. See tr_plan_access.cgi
|
2006-07-18 21:38:13 +04:00
|
|
|
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;
|
2006-07-18 21:38:13 +04:00
|
|
|
push @plan_ids, $id;
|
|
|
|
push @plans, $plan;
|
2006-12-01 21:06:58 +03:00
|
|
|
push @categories, @{$plan->product->categories};
|
2006-07-18 21:38:13 +04:00
|
|
|
}
|
2006-06-13 19:09:54 +04:00
|
|
|
|
2007-08-24 03:00:21 +04:00
|
|
|
# We need at least one category in the list.
|
2006-07-18 21:38:13 +04:00
|
|
|
ThrowUserError('testopia-create-category', {'plan' => $plans[0] }) if scalar @categories < 1;
|
2006-06-13 19:09:54 +04:00
|
|
|
|
2007-08-24 03:00:21 +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
|
|
|
|
2007-08-24 03:00:21 +04:00
|
|
|
});
|
2006-07-18 21:38:13 +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";
|
2006-07-18 21:38:13 +04:00
|
|
|
$vars->{'case'} = $case;
|
2007-08-24 03:00:21 +04:00
|
|
|
$vars->{'tr_message'} = "Case ". $case->id ." Created.
|
2006-07-18 21:38:13 +04:00
|
|
|
<a href=\"tr_new_case.cgi?plan_id=" . join(",", @plan_ids) . "\">Add another</a>";
|
2006-10-31 01:29:32 +03:00
|
|
|
$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-08-24 03:00:21 +04:00
|
|
|
|
2007-01-05 01:45:11 +03:00
|
|
|
my $summary;
|
|
|
|
my $text;
|
|
|
|
if( $cgi->param('bug')){
|
2007-08-24 03:00:21 +04:00
|
|
|
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;
|
|
|
|
|
2007-05-12 02:35:11 +04:00
|
|
|
$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;
|
|
|
|
|
2007-02-20 21:27:19 +03:00
|
|
|
$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;
|
|
|
|
|
2007-02-20 21:27:19 +03:00
|
|
|
$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};
|
2007-08-24 03:00:21 +04:00
|
|
|
|
|
|
|
$vars->{'bugs'} = $bug->bug_id;
|
2007-01-05 01:45:11 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-05-12 02:35:11 +04:00
|
|
|
$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(
|
2007-08-24 03:00:21 +04:00
|
|
|
{'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;
|
2007-08-24 03:00:21 +04:00
|
|
|
|
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());
|
|
|
|
}
|