2005-07-30 00:21:01 +04:00
|
|
|
#!/usr/bin/perl -w
|
2006-02-07 21:20:53 +03:00
|
|
|
# -*- Mode: cperl; indent-tabs-mode: nil -*-
|
2005-07-30 00:21:01 +04:00
|
|
|
#
|
|
|
|
# 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 Litmus.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Zach Lipton <zach@zachlipton.com>
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use Litmus;
|
|
|
|
use Litmus::Error;
|
|
|
|
use Litmus::DB::Product;
|
|
|
|
use Litmus::UserAgentDetect;
|
|
|
|
use Litmus::SysConfig;
|
|
|
|
use Litmus::Auth;
|
2006-02-07 21:20:53 +03:00
|
|
|
use Litmus::Utils;
|
|
|
|
use Litmus::DB::Resultbug;
|
2005-07-30 00:21:01 +04:00
|
|
|
|
|
|
|
use CGI;
|
2006-02-07 21:20:53 +03:00
|
|
|
use Date::Manip;
|
2005-07-30 00:21:01 +04:00
|
|
|
use Time::Piece::MySQL;
|
|
|
|
|
2006-02-07 21:20:53 +03:00
|
|
|
|
2006-08-02 00:50:15 +04:00
|
|
|
|
|
|
|
Litmus->init();
|
2006-01-08 06:56:10 +03:00
|
|
|
my $c = Litmus->cgi();
|
2005-07-30 00:21:01 +04:00
|
|
|
|
|
|
|
print $c->header();
|
|
|
|
|
2005-10-11 22:44:16 +04:00
|
|
|
my $vars;
|
|
|
|
my $cookie = Litmus::Auth::getCookie();
|
|
|
|
$vars->{"defaultemail"} = $cookie;
|
2006-06-05 08:07:29 +04:00
|
|
|
$vars->{"show_admin"} = Litmus::Auth::istrusted($cookie);
|
|
|
|
|
|
|
|
$vars->{'default_match_limit'} = Litmus::DB::Testcase->getDefaultMatchLimit();
|
2006-06-28 23:03:45 +04:00
|
|
|
$vars->{'default_num_days'} = Litmus::DB::Testcase->getDefaultNumDays();
|
2006-06-05 08:07:29 +04:00
|
|
|
$vars->{'default_relevance_threshold'} = Litmus::DB::Testcase->getDefaultRelevanceThreshold();
|
2005-10-11 22:44:16 +04:00
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
if (! $c->param) {
|
|
|
|
Litmus->template()->process("show/search_for_testcases.tmpl", $vars) ||
|
2005-07-30 00:21:01 +04:00
|
|
|
internalError(Litmus->template()->error());
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
if ($c->param("id")) {
|
|
|
|
my $testcase_id = $c->param("id");
|
2006-02-07 21:20:53 +03:00
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
# Process changes to testcases:
|
|
|
|
# Only users with canedit can edit testcases.
|
|
|
|
my @changed;
|
|
|
|
my $update_status = 0;
|
|
|
|
if ($c->param("editingTestcases") &&
|
|
|
|
Litmus::Auth::canEdit(Litmus::Auth::getCookie())) {
|
2006-02-07 21:20:53 +03:00
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
# the editingTestcases param contains a comma-separated list of
|
|
|
|
# testcase IDs that the user has made changes to (well, has clicked
|
|
|
|
# the edit button for).
|
|
|
|
@changed = split(',' => $c->param("editingTestcases"));
|
|
|
|
foreach my $editid (@changed) {
|
|
|
|
my $edittest = Litmus::DB::Testcase->retrieve($editid);
|
|
|
|
if (! $edittest) {invalidInputError("Testcase $editid does not exist")}
|
|
|
|
|
|
|
|
$edittest->summary($c->param("summary_edit_$editid"));
|
|
|
|
my $product = Litmus::DB::Product->retrieve($c->param("product_$editid"));
|
|
|
|
requireField("product", $product);
|
|
|
|
$edittest->product($product);
|
|
|
|
|
|
|
|
$edittest->steps($c->param("steps_edit_$editid"));
|
|
|
|
$edittest->expected_results($c->param("results_edit_$editid"));
|
|
|
|
|
|
|
|
if ($c->param("enabled_$editid")) {
|
|
|
|
$edittest->enabled(1);
|
|
|
|
if ($c->param("communityenabled_$editid")) {
|
|
|
|
$edittest->communityenabled(1);
|
|
|
|
} else {
|
|
|
|
$edittest->communityenabled(0);
|
|
|
|
}
|
2006-04-06 23:37:39 +04:00
|
|
|
} else {
|
2006-06-05 08:07:29 +04:00
|
|
|
$edittest->enabled(0);
|
2006-04-06 23:37:39 +04:00
|
|
|
$edittest->communityenabled(0);
|
|
|
|
}
|
2006-06-05 08:07:29 +04:00
|
|
|
my $r_bug_id = $c->param("regression_bug_id_$editid");
|
|
|
|
if ($r_bug_id eq '' or $r_bug_id eq '0') {
|
|
|
|
undef $r_bug_id;
|
|
|
|
}
|
|
|
|
$edittest->regression_bug_id($r_bug_id);
|
2006-06-14 21:30:10 +04:00
|
|
|
# $edittest->sort_order($c->param("sort_order_$editid"));
|
2006-06-05 08:07:29 +04:00
|
|
|
$edittest->author_id(Litmus::Auth::getCurrentUser());
|
|
|
|
$edittest->last_updated(&Date::Manip::UnixDate("now","%q"));
|
|
|
|
$edittest->version($edittest->version()+1);
|
|
|
|
|
|
|
|
my $update_status = $edittest->update();
|
|
|
|
|
|
|
|
my $status = "";
|
|
|
|
my $message = "";
|
|
|
|
if ($update_status) {
|
|
|
|
$status = "success";
|
|
|
|
$message = "Testcase ID# $editid updated successfully.";
|
|
|
|
} else {
|
|
|
|
$status = "failure";
|
|
|
|
$message = "Unable to update testcase ID# $editid.";
|
|
|
|
}
|
|
|
|
$vars->{'onload'} = "toggleMessage('$status','$message');";
|
2006-02-07 21:20:53 +03:00
|
|
|
}
|
2006-06-05 08:07:29 +04:00
|
|
|
} elsif ($c->param("editingTestcases") &&
|
2006-06-28 23:03:45 +04:00
|
|
|
! Litmus::Auth::canEdit(Litmus::Auth::getCookie())) {
|
2006-06-05 08:07:29 +04:00
|
|
|
invalidInputError("You do not have permissions to edit testcases. ");
|
|
|
|
}
|
|
|
|
|
|
|
|
my $testcase = Litmus::DB::Testcase->retrieve($testcase_id);
|
|
|
|
|
|
|
|
if (! $testcase) {
|
|
|
|
invalidInputError("\"$testcase_id\" is not a valid testcase ID.");
|
2006-02-07 21:20:53 +03:00
|
|
|
}
|
2005-07-30 00:21:01 +04:00
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
my @testgroups = Litmus::DB::Testgroup->search_EnabledByTestcase($testcase_id);
|
|
|
|
my @subgroups = Litmus::DB::Subgroup->search_EnabledByTestcase($testcase_id);
|
2005-07-30 00:21:01 +04:00
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
my @result_statuses = Litmus::DB::ResultStatus->retrieve_all();
|
|
|
|
|
|
|
|
my $showallresults = $c->param("showallresults") || "";
|
|
|
|
|
|
|
|
my @where;
|
|
|
|
push @where, { field => 'testcase_id', value => $testcase_id };
|
|
|
|
my @order_by;
|
|
|
|
push @order_by, { field => 'created', direction => 'DESC' };
|
|
|
|
my $test_results = Litmus::DB::Testresult->getTestResults(\@where,\@order_by);
|
|
|
|
|
|
|
|
$vars->{'testcase'} = $testcase;
|
|
|
|
$vars->{'sysconfig'} = Litmus::SysConfig->getCookie($testcase->product());
|
|
|
|
$vars->{'testgroups'} = \@testgroups;
|
|
|
|
$vars->{'subgroups'} = \@subgroups;
|
|
|
|
$vars->{'result_statuses'} = \@result_statuses;
|
|
|
|
$vars->{'showallresults'} = $showallresults;
|
|
|
|
$vars->{'test_results'} = $test_results;
|
2006-06-23 03:21:38 +04:00
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
Litmus->template()->process("show/show.html.tmpl", $vars) ||
|
2006-06-23 03:21:38 +04:00
|
|
|
internalError(Litmus->template()->error());
|
2005-07-30 00:21:01 +04:00
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
exit;
|
|
|
|
}
|
2005-08-07 07:05:49 +04:00
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
if ($c->param("text_snippet")) {
|
|
|
|
my $text_snippet = $c->param("text_snippet");
|
|
|
|
my $match_limit = $c->param("match_limit");
|
|
|
|
my $relevance_threshold = $c->param("relevance_threshold");
|
|
|
|
my @testcases = Litmus::DB::Testcase->getFullTextMatches($text_snippet,
|
|
|
|
$match_limit,
|
|
|
|
$relevance_threshold);
|
|
|
|
$vars->{'testcases'} = \@testcases;
|
|
|
|
$vars->{'search_string_for_display'} = "Full-Text Search: \"$text_snippet\"";
|
2006-06-28 23:03:45 +04:00
|
|
|
$vars->{'fulltext'} = 1;
|
|
|
|
} elsif ($c->param("recently")) {
|
|
|
|
my $recently = $c->param("recently");
|
|
|
|
my $match_limit = $c->param("match_limit");
|
|
|
|
my $num_days = $c->param("num_days") || Litmus::DB::Testcase->getDefaultNumDays();
|
|
|
|
my @testcases;
|
|
|
|
my $search_string_for_display;
|
|
|
|
if ($recently eq 'added') {
|
|
|
|
@testcases = Litmus::DB::Testcase->getNewTestcases(
|
|
|
|
$num_days,
|
|
|
|
$match_limit
|
|
|
|
);
|
|
|
|
$search_string_for_display = "Testcases added in the last $num_days days";
|
|
|
|
} elsif ($recently eq 'changed') {
|
|
|
|
@testcases = Litmus::DB::Testcase->getRecentlyUpdated(
|
|
|
|
$num_days,
|
|
|
|
$match_limit
|
|
|
|
);
|
|
|
|
$search_string_for_display = "Testcases changed in the last $num_days days";
|
|
|
|
}
|
|
|
|
$vars->{'testcases'} = \@testcases;
|
|
|
|
$vars->{'search_string_for_display'} = $search_string_for_display;
|
2006-07-29 02:26:43 +04:00
|
|
|
} elsif ($c->param('type') eq 'by_category') {
|
|
|
|
my $product_id = $c->param("product");
|
|
|
|
my $testgroup_id = $c->param("testgroup");
|
|
|
|
my $subgroup_id = $c->param("subgroup");
|
|
|
|
my ($product, $testgroup, $subgroup);
|
|
|
|
my @testcases;
|
|
|
|
|
|
|
|
if ($subgroup_id && $subgroup_id ne '-Subgroup-' && $subgroup_id ne '---') {
|
|
|
|
@testcases = Litmus::DB::Testcase->search_BySubgroup($subgroup_id);
|
|
|
|
$subgroup = Litmus::DB::Subgroup->retrieve($subgroup_id);
|
|
|
|
$testgroup = Litmus::DB::Testgroup->retrieve($testgroup_id);
|
|
|
|
$product = Litmus::DB::Product->retrieve($product_id);
|
|
|
|
} elsif ($testgroup_id && $testgroup_id ne '-Testgroup-' && $testgroup_id ne '---') {
|
|
|
|
@testcases = Litmus::DB::Testcase->search_ByTestgroup($testgroup_id);
|
|
|
|
$testgroup = Litmus::DB::Testgroup->retrieve($testgroup_id);
|
|
|
|
$product = Litmus::DB::Product->retrieve($product_id);
|
|
|
|
} elsif ($product_id && $product_id ne '-Product-' && $product_id ne '---') {
|
|
|
|
@testcases = Litmus::DB::Testcase->search(product => $product_id);
|
|
|
|
$product = Litmus::DB::Product->retrieve($product_id);
|
|
|
|
}
|
|
|
|
$vars->{'testcases'} = \@testcases;
|
|
|
|
$vars->{'search_string_for_display'} =
|
|
|
|
($product ? "product: ".$product->name() : '').
|
|
|
|
($testgroup ? " | testgroup: ".$testgroup->name() : '').
|
|
|
|
($subgroup ? " | subgroup: ".$subgroup->name() : '');
|
|
|
|
}
|
2005-10-11 22:44:16 +04:00
|
|
|
|
2006-07-29 02:26:43 +04:00
|
|
|
if ($c->param('print')) {
|
|
|
|
Litmus->template()->process("show/print_testcases.tmpl", $vars) ||
|
|
|
|
internalError(Litmus->template()->error());
|
|
|
|
} else {
|
|
|
|
Litmus->template()->process("show/search_for_testcases.tmpl", $vars) ||
|
|
|
|
internalError(Litmus->template()->error());
|
|
|
|
}
|