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]->get_axes()],
['filename'],
'un solo asse');
is_deeply(
[$resources[0]->get_axis_value('filename')],
["$thisdir/src/file1.rest.txt"],
'filename');
is($resources[0]->get_datastream(filename=>"$thisdir/src/file1.rest.txt"),
<<'EOF','');
Titolo
======
testo
EOF
is_deeply(
[$resources[0]->get_properties()],
[],
'no properties');
is_deeply(
[$resources[0]->get_collections()],
[],
'no collections');
is(WebCoso::Config->get_pipeline_for($resources[0]),
'WebCoso::Pipeline::Id',
'si segna le pipeline');
throws_ok {
WebCoso::Config->get_pipeline_for('not-a-resource')
}
'WebCoso::X::NoSuchResource',
'muore se gli si chiede una risorsa ignota';
}
WebCoso::Config->clear();
{
my $conf_file=<<'EOF';
res('src/file1.rest.txt','src/nonce.rest.txt','Id','dst/file.html');
EOF
throws_ok {
WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test")
}
'WebCoso::X::ConfigError',
'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_collections();
isa_ok($collections,'WebCoso::Config::Collections');
my @collections=$collections->get_all_collections();
is(scalar @collections,1,'una collezione');
is_deeply(
[$collections[0]->get_axes()],
['language'],
'multilingua');
is_deeply(
[$collections[0]->get_axis_value('language')],
[],
'ma nessuna definita');
is_deeply(
[$collections->get_axes()],
['language'],
'multilingua, insieme');
is_deeply(
[$collections->get_axis_value('language')],
[],
'ma nessuna definita, insieme');
my $props=$collections[0]->get_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');
is_deeply(
[$collections->get_root_collections()],
[@collections],
'una radice');
is_deeply(
[$collections->get_leaf_collections()],
[@collections],
'una foglia');
}
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_collections();
my @collections=$collections->get_all_collections();
is(scalar @collections,2,'due collezioni');
is_deeply(
[sort $collections[0]->get_axis_value('language')],
['en', 'it'],
'due lingue');
is_deeply(
[sort $collections->get_axis_value('language')],
['en', 'it'],
'due lingue');
is(
$collections[0]->get_properties(language=>'en')->{name},
'coll1-en',
'nome en');
is(
$collections[0]->get_properties(language=>'it')->{name},
'coll1',
'nome it');
is(
$collections[1]->get_properties(language=>'it')->{name},
'coll2',
'nome default');
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');
is_deeply(
[$collections->get_root_collections()],
[$collections[1]],
'una radice');
is_deeply(
[$collections->get_leaf_collections()],
[$collections[0]],
'una foglia');
}
WebCoso::Config->clear();
{
my $conf_file=<<'EOF';
$c1=coll({it=>'coll1',en=>'coll1-en'});
$c2=coll('coll2',[],[$c1]);
$c1->add_child($c2);
EOF
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
'eseguita la configurazione (no strict)');
my $collections=WebCoso::Config->get_collections();
my @collections=$collections->get_all_collections();
is(scalar @collections,2,'due collezioni');
is_deeply(
[$collections[1]->get_children()],
[$collections[0]],
'c1 figlio di c2');
is_deeply(
[$collections[0]->get_parents()],
[$collections[1]],
'c2 padre di c1');
is_deeply(
[$collections[0]->get_children()],
[$collections[1]],
'c2 figlio di c1');
is_deeply(
[$collections[1]->get_parents()],
[$collections[0]],
'c1 padre di c2');
is_deeply(
[$collections->get_root_collections()],
[],
'nessuna radice');
is_deeply(
[$collections->get_leaf_collections()],
[],
'nessuna foglia');
}
WebCoso::Config->clear();
{
my $conf_file=<<'EOF';
$r1=res('src/file1.rest.txt','Id','dst/file.html');
$c1=coll('coll1');
$c1->add_res($r1);
EOF
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
'eseguita la configurazione (no strict)');
my @resources=WebCoso::Config->get_all_resources();
my $collections=WebCoso::Config->get_collections();
my @collections=$collections->get_all_collections();
is(scalar @resources,1,'una risorsa');
is(scalar @collections,1,'una collezione');
is_deeply(
[$resources[0]->get_collections()],
[$collections[0]],
'aggancio r->c');
is_deeply(
[$collections[0]->get_resources()],
[$resources[0]],
'aggancio c->r');
}
WebCoso::Config->clear();
{
my $conf_file=<<'EOF';
$r1=res('src/file1.rest.txt','Id','dst/file.html');
$c1=coll('coll1');
$c2=coll('coll2');
$c1->add_res($r1);
$r1->add_coll($c1);
$c2->add_res($r1);
EOF
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
'eseguita la configurazione (no strict)');
my @resources=WebCoso::Config->get_all_resources();
my $collections=WebCoso::Config->get_collections();
my @collections=$collections->get_all_collections();
is(scalar @resources,1,'una risorsa');
is(scalar @collections,2,'due collezioni');
is_deeply(
[sort $resources[0]->get_collections()],
[sort $collections[0],$collections[1]],
'aggancio r->c');
is_deeply(
[$collections[0]->get_resources()],
[$resources[0]],
'aggancio c->r');
is_deeply(
[$collections[1]->get_resources()],
[$resources[0]],
'aggancio c->r');
}
WebCoso::Config->clear();
{
my $conf_file=<<'EOF';
res('src/file1.rest.txt','NoSuchPipeline','dst/file.html');
EOF
throws_ok {
WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test")
}
'WebCoso::X::ConfigError',
'muore se la pipeline è ignota';
}