aboutsummaryrefslogtreecommitdiff
path: root/t/01-config.t
blob: 78000a32db3bb4d53fd4a26230aa851b359bf748 (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/perl 
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');
 
# qui sto assumendo che le collezioni vengano registrate in ordine di 
# definizione. Forse non sarà sempre vero 
 
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');
 
}
 
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_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');
}