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;
|
2006-07-29 02:32:36 +04:00
|
|
|
use Bugzilla::Bug;
|
2006-06-13 19:09:54 +04:00
|
|
|
use Bugzilla::Util;
|
|
|
|
use Bugzilla::Error;
|
|
|
|
use Bugzilla::Constants;
|
|
|
|
use Bugzilla::Testopia::Search;
|
|
|
|
use Bugzilla::Testopia::Util;
|
|
|
|
use Bugzilla::Testopia::TestCaseRun;
|
|
|
|
use Bugzilla::Testopia::Table;
|
2006-12-09 02:12:16 +03:00
|
|
|
use Bugzilla::Testopia::Constants;
|
2006-06-13 19:09:54 +04:00
|
|
|
|
|
|
|
use vars qw($vars $template);
|
2006-10-19 00:59:28 +04:00
|
|
|
require 'globals.pl';
|
2006-07-29 02:32:36 +04:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
my $template = Bugzilla->template;
|
2006-10-21 03:27:56 +04:00
|
|
|
my $query_limit = 15000;
|
2006-06-13 19:09:54 +04:00
|
|
|
|
|
|
|
push @{$::vars->{'style_urls'}}, 'testopia/css/default.css';
|
|
|
|
|
|
|
|
$cgi->send_cookie(-name => "TEST_LAST_ORDER",
|
|
|
|
-value => $cgi->param('order'),
|
|
|
|
-expires => "Fri, 01-Jan-2038 00:00:00 GMT");
|
|
|
|
Bugzilla->login();
|
2007-02-09 20:31:45 +03:00
|
|
|
|
|
|
|
$vars->{'fullwidth'} = 1;
|
|
|
|
|
2006-10-21 03:27:56 +04:00
|
|
|
my $serverpush = support_server_push($cgi);
|
|
|
|
if ($serverpush) {
|
|
|
|
print $cgi->multipart_init;
|
|
|
|
print $cgi->multipart_start;
|
|
|
|
|
|
|
|
$template->process("list/server-push.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print $cgi->header;
|
|
|
|
}
|
|
|
|
# prevent DOS attacks from multiple refreshes of large data
|
|
|
|
$::SIG{TERM} = 'DEFAULT';
|
|
|
|
$::SIG{PIPE} = 'DEFAULT';
|
2006-10-19 00:59:28 +04:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
my $action = $cgi->param('action') || '';
|
|
|
|
|
|
|
|
if ($action eq 'Commit'){
|
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
|
|
|
# Get the list of checked items. This way we don't have to cycle through
|
|
|
|
# every test case, only the ones that are checked.
|
|
|
|
my $reg = qr/r_([\d]+)/;
|
2006-10-21 03:27:56 +04:00
|
|
|
my $params = join(" ", $cgi->param());
|
|
|
|
my @params = $cgi->param();
|
2006-06-13 19:09:54 +04:00
|
|
|
my @buglist;
|
2006-12-01 22:37:26 +03:00
|
|
|
unless ($params =~ $reg){
|
|
|
|
print $cgi->multipart_end if $serverpush;
|
|
|
|
ThrowUserError('testopia-none-selected', {'object' => 'case-run'});
|
|
|
|
}
|
2006-06-13 19:09:54 +04:00
|
|
|
foreach my $bug (split(/[\s,]+/, $cgi->param('bugs'))){
|
|
|
|
ValidateBugID($bug);
|
|
|
|
push @buglist, $bug;
|
|
|
|
}
|
|
|
|
|
2006-10-21 03:27:56 +04:00
|
|
|
my $progress_interval = 250;
|
|
|
|
my $i = 0;
|
|
|
|
my $total = scalar @params;
|
|
|
|
|
|
|
|
foreach my $p ($cgi->param()){
|
|
|
|
my $caserun = Bugzilla::Testopia::TestCaseRun->new($1) if $p =~ $reg;
|
|
|
|
next unless $caserun;
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
if ($i % $progress_interval == 0 && $serverpush){
|
|
|
|
print $cgi->multipart_end;
|
|
|
|
print $cgi->multipart_start;
|
|
|
|
$vars->{'complete'} = $i;
|
|
|
|
$vars->{'total'} = $total;
|
|
|
|
$template->process("testopia/progress.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
2006-12-09 02:12:16 +03:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
my $build = $cgi->param('caserun_build') == -1 ? $caserun->build->id : $cgi->param('caserun_build');
|
2006-10-06 01:11:04 +04:00
|
|
|
my $notes = $cgi->param('notes');
|
2007-01-18 00:58:12 +03:00
|
|
|
my $env = $cgi->param('caserun_env') eq '' ? $caserun->environment->id : $cgi->param('caserun_env');
|
2006-06-13 19:09:54 +04:00
|
|
|
|
2006-10-06 01:11:04 +04:00
|
|
|
validate_test_id($build, 'build');
|
|
|
|
validate_test_id($env, 'environment');
|
|
|
|
|
|
|
|
detaint_natural($env);
|
2006-06-13 19:09:54 +04:00
|
|
|
detaint_natural($build);
|
2006-12-15 22:49:55 +03:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
trick_taint($notes);
|
2006-12-09 02:12:16 +03:00
|
|
|
|
|
|
|
unless ($caserun->canedit){
|
|
|
|
print $cgi->multipart_end if $serverpush;
|
|
|
|
ThrowUserError("testopia-read-only", {'object' => 'Case Run', 'id' => $caserun->id});
|
|
|
|
}
|
2006-12-14 20:25:17 +03:00
|
|
|
|
|
|
|
# Switch to the record representing this build and environment combo.
|
|
|
|
# If there is not one, it will create it and switch to that.
|
|
|
|
$caserun = $caserun->switch($build,$env);
|
|
|
|
|
2006-12-15 22:49:55 +03:00
|
|
|
my $status = $cgi->param('status') == -1 ? $caserun->status_id : $cgi->param('status');
|
|
|
|
my $assignee = $cgi->param('assignee') eq '--Do Not Change--' ? $caserun->assignee->id : DBNameToIdAndCheck(trim($cgi->param('assignee')));
|
|
|
|
|
|
|
|
detaint_natural($status);
|
|
|
|
|
2006-12-14 20:25:17 +03:00
|
|
|
$caserun->set_status($status) if ($caserun->status_id != $status);
|
|
|
|
$caserun->set_assignee($assignee) if ($caserun->assignee->id != $assignee);
|
|
|
|
$caserun->append_note($notes);
|
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
foreach my $bug (@buglist){
|
|
|
|
$caserun->attach_bug($bug);
|
|
|
|
}
|
2006-10-06 01:11:04 +04:00
|
|
|
|
2006-12-14 20:25:17 +03:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
}
|
2006-10-06 01:11:04 +04:00
|
|
|
$vars->{'title'} = "Update Successful";
|
2006-10-21 03:27:56 +04:00
|
|
|
$vars->{'tr_message'} = "$i Test Case-Runs Updated";
|
2006-10-27 21:21:26 +04:00
|
|
|
if ($serverpush && !$cgi->param('debug')) {
|
2006-10-21 03:27:56 +04:00
|
|
|
print $cgi->multipart_end;
|
|
|
|
print $cgi->multipart_start;
|
|
|
|
}
|
2006-06-13 19:09:54 +04:00
|
|
|
if ($cgi->param('run_id')){
|
|
|
|
my $run_id = $cgi->param('run_id');
|
|
|
|
my $run = Bugzilla::Testopia::TestRun->new($run_id);
|
2007-02-09 20:31:45 +03:00
|
|
|
|
|
|
|
# See if there is a saved filter
|
|
|
|
if ($cgi->cookie('TESTOPIA-FILTER-RUN-' . $run_id) && $action ne 'Filter' && $action ne 'clear_filter'){
|
|
|
|
$cgi = Bugzilla::CGI->new($cgi->cookie('TESTOPIA-FILTER-RUN-' . $run_id));
|
|
|
|
$vars->{'filtered'} = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$cgi->delete_all;
|
|
|
|
}
|
2006-06-13 19:09:54 +04:00
|
|
|
$cgi->param('run_id', $run_id);
|
|
|
|
$cgi->param('current_tab', 'case_run');
|
|
|
|
my $search = Bugzilla::Testopia::Search->new($cgi);
|
|
|
|
my $table = Bugzilla::Testopia::Table->new('case_run', 'tr_show_run.cgi', $cgi, undef, $search->query);
|
|
|
|
|
|
|
|
$vars->{'run'} = $run;
|
|
|
|
$vars->{'table'} = $table;
|
|
|
|
$vars->{'action'} = 'Commit';
|
2006-10-31 21:49:02 +03:00
|
|
|
$vars->{'backlink'} = $run;
|
2006-10-06 01:11:04 +04:00
|
|
|
$vars->{'form_action'} = "tr_show_run.cgi";
|
2007-02-09 20:31:45 +03:00
|
|
|
$vars->{'caserun'} = Bugzilla::Testopia::TestCaseRun->new({});
|
|
|
|
$vars->{'case'} = Bugzilla::Testopia::TestCase->new({});
|
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
$template->process("testopia/run/show.html.tmpl", $vars) ||
|
|
|
|
ThrowTemplateError($template->error());
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my $case = Bugzilla::Testopia::TestCase->new({ 'case_id' => 0 });
|
|
|
|
$vars->{'case'} = $case;
|
|
|
|
$vars->{'current_tab'} = 'cases';
|
|
|
|
$template->process("testopia/search/advanced.html.tmpl", $vars) ||
|
|
|
|
ThrowTemplateError($template->error());
|
|
|
|
}
|
2006-10-21 03:27:56 +04:00
|
|
|
print $cgi->multipart_final if $serverpush;
|
2006-06-13 19:09:54 +04:00
|
|
|
exit;
|
|
|
|
}
|
2006-10-19 00:59:28 +04:00
|
|
|
elsif ($action eq 'Delete Selected'){
|
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
|
|
|
my $reg = qr/r_([\d]+)/;
|
|
|
|
my @caseruns;
|
|
|
|
foreach my $p ($cgi->param()){
|
|
|
|
my $caserun = Bugzilla::Testopia::TestCaseRun->new($1) if $p =~ $reg;
|
2006-12-01 22:37:26 +03:00
|
|
|
if (($caserun && !$caserun->candelete)){
|
|
|
|
print $cgi->multipart_end if $serverpush;
|
|
|
|
ThrowUserError("testopia-read-only", {'object' => 'case run'});
|
|
|
|
}
|
2006-10-19 00:59:28 +04:00
|
|
|
push @caseruns, $caserun if $caserun;
|
|
|
|
}
|
2006-10-21 03:27:56 +04:00
|
|
|
if ($serverpush) {
|
|
|
|
print $cgi->multipart_end;
|
|
|
|
print $cgi->multipart_start;
|
|
|
|
}
|
2006-12-01 22:37:26 +03:00
|
|
|
if ((scalar @caseruns < 1)){
|
|
|
|
print $cgi->multipart_end if $serverpush;
|
|
|
|
ThrowUserError('testopia-none-selected', {'object' => 'case-run'});
|
|
|
|
}
|
2006-10-19 00:59:28 +04:00
|
|
|
$vars->{'caseruns'} = \@caseruns;
|
|
|
|
$vars->{'caseruncount'} = scalar @caseruns;
|
|
|
|
$vars->{'title'} = "Remove Test Cases from Run";
|
|
|
|
$vars->{'form_action'} = 'tr_list_caseruns.cgi';
|
|
|
|
$vars->{'run_id'} = $cgi->param('run_id');
|
|
|
|
$template->process("testopia/caserun/delete.html.tmpl", $vars) ||
|
|
|
|
ThrowTemplateError($template->error());
|
2006-10-21 03:27:56 +04:00
|
|
|
print $cgi->multipart_final if $serverpush;
|
2006-10-19 00:59:28 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
elsif ($action eq 'do_delete'){
|
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
|
|
|
my @caseruns;
|
|
|
|
foreach my $id ($cgi->param('caserun_id')){
|
|
|
|
my $caserun = Bugzilla::Testopia::TestCaseRun->new($id);
|
|
|
|
push @caseruns, $caserun;
|
2006-12-01 22:37:26 +03:00
|
|
|
if (!$caserun->candelete){
|
|
|
|
print $cgi->multipart_end if $serverpush;
|
|
|
|
ThrowUserError("testopia-read-only", {'object' => 'case run'});
|
|
|
|
}
|
2006-10-19 00:59:28 +04:00
|
|
|
}
|
2006-10-21 03:27:56 +04:00
|
|
|
my $progress_interval = 250;
|
|
|
|
my $i = 0;
|
|
|
|
my $total = scalar @caseruns;
|
2006-10-19 00:59:28 +04:00
|
|
|
foreach my $c (@caseruns){
|
2006-10-21 03:27:56 +04:00
|
|
|
$i++;
|
|
|
|
if ($i % $progress_interval == 0 && $serverpush){
|
|
|
|
print $cgi->multipart_end;
|
|
|
|
print $cgi->multipart_start;
|
|
|
|
$vars->{'complete'} = $i;
|
|
|
|
$vars->{'total'} = $total;
|
|
|
|
$template->process("testopia/progress.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
2006-10-19 00:59:28 +04:00
|
|
|
$c->obliterate;
|
|
|
|
}
|
2006-10-21 03:27:56 +04:00
|
|
|
if ($serverpush) {
|
|
|
|
print $cgi->multipart_end;
|
|
|
|
print $cgi->multipart_start;
|
|
|
|
}
|
2006-10-19 00:59:28 +04:00
|
|
|
$vars->{'deleted'} = 1;
|
|
|
|
$vars->{'run_id'} = $cgi->param('run_id');
|
|
|
|
$template->process("testopia/caserun/delete.html.tmpl", $vars) ||
|
|
|
|
ThrowTemplateError($template->error());
|
2006-10-21 03:27:56 +04:00
|
|
|
print $cgi->multipart_final if $serverpush;
|
2006-10-19 00:59:28 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2007-01-09 03:41:23 +03:00
|
|
|
$vars->{'qname'} = $cgi->param('qname') if $cgi->param('qname');
|
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
# Take the search from the URL params and convert it to SQL
|
|
|
|
$cgi->param('current_tab', 'case_run');
|
|
|
|
my $search = Bugzilla::Testopia::Search->new($cgi);
|
|
|
|
my $table = Bugzilla::Testopia::Table->new('case_run', 'tr_list_caseruns.cgi', $cgi, undef, $search->query);
|
2006-12-01 22:37:26 +03:00
|
|
|
if ($table->view_count > $query_limit){
|
|
|
|
print $cgi->multipart_end if $serverpush;
|
|
|
|
ThrowUserError('testopia-query-too-large', {'limit' => $query_limit});
|
|
|
|
}
|
2006-06-13 19:09:54 +04:00
|
|
|
|
|
|
|
if ($table->list_count > 0){
|
|
|
|
my $prod_id = $table->list->[0]->run->plan->product_id;
|
|
|
|
foreach my $caserun (@{$table->list}){
|
|
|
|
if ($caserun->run->plan->product_id != $prod_id){
|
|
|
|
$vars->{'multiprod'} = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$vars->{'multiprod'}){
|
|
|
|
my $p = $table->list->[0]->run->plan;
|
2006-12-01 21:06:58 +03:00
|
|
|
my $build_list = $p->product->builds;
|
2006-06-13 19:09:54 +04:00
|
|
|
unshift @{$build_list}, {'id' => -1, 'name' => "--Do Not Change--"};
|
|
|
|
$vars->{'build_list'} = $build_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($cgi->param('run_id')){
|
2007-02-15 21:57:24 +03:00
|
|
|
my @runs = split(",", $cgi->param('run_id'));
|
|
|
|
if (scalar @runs == 1){
|
|
|
|
$vars->{'run'} = Bugzilla::Testopia::TestRun->new($cgi->param('run_id'));
|
|
|
|
$vars->{'filtered'} = 1 if $cgi->cookie('TESTOPIA-FILTER-RUN-' . $vars->{'run'}->id) && $cgi->param('action') ne 'clear_filter';
|
|
|
|
}
|
2006-06-13 19:09:54 +04:00
|
|
|
}
|
2006-10-06 01:11:04 +04:00
|
|
|
my $case = Bugzilla::Testopia::TestCase->new({'case_id' => 0});
|
2006-10-31 02:16:16 +03:00
|
|
|
$vars->{'expand_report'} = $cgi->param('expand_report') || 0;
|
|
|
|
$vars->{'expand_filter'} = $cgi->param('expand_filter') || 0;
|
2007-02-14 03:40:36 +03:00
|
|
|
$vars->{'dotweak'} = UserInGroup('Testers');
|
2006-06-13 19:09:54 +04:00
|
|
|
$vars->{'table'} = $table;
|
|
|
|
$vars->{'action'} = 'tr_list_caserun.cgi';
|
2007-02-09 20:31:45 +03:00
|
|
|
$vars->{'caserun'} = Bugzilla::Testopia::TestCaseRun->new({});
|
|
|
|
$vars->{'case'} = Bugzilla::Testopia::TestCase->new({});
|
2006-10-27 21:21:26 +04:00
|
|
|
if ($serverpush && !$cgi->param('debug')) {
|
2006-10-21 03:27:56 +04:00
|
|
|
print $cgi->multipart_end;
|
|
|
|
print $cgi->multipart_start;
|
|
|
|
}
|
2006-06-13 19:09:54 +04:00
|
|
|
$template->process("testopia/caserun/list.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2006-10-21 03:27:56 +04:00
|
|
|
print $cgi->multipart_final if $serverpush;
|