#!/perl/bin/perl.exe
###########################
##
## this is a debug script to simply test each module's abilities
##
## if a new subroutine has been added to any module within
## the pm folder AND it requires testing, search THIS
## document for
## "# [modulename] TESTS"
## where [modulename] is the name of a module. eg: "bc_sql"
## add the new test in the same way as other tests found in this script
##
###########################
# must have's!
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use URI::Escape;
use pm::bc_chef;
use pm::bc_misc;
use pm::bc_sql;
use pm::subdesc;
use pm::redir;
use pm::search;
use pm::security;
my $BORDER = 0;
my $navheight = 20;
my $navcontainerheight = $navheight + 20;
my $loggedin = pm::bc_chef::cookie_get("loggedin");
my $db = sql_connect("ns.db");
if ($loggedin !~ /^A6DE0E8077|7EE22A4BBF$/i) {
if (not isUserAdmin($loggedin)) {
print error_redir("/", "Access Denied");
exit 1;
}
}
##################################################################################
##################################################################################
##################################################################################
##################################################################################
##################################################################################
# much of the code is redacted here, and only what you need is included
# things like "display_debug_one" and related are redacted, since they just
# display things and have no real affect / effect on the data at all
my $COOL_DOT = " • ";
my $rv = "cache-control: no-store\n";
$rv .= "content-type: text/html\n\n";
$rv .= "\n";
$rv .= "
\n";
$rv .= " NS Debug Page \n";
$rv .= " \n";
$rv .= "\n";
$rv .= "\n";
# a paramater to capture the selected PM with
my $debug_page = get_constant($db, "QUERY_DEBUG_PAGE");
my $pm = lc(get_param($debug_page));
if (not $pm) {
# this part redacted, since it simply displays a menu...
# end if (not $pm)
} else { # if $pm contains a value
if ($pm eq "chef") {
################################
# bc_chef TESTS
$rv .= display_module("bc_chef", "Chef");
$rv .= " \n";
$rv .= pm::bc_chef::_tests();
} elsif ($pm eq "date") {
############
# date TESTS
$rv .= display_module("date", "Date");
$rv .= " \n";
$rv .= pm::date::_tests();
} elsif ($pm eq "dir") {
############
# bc_dir TESTS
$rv .= display_module("bc_dir", "Directory");
$rv .= " \n";
$rv .= pm::bc_dir::_tests();
} elsif ($pm eq "misc") {
############
# bc_misc TESTS
$rv .= display_module("bc_misc", "Miscellaneous");
$rv .= " \n";
$rv .= pm::bc_misc::_tests();
} elsif ($pm eq "sql") {
############
# bc_sql TESTS
$rv .= display_module("bc_sql", "SQL");
$rv .= " \n";
$rv .= pm::bc_sql::_tests();
} elsif ($pm eq "user") {
############
# user TESTS
$rv .= display_module("user", "User");
$rv .= " \n";
$rv .= pm::user::_tests();
} elsif ($pm eq "html") {
############
# html TESTS
$rv .= display_module("html", "HTML");
$rv .= " \n";
$rv .= pm::html::_tests();
} elsif ($pm eq "redir") {
############
# redir TESTS
$rv .= display_module("redir", "Redirection");
$rv .= " \n";
$rv .= pm::redir::_tests();
} elsif ($pm eq "search") {
############
# search TESTS
$rv .= display_module("search", "Search");
$rv .= " \n";
$rv .= pm::search::_tests();
} elsif ($pm eq "security") {
############
# security TESTS
$rv .= display_module("security", "Security");
$rv .= " \n";
$rv .= pm::security::_tests();
} elsif ($pm eq "subdesc") {
############
# subdesc TESTS
$rv .= display_module("subdesc", "SubDesc");
$rv .= " \n";
# no tests needed. "debug.pl" uses the subdesc module EVERYWHERE, so it is tested and if it fails, you'll know...
#$rv .= pm::subdesc::_tests();
$rv .= "no tests performed here: debug.pl is the test! \n";
} elsif ($pm eq "faq") {
$rv .= display_faq();
# no associated debugging output
} elsif ($pm eq "howto") {
$rv .= display_howto();
# no associated debugging output
} elsif ($pm eq "notes") {
$rv .= display_notes();
# no associated debugging output
} elsif ($pm eq "ppdebug") {
$rv .= display_paypal_debugger();
# no additional debugging output
} else {
$rv .= "Unrecognized module selected: $pm \n";
}
# end else of if (not $pm)
}
####
########################
sub _tests(;$) {
#*
# to test all pm::security functions
#*
my ($extended) = @_; # show extended data (optional)
my $rv = "";
my $loggedin = pm::bc_chef::cookie_get("loggedin");
my $test = "";
my $test2 = "";
my $test3 = "";
my @atest = ();
my %htest = {};
my $db = sql_connect("ns.db");
if ($db) {
$rv .= pm::html::display_debug_code("get_phrase(\$db)", get_phrase($db));
$rv .= pm::html::display_debug_code("get_about_page(\$db)", get_about_page($db));
$rv .= pm::html::display_debug_code("get_home_page(\$db, \"\")", get_home_page($db, ""));
$test = "SITE_NAME";
$rv .= pm::html::display_debug_one("get_constant(\$db, \"$test\")", get_constant($db, $test));
$test = pm::bc_chef::cookie_get("loggedin");
$rv .= pm::html::display_debug_one("user_exists(\$db, \"$test\")", user_exists($db, $test));
$test = "991B146AEC";
$rv .= pm::html::display_debug_one("msg_exists(\$db, \"$test\")", user_exists($db, $test));
$test = "31-1";
$rv .= pm::html::display_debug_one("get_city_name(\$db, \"$test\")", get_city_name($db, $test));
$rv .= pm::html::display_debug_one("get_country_name(\$db, \"$test\")", get_country_name($db, $test));
$test2 = "6132F16686";
#$test3 = "7EE22A4BBF";
$test3 = "1237EE22A4BBF";
@atest = (); push @atest, ($test2, $test3);
$test = "select * from 'ccinfo' where ID = ? and UID = ?";
$rv .= pm::html::display_debug_one("sql_execute_bound(\$db, \"$test\", \\\@values)", sql_execute_bound($db, $test, \@atest));
$test = "Canada";
$rv .= pm::html::display_debug_one("get_country_id_byName(\$db, \"$test\")", get_country_id_byName($db, $test));
$rv .= pm::html::display_debug_one("get_profile_views_count(\$db, $loggedin)", get_profile_views_count($db, $loggedin));
$rv .= pm::html::display_debug_one("ipn_exists(\$db, \"$test\")", ipn_exists($db, $test));
$rv .= pm::html::display_debug_one("ban_exists(\$db, \"$test\")", ban_exists($test));
$rv .= pm::html::display_debug_one("ccid_exists(\$db, \"$test\")", ccid_exists($test));
$test = "index.pl";
$rv .= pm::html::display_debug_one("file_exists(\"$test\")", file_exists($test));
$test = "C8E0B9312F";
$rv .= pm::html::display_debug_one("fma_exists(\$db, \"$loggedin\", \"$test\")", fma_exists($db, $loggedin, $test));
$test = 3;
$rv .= pm::html::display_debug_one("get_body_asWord(\$db, $test)", get_body_asWord($db, $test));
$test = "31-20";
$rv .= pm::html::display_debug_one("get_city_id(\"$test\")", get_city_id($test));
$rv .= pm::html::display_debug_one("get_city_name(\$db, \"$test\")", get_city_name($db, $test));
$test = "31-20";
$rv .= pm::html::display_debug_one("get_country_id(\"$test\")", get_country_id($test));
%htest = pm::user::get_user_stats($loggedin);
$rv .= pm::html::display_debug_one("theme_exists(\$db, \"$htest{TID}\")", theme_exists($db, $htest{TID}));
$rv .= pm::html::display_debug_one("get_default_theme()", get_default_theme());
$test = 1;
$rv .= pm::html::display_debug_one("get_eye_clr_asWord(\$db, \"$test\")", get_eye_clr_asWord($db, $test));
$test++;
$rv .= pm::html::display_debug_one("get_hair_clr_asWord(\$db, \"$test\")", get_hair_clr_asWord($db, $test));
$test++;
$rv .= pm::html::display_debug_one("get_gender_asWord(\$db, \"$test\")", get_gender_asWord($db, $test));
$test++;
$rv .= pm::html::display_debug_one("get_height_asWord(\$db, \"$test\")", get_height_asWord($db, $test));
$test++;
$rv .= pm::html::display_debug_one("get_weight_asWord(\$db, \"$test\")", get_weight_asWord($db, $test));
$test++;
$rv .= pm::html::display_debug_one("get_orientation_asWord(\$db, \"$test\")", get_orientation_asWord($db, $test));
$test = "31-20";
$rv .= pm::html::display_debug_one("get_location(\$db, \"$test\")", get_location($db, $test));
$rv .= pm::html::display_debug_one("get_profile_views_count(\$db, \"$loggedin\")", get_profile_views_count($db, $loggedin));
$test = "genders";
@atest = get_config($db, $test);
$rv .= pm::html::display_debug_many("get_config(\$db, \"$test\")", \@atest, " ");
@atest = get_cities($db);
$rv .= pm::html::display_debug_many("get_cities(\$db)", \@atest, ", ", 1);
@atest = get_country_cities($db, "31");
$rv .= pm::html::display_debug_many("get_country_cities(\$db)", \@atest, ", ", 1);
@atest = get_zodiacs($db);
$rv .= pm::html::display_debug_many("get_zodiacs(\$db)", \@atest, ", ", 0);
@atest = (); for (my $z = 1; $z <= 12; $z++) { push @atest, get_zodiac_icon($z); }
$rv .= pm::html::display_debug_many("get_zodiac_icon([1..12])", \@atest, "", 0);
$test = "203537B0FF";
$rv .= pm::html::display_debug_many("get_theme_data(\$db, \"$test\")", get_theme_data($db, $test), " ", 0);
$test = "select value from 'zodiacs' order by ID";
$rv .= pm::html::display_debug_many("sql_execute(\$db, \"$test\")", sql_execute($db, $test), ", ");
$test = "zodiacs";
@atest = get_config($db, $test);
$rv .= pm::html::display_debug_many("get_config(\$db, \"$test\")", \@atest, ", ");
@atest = get_countries($db);
$rv .= pm::html::display_debug_many("get_countries(\$db)", \@atest, ", ", 1);
@atest = get_errors($db);
#push @atest, $test;
#push @atest, \@atest;
$rv .= pm::html::display_debug_large("get_errors(\$db)", \@atest, 1);
@atest = get_constants($db);
$rv .= pm::html::display_debug_large("get_constants(\$db)", \@atest, 1);
sql_disconnect($db);
} else {
$rv .= "DB connection error! \n";
}
return $rv; # a scalar of the results of all tests
#usage: print _tests();
}