1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#!perl
use 5.012;
use strict;
use warnings;
use App::CELL qw( $CELL $log $meta $core $site );
use App::CELL::Test qw( mktmpdir cleartmpdir populate_file );
#use App::CELL::Test::LogToFile;
#use Data::Dumper;
use File::Spec;
use Scalar::Util qw( blessed );
use Test::More;
use Test::Warnings;
my $status;
delete $ENV{CELL_DEBUG_MODE};
$log->init( ident => 'CELLtest', debug_mode => 1 );
$log->info("------------------------------------------------------- ");
$log->info("--- 110-site.t ---");
$log->info("------------------------------------------------------- ");
$status = mktmpdir();
ok( $status->ok, "Temporary directory created" );
my $sitedir = $status->payload;
ok( -d $sitedir, "tmpdir is a directory" );
ok( -W $sitedir, "tmpdir is writable by us" );
my $full_path = File::Spec->catfile( $sitedir, 'CELL_Message_en.conf' );
my $stuff = <<'EOS';
# some messages in English
TEST_MESSAGE
This is a test message.
FOO_BAR
Message that says foo bar.
BAR_ARGS_MSG
This %s message takes %s arguments.
EOS
#diag( "Now populating $full_path" );
populate_file( $full_path, $stuff );
$full_path = File::Spec->catfile( $sitedir, 'CELL_Message_cz.conf' );
$stuff = <<'EOS';
# some messages in Czech
TEST_MESSAGE
Tato zpráva slouží k testování.
FOO_BAR
Zpráva, která zní foo bar.
BAR_ARGS_MSG
Tato %s zpráva bere %s argumenty.
EOS
#diag( "Now populating $full_path" );
populate_file( $full_path, $stuff );
$full_path = File::Spec->catfile( $sitedir, 'CELL_SiteConfig.pm' );
$stuff = <<'EOS';
# set supported languages
set( 'CELL_SUPP_LANG', [ 'en', 'cz' ] );
# a random parameter
set( 'A_RANDOM_PARAMETER', "34WDFWWD" );
1;
EOS
#diag( "Now populating $full_path" );
populate_file( $full_path, $stuff );
ok( ! defined( $meta->CELL_META_SITEDIR_LOADED ), "Meta param undefined before load");
$status = $CELL->load( sitedir => $sitedir );
ok( $status->ok, "CELL initialization with sitedir OK" );
ok( $meta->CELL_META_SITEDIR_LOADED, "Meta param set correctly after load" );
is( $CELL->loaded, "BOTH", "Both sharedir and sitedir have been loaded" );
is_deeply( $meta->CELL_META_SITEDIR_LIST, [ $sitedir ], "List of sitedirs is correct" );
is_deeply( $CELL->supported_languages, [ 'en', 'cz' ],
"CELL now supports two languages instead of just one" );
ok( $CELL->language_supported( 'en' ), "English is supported" );
ok( $CELL->language_supported( 'cz' ), "Czech is supported" );
ok( ! $CELL->language_supported( 'fr' ), "French is not supported" );
is( $site->CELL_DEF_LANG, 'en', "Site language default is English" );
my $msgobj = $CELL->msg('TEST_MESSAGE');
ok( blessed($msgobj), "Message object is blessed" );
is( $msgobj->text, 'This is a test message.',
"Test message has the right text" );
$msgobj = $CELL->msg( 'NON_EXISTENT_MESSAGE' );
ok( blessed($msgobj), "Message object with undefined code is blessed" );
is( $msgobj->text, 'NON_EXISTENT_MESSAGE',
"Non-existent message text the same as non-existent message code" );
$msgobj = $CELL->msg( 'BAR_ARGS_MSG', "FooBar", 2 );
is( $msgobj->text, 'This FooBar message takes 2 arguments.' );
#$status = $msgobj->lang('cz');
#my $cesky_text = $status->payload->text;
#is( $cesky_text, "Tato FooBar zpráva bere 2 argumenty." );
is( $site->A_RANDOM_PARAMETER, "34WDFWWD", "Random parameter has value we set" );
#---
# and now, a second sitedir
#---
$status = mktmpdir();
ok( $status->ok, "Second temporary directory created" );
my $sitedir2 = $status->payload;
ok( -d $sitedir2, "Second tmpdir is a directory" );
ok( -W $sitedir2, "Second tmpdir is writable by us" );
$full_path = File::Spec->catfile( $sitedir2, 'CELL2_Message_en.conf' );
$stuff = <<'EOS';
# some messages for the second sitedir
TEST2_MESSAGE
This is a test2 message.
FOO2_BAR
Second message that says bar foo.
BAR2_ARGS_MSG
This second %s message takes %s arguments.
EOS
#diag( "Now populating $full_path" );
populate_file( $full_path, $stuff );
$full_path = File::Spec->catfile( $sitedir2, 'CELL_SiteConfig.pm' );
$stuff = <<'EOS';
set( 'CELL2_BIG_BUS_PARAM', "Vehiculo longo" );
# a random parameter
set( 'A_RANDOM_PARAMETER', "different value" );
use strict;
use warnings;
1;
EOS
#diag( "Now populating $full_path" );
populate_file( $full_path, $stuff );
$status = $CELL->load( sitedir => $sitedir2 );
ok( $status->ok, "CELL initialization with second sitedir OK" );
is( $site->CELL2_BIG_BUS_PARAM, "Vehiculo longo", "Unique param has value we set" );
is( $site->A_RANDOM_PARAMETER, "34WDFWWD", "Attempt to overwrite existing site param failed" );
is( $meta->CELL_META_SITEDIR_LOADED, 2, "Meta param set correctly after second load");
is_deeply( $meta->CELL_META_SITEDIR_LIST, [ $sitedir, $sitedir2 ], "List of sitedirs correctly expanded after second load" );
done_testing;
|