2006-06-20 19:34:53 +00:00
|
|
|
#!/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;
|
2006-06-22 22:05:33 +00:00
|
|
|
use Litmus::Cache;
|
2006-06-20 19:34:53 +00:00
|
|
|
use Litmus::Error;
|
|
|
|
use Litmus::FormWidget;
|
|
|
|
use Litmus::Utils;
|
|
|
|
|
|
|
|
use CGI;
|
|
|
|
use Date::Manip;
|
|
|
|
|
2006-08-01 20:50:15 +00:00
|
|
|
Litmus->init();
|
2006-06-20 19:34:53 +00:00
|
|
|
my $c = Litmus->cgi();
|
|
|
|
|
|
|
|
my $vars;
|
|
|
|
|
|
|
|
my $testcase_id;
|
2006-06-30 18:37:29 +00:00
|
|
|
my $edit;
|
2006-06-20 19:34:53 +00:00
|
|
|
my $message;
|
|
|
|
my $status;
|
|
|
|
my $rv;
|
2006-07-13 17:17:59 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
|
2006-06-20 19:34:53 +00:00
|
|
|
if ($c->param("testcase_id")) {
|
|
|
|
$testcase_id = $c->param("testcase_id");
|
2006-06-30 18:37:29 +00:00
|
|
|
if ($c->param("edit")) {
|
|
|
|
$edit = $testcase_id;
|
|
|
|
}
|
2006-06-20 19:34:53 +00:00
|
|
|
}
|
|
|
|
|
2006-06-22 22:05:33 +00:00
|
|
|
my $rebuild_cache = 0;
|
2006-06-22 22:54:02 +00:00
|
|
|
my $defaults;
|
2006-06-20 19:34:53 +00:00
|
|
|
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.";
|
2006-06-22 22:05:33 +00:00
|
|
|
$rebuild_cache=1;
|
2006-06-20 19:34:53 +00:00
|
|
|
} 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;
|
2006-06-22 22:54:02 +00:00
|
|
|
$defaults->{'testcase_id'} = $new_testcase->testcase_id;
|
2006-06-22 22:05:33 +00:00
|
|
|
$rebuild_cache=1;
|
2006-06-20 19:34:53 +00:00
|
|
|
} 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('product'));
|
|
|
|
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('product'),
|
|
|
|
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;
|
2006-06-22 22:54:02 +00:00
|
|
|
$defaults->{'testcase_id'} = $new_testcase->testcase_id;
|
2006-06-22 22:05:33 +00:00
|
|
|
$rebuild_cache=1;
|
2006-06-20 19:34:53 +00:00
|
|
|
} 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('product'));
|
|
|
|
$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.";
|
2006-06-22 22:54:02 +00:00
|
|
|
$defaults->{'testcase_id'} = $testcase_id;
|
2006-06-22 22:05:33 +00:00
|
|
|
$rebuild_cache=1;
|
2006-06-20 19:34:53 +00:00
|
|
|
} 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");
|
2006-06-22 22:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($defaults) {
|
|
|
|
$vars->{'defaults'} = $defaults;
|
2006-06-20 19:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($status and $message) {
|
|
|
|
$vars->{'onload'} = "toggleMessage('$status','$message');";
|
|
|
|
}
|
|
|
|
|
2006-06-22 22:05:33 +00:00
|
|
|
if ($rebuild_cache) {
|
2006-08-15 16:17:38 +00:00
|
|
|
Litmus::Cache::rebuildCache();
|
2006-06-22 22:05:33 +00:00
|
|
|
}
|
|
|
|
|
2006-07-13 17:17:59 +00:00
|
|
|
my $testcases = Litmus::FormWidget->getTestcases();
|
2006-06-20 19:34:53 +00:00
|
|
|
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();
|
2006-06-30 18:37:29 +00:00
|
|
|
$vars->{'edit'} = $edit;
|
2006-06-20 19:34:53 +00:00
|
|
|
|
|
|
|
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) ||
|
2006-07-13 17:17:59 +00:00
|
|
|
internalError("Error loading template: ".Litmus->template()->error());
|
2006-06-20 19:34:53 +00:00
|
|
|
|