use strict;
use warnings;
use Path::Class;
use Test::More 'no_plan';
use Test::Exception;
my $thisdir=file($0)->parent->absolute;
BEGIN { use_ok('WebCoso::Config'); }
{
my $conf_file=<<'EOF';
res('src/file1.rest.txt','Id','dst/file.html');
EOF
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
'eseguita la configurazione');
my @resources=WebCoso::Config->get_all_resources();
is(scalar @resources,1,'una risorsa definta');
isa_ok($resources[0],'WebCoso::Config::Resource');
is_deeply(
[$resources[0]->axes()],
['filename'],
'un solo asse');
is_deeply(
[$resources[0]->axis('filename')],
["$thisdir/src/file1.rest.txt"],
'filename');
is($resources[0]->datastream(filename=>"$thisdir/src/file1.rest.txt"),
<<'EOF','');
Titolo
======
testo
EOF
is_deeply(
[$resources[0]->properties()],
[],
'no properties');
is_deeply(
[$resources[0]->collections()],
[],
'no collections');
}
WebCoso::Config->clear();
{
my $conf_file=<<'EOF';
res('src/file1.rest.txt','src/nonce.rest.txt','Id','dst/file.html');
EOF
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
'eseguita la configurazione');
my @resources=WebCoso::Config->get_all_resources();
is(scalar @resources,1,'una risorsa definta');
is_deeply(
[$resources[0]->axis('filename')],
["$thisdir/src/file1.rest.txt", "$thisdir/src/nonce.rest.txt"],
'filenames');
dies_ok
{
$resources[0]->datastream(filename=>"$thisdir/src/nonce.rest.txt")
}
'muore se non trova il file';
}
WebCoso::Config->clear();
{
my $conf_file=<<'EOF';
coll('coll1');
EOF
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
'eseguita la configurazione');
is(scalar WebCoso::Config->get_all_resources(),0,'nessuna risorsa');
my @collections=WebCoso::Config->get_all_collections();
is(scalar @collections,1,'una collezione');
is_deeply(
[$collections[0]->axes()],
['language'],
'multilingua');
is_deeply(
[$collections[0]->axis('language')],
[''],
'ma nessuna definita');
my $props=$collections[0]->properties(language=>'');
isa_ok($props,'HASH');
is_deeply(
$props,
{name=>'coll1'},
'solo il nome');
is_deeply(
[$collections[0]->get_parents()],
[],
'no parents');
is_deeply(
[$collections[0]->get_children()],
[],
'no children');
is_deeply(
[$collections[0]->get_resources()],
[],
'no resources');
}
WebCoso::Config->clear();
{
my $conf_file=<<'EOF';
my $c1=coll({it=>'coll1',en=>'coll1-en'});
coll('coll2',[],[$c1]);
EOF
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
'eseguita la configurazione');
my @collections=WebCoso::Config->get_all_collections();
is(scalar @collections,2,'due collezioni');
is_deeply(
[sort $collections[0]->axis('language')],
['en', 'it'],
'due lingue');
is(
$collections[0]->properties(language=>'en')->{name},
'coll1-en',
'nome en');
is(
$collections[0]->properties(language=>'it')->{name},
'coll1',
'nome it');
is_deeply(
[$collections[0]->get_parents()],
[$collections[1]],
'c2 padre di c1');
is_deeply(
[$collections[0]->get_children()],
[],
'c1 no children');
is_deeply(
[$collections[1]->get_parents()],
[],
'c2 no parents');
is_deeply(
[$collections[1]->get_children()],
[$collections[0]],
'c1 figlio di c2');
}