From: Chris W. <la...@us...> - 2004-11-28 20:29:20
|
Update of /cvsroot/openinteract/OpenInteract2/t In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19384/t Modified Files: utils.pl Added Files: 00_manage_create_website.t Removed Files: manage_create_website.t Log Message: OIN-107: order the tests so that the management task to create a website runs first and leaves the website in a usable state for other tests that need it --- NEW FILE: 00_manage_create_website.t --- # -*-perl-*- # $Id: 00_manage_create_website.t,v 1.1 2004/11/28 20:29:09 lachoy Exp $ # Odd name rationale: we try to run this test first to get the test # site created and available for other tests that need it. # See: http://jira.openinteract.org/browse/OIN-107 use strict; use lib 't/'; require 'utils.pl'; use File::Spec::Functions qw( :ALL ); use Test::More tests => 45; require_ok( 'OpenInteract2::Manage' ); my $website_dir = get_test_site_dir(); # If the testing site already exists it's history if ( -d $website_dir ) { rmtree( $website_dir ); } my $source_dir = get_source_dir(); create_tmp_dir(); my $task = eval { OpenInteract2::Manage->new( 'create_website', { website_dir => $website_dir, source_dir => $source_dir }) }; ok( ! $@, 'Task created' ) || diag "Error: $@"; is( ref $task, 'OpenInteract2::Manage::Website::Create', 'Correct type of task created' ); # TODO: Add observer here to ensure we get all the fired # observations... warn "\nCreating website... this may take a while\n"; my @status = eval { $task->execute }; ok( ! $@, 'Task executed' ) || diag "Error: $@"; is( scalar @status, 109, 'Number of status messages' ); # Look at the directories we should have created and see they're there my @check_dir_pieces = qw( cache cache/tt cache/content cache/sessions cache/sessions_lock conf error html html/images html/images/icons logs mail msg overflow pkg template uploads ); foreach my $piece ( @check_dir_pieces ) { my $check_dir = catdir( $website_dir, split( '/', $piece ) ); ok( -d $check_dir, "Created directory $piece" ); } # Now just count up the directories and files where it matters is( count_dirs( $website_dir ), 12, "Number of top-level directories" ); is( first_dir( $website_dir ), 'cache', 'First dir in top-level' ); is( last_dir( $website_dir ), 'uploads', 'Last dir in top-level' ); is( count_files( $website_dir ), 0, "Number of top-level files" ); is( count_dirs( catdir( $website_dir, 'cache' ) ), 4, 'Number of directories in cache/' ); my $site_conf_dir = catdir( $website_dir, 'conf' ); is( count_files( $site_conf_dir ), 16, "Number of files in conf/" ); is( first_file( $site_conf_dir ), 'base.conf', "First file in conf/" ); is( last_file( $site_conf_dir ), 'startup_mp2.pl', "Last file in conf/" ); my $site_html_dir = catdir( $website_dir, 'html' ); is( count_dirs( $site_html_dir ), 1, "Number of directories in html/" ); is( count_files( $site_html_dir ), 5, "Number of files in html/" ); is( first_file( $site_html_dir ), '.no_overwrite', "First file in html/" ); is( last_file( $site_html_dir ), 'main.css', "Last file in html/" ); my $site_images_dir = catdir( $website_dir, 'html', 'images' ); is( count_dirs( $site_images_dir ), 1, "Number of directories in html/images/" ); is( count_files( $site_images_dir ), 14, "Number of files in html/images/" ); my $site_icons_dir = catdir( $website_dir, 'html', 'images', 'icons' ); is( count_files( $site_icons_dir ), 27, "Number of files in html/images/icons/" ); my $site_msg_dir = catdir( $website_dir, 'msg' ); is( count_files( $site_msg_dir ), 1, 'Number of files in msg/' ); my $site_pkg_dir = catdir( $website_dir, 'pkg' ); is( count_dirs( $site_pkg_dir ), 16, 'Number of directories in pkg/' ); my $site_template_dir = catdir( $website_dir, 'template' ); is( count_files( $site_template_dir ), 58, "Number of files in template/" ); is( first_file( $site_template_dir ), '.no_overwrite', 'First file in template/' ); is( last_file( $site_template_dir ), 'to_group', 'Last file in template/' ); # Open up the repository and see that all the files are there my $repository = OpenInteract2::Repository->new({ website_dir => $website_dir, }); is( $repository->full_config_dir, $site_conf_dir, 'Repository reports proper config dir' ); is( $repository->full_package_dir, $site_pkg_dir, 'Repository reports proper config dir' ); my $packages = $repository->fetch_all_packages; is( scalar @{ $packages }, 16, 'Repository contains correct number of packages' ); # These operations done for the rest of the tests (not optimal for # design, but good for speed) write_website_check_file(); initialize_website_libraries(); modify_website_post_creation( $website_dir ); Index: utils.pl =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/t/utils.pl,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** utils.pl 28 Nov 2004 06:46:09 -0000 1.79 --- utils.pl 28 Nov 2004 20:29:09 -0000 1.80 *************** *** 106,109 **** --- 106,117 ---- } + sub main::create_tmp_dir { + my $tmp_dir = get_tmp_dir(); + unless ( -d $tmp_dir ) { + LOG()->debug( "Creating temp dir '$tmp_dir'" ); + mkdir( $tmp_dir, 0777 ); + } + } + # Get the base website directory for testing *************** *** 182,190 **** # WEBSITE INSTALL/CONTEXT INIT ! sub main::install_website { ! my $source_dir = get_source_dir(); ! my $website_dir = get_test_site_dir(); ! my $is_recent = _is_recent_website( $website_dir ); ! eval { require SPOPS::DBI::SQLite; --- 190,194 ---- # WEBSITE INSTALL/CONTEXT INIT ! sub main::initialize_website_libraries { eval { require SPOPS::DBI::SQLite; *************** *** 201,204 **** --- 205,216 ---- die "Failed to require file session modules: $@"; } + } + + sub main::install_website { + my $source_dir = get_source_dir(); + my $website_dir = get_test_site_dir(); + my $is_recent = _is_recent_website( $website_dir ); + + initialize_website_libraries(); if ( -d $website_dir and $is_recent ) { *************** *** 220,228 **** unlink( $db_file ); } ! my $tmp_dir = get_tmp_dir(); ! unless ( -d $tmp_dir ) { ! LOG()->debug( "Creating temp dir '$tmp_dir'" ); ! mkdir( $tmp_dir, 0777 ); ! } # let any errors bubble up --- 232,236 ---- unlink( $db_file ); } ! create_tmp_dir(); # let any errors bubble up *************** *** 234,246 **** LOG()->debug( "Executed management task ok" ); ! _write_website_check_file(); ! _modify_server_config(); ! ! CTX->setup({ skip => 'activate spops' }); ! OpenInteract2::Manage->new( 'install_sql', ! { website_dir => $website_dir, ! package => [ 'SYSTEM' ] } ) ! ->execute; ! OpenInteract2::Setup->activate_spops_classes; return $website_dir; } --- 242,247 ---- LOG()->debug( "Executed management task ok" ); ! write_website_check_file(); ! modify_website_post_creation( $website_dir ); return $website_dir; } *************** *** 255,259 **** } ! sub _write_website_check_file { my $check_recent = _get_website_check_file(); open( RECENT, '>', $check_recent ) --- 256,260 ---- } ! sub main::write_website_check_file { my $check_recent = _get_website_check_file(); open( RECENT, '>', $check_recent ) *************** *** 268,276 **** } # Write out SQLite information so that the Context gets read in # properly (SPOPS classes need this); use file-based sessions and # write the appropriate directories ! sub _modify_server_config { my $site_dir = get_test_site_dir(); my $config_file = catfile( $site_dir, 'conf', 'server.ini' ); --- 269,289 ---- } + sub main::modify_website_post_creation { + my ( $website_dir ) = @_; + modify_server_config(); + CTX->setup({ skip => 'activate spops' }); + OpenInteract2::Manage->new( + 'install_sql', { + website_dir => $website_dir, + package => [ 'SYSTEM' ], + })->execute(); + OpenInteract2::Setup->activate_spops_classes; + } + # Write out SQLite information so that the Context gets read in # properly (SPOPS classes need this); use file-based sessions and # write the appropriate directories ! sub main::modify_server_config { my $site_dir = get_test_site_dir(); my $config_file = catfile( $site_dir, 'conf', 'server.ini' ); --- manage_create_website.t DELETED --- |