gecko-dev/webtools/litmus/manage_testcases.cgi
ccooper%deadsquid.com a0b5af87db b=355278
- associate branches directly with testcases, subgroups, and testgroups
- existing Litmus installs will need to run the migration/update_branch_relationships.pl script to update their installs
- fix fidelity of testcase, subgroup, and testgroup listings so that entities th
at don't belong to groupings are still displayed

Misc.
- standardize how we call 'onchange' js functions to avoid capitalization errors that were plaguing us before
- enable differential sorting in FormWidget listings
2006-12-06 18:18:31 +00:00

217 lines
7.0 KiB
Perl
Executable File

#!/usr/bin/perl -w
# -*- mode: cperl; c-basic-offset: 8; indent-tabs-mode: nil; -*-
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# 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
# the Mozilla Corporation.
# Portions created by the Initial Developer are Copyright (C) 2006
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Chris Cooper <ccooper@deadsquid.com>
# Zach Lipton <zach@zachlipton.com>
#
# ***** END LICENSE BLOCK *****
use strict;
use Litmus;
use Litmus::Auth;
use Litmus::Cache;
use Litmus::Error;
use Litmus::FormWidget;
use Litmus::Utils;
use CGI;
use Date::Manip;
Litmus->init();
my $c = Litmus->cgi();
my $vars;
my $testcase_id;
my $edit;
my $message;
my $status;
my $rv;
if ($c->param("searchTestcaseList")) {
print $c->header('text/plain');
my $product_id = $c->param("product");
my $testgroup_id = $c->param("testgroup");
my $subgroup_id = $c->param("subgroup");
my $tests;
if ($subgroup_id) {
$tests = Litmus::DB::Testcase->search_BySubgroup($subgroup_id);
} elsif ($testgroup_id) {
$tests = Litmus::DB::Testcase->search_ByTestgroup($testgroup_id);
} elsif ($product_id) {
$tests = Litmus::DB::Testcase->search(product => $product_id);
}
while (my $t = $tests->next) {
print $t->testcase_id()."\n";
}
exit;
}
# anyone can use this script for its searching capabilities, but if we
# get here, then you need to be an admin:
Litmus::Auth::requireAdmin('manage_testcases.cgi');
if ($c->param("testcase_id")) {
$testcase_id = $c->param("testcase_id");
if ($c->param("edit")) {
$edit = $testcase_id;
}
}
my $rebuild_cache = 0;
my $defaults;
if ($c->param("delete_testcase_button")) {
my $testcase = Litmus::DB::Testcase->retrieve($testcase_id);
if ($testcase) {
$rv = $testcase->delete_with_refs();
if ($rv) {
$status = "success";
$message = "Testcase ID# $testcase_id deleted successfully.";
$rebuild_cache=1;
} else {
$status = "failure";
$message = "Failed to delete Testcase ID# $testcase_id.";
}
} else {
$status = "failure";
$message = "Testcase ID# $testcase_id does not exist. (Already deleted?)";
}
} elsif ($c->param("clone_testcase_button")) {
my $testcase = Litmus::DB::Testcase->retrieve($testcase_id);
my $new_testcase = $testcase->clone;
if ($new_testcase) {
$status = "success";
$message = "Testcase cloned successfully. New testcase ID# is " . $new_testcase->testcase_id;
$defaults->{'testcase_id'} = $new_testcase->testcase_id;
$rebuild_cache=1;
} else {
$status = "failure";
$message = "Failed to clone Testcase ID# $testcase_id.";
}
} elsif ($c->param("editform_mode")) {
requireField('summary', $c->param('editform_summary'));
requireField('product', $c->param('editform_product'));
requireField('branch', $c->param('editform_branch'));
requireField('author', $c->param('editform_author_id'));
my $enabled = $c->param('editform_enabled') ? 1 : 0;
my $community_enabled = $c->param('editform_communityenabled') ? 1 : 0;
my $now = &UnixDate("today","%q");
if ($c->param("editform_mode") eq "add") {
my %hash = (
summary => $c->param('editform_summary'),
steps => $c->param('editform_steps') ? $c->param('editform_steps') : '',
expected_results => $c->param('editform_results') ? $c->param('editform_results') : '',
product_id => $c->param('editform_product'),
branch_id => $c->param('editform_branch'),
enabled => $enabled,
community_enabled => $community_enabled,
regression_bug_id => $c->param('editform_regression_bug_id') ? $c->param('editform_regression_bug_id') : '',
author_id => $c->param('editform_author_id'),
creation_date => $now,
last_updated => $now,
);
my $new_testcase =
Litmus::DB::Testcase->create(\%hash);
if ($new_testcase) {
$status = "success";
$message = "Testcase added successfully. New testcase ID# is " . $new_testcase->testcase_id;
$defaults->{'testcase_id'} = $new_testcase->testcase_id;
$rebuild_cache=1;
} else {
$status = "failure";
$message = "Failed to add testcase.";
}
} elsif ($c->param("editform_mode") eq "edit") {
requireField('testcase_id', $c->param("editform_testcase_id"));
$testcase_id = $c->param("editform_testcase_id");
my $testcase = Litmus::DB::Testcase->retrieve($testcase_id);
if ($testcase) {
$testcase->summary($c->param('editform_summary'));
$testcase->steps($c->param('editform_steps') ? $c->param('editform_steps') : '');
$testcase->expected_results($c->param('editform_results') ? $c->param('editform_results') : '');
$testcase->product_id($c->param('editform_product'));
$testcase->branch_id($c->param('editform_branch'));
$testcase->enabled($enabled);
$testcase->community_enabled($community_enabled);
$testcase->regression_bug_id($c->param('editform_regression_bug_id') ? $c->param('editform_regression_bug_id') : '');
$testcase->author_id($c->param('editform_author_id'));
$testcase->last_updated($now);
$testcase->version($testcase->version + 1);
$rv = $testcase->update();
if ($rv) {
$status = "success";
$message = "Testcase ID# $testcase_id updated successfully.";
$defaults->{'testcase_id'} = $testcase_id;
$rebuild_cache=1;
} else {
$status = "failure";
$message = "Failed to update testcase ID# $testcase_id.";
}
} else {
$status = "failure";
$message = "Testcase ID# $testcase_id not found.";
}
}
} else {
$defaults->{'testcase_id'} = $c->param("testcase_id");
}
if ($defaults) {
$vars->{'defaults'} = $defaults;
}
if ($status and $message) {
$vars->{'onload'} = "toggleMessage('$status','$message');";
}
if ($rebuild_cache) {
Litmus::Cache::rebuildCache();
}
my $testcases = Litmus::FormWidget->getTestcases(0,'name');
my $products = Litmus::FormWidget->getProducts();
my $authors = Litmus::FormWidget->getAuthors();
$vars->{'title'} = "Manage Testcases";
$vars->{'testcases'} = $testcases;
$vars->{'products'} = $products;
$vars->{'authors'} = $authors;
$vars->{'user'} = Litmus::Auth::getCurrentUser();
$vars->{'edit'} = $edit;
my $cookie = Litmus::Auth::getCookie();
$vars->{"defaultemail"} = $cookie;
$vars->{"show_admin"} = Litmus::Auth::istrusted($cookie);
print $c->header();
Litmus->template()->process("admin/manage_testcases.tmpl", $vars) ||
internalError("Error loading template: ".Litmus->template()->error());