]>
Commit | Line | Data |
---|---|---|
57e4a9c7 TC |
1 | #!perl -w |
2 | use strict; | |
3 | use BSE::Test qw(base_url); | |
4 | use File::Spec; | |
5 | use File::Temp; | |
6 | ||
7 | use Test::More tests => 5; | |
8 | ||
9 | BEGIN { | |
10 | unshift @INC, File::Spec->catdir(BSE::Test::base_dir(), "cgi-bin", "modules"); | |
11 | } | |
12 | ||
13 | use BSE::Importer; | |
14 | use BSE::API qw(bse_init bse_make_article); | |
15 | ||
16 | my $base_cgi = File::Spec->catdir(BSE::Test::base_dir(), "cgi-bin"); | |
17 | ok(bse_init($base_cgi), "initialize api") | |
18 | or print "# failed to bse_init in $base_cgi\n"; | |
19 | ||
20 | my $when = time; | |
21 | ||
22 | my $cfg = BSE::Cfg->new(path => $base_cgi, extra_text => <<CFG); | |
23 | [import profile simple$when] | |
24 | map_title=1 | |
25 | source=CSV | |
26 | target=Article | |
27 | ||
28 | [import profile simpleupdate$when] | |
29 | map_linkAlias=1 | |
30 | map_body=2 | |
31 | source=CSV | |
32 | target=Article | |
33 | update_only=1 | |
34 | sep_char=\\t | |
35 | CFG | |
36 | ||
37 | { | |
38 | my @added; | |
39 | ||
40 | my $imp = BSE::Importer->new(cfg => $cfg, profile => "simple$when", callback => sub { note @_ }); | |
41 | $imp->process("t/data/importer/article-simple.csv"); | |
42 | @added = sort { $a->title cmp $b->title } $imp->leaves; | |
43 | ||
44 | is(@added, 2, "imported two articles"); | |
45 | is($added[0]->title, "test1", "check title of first import"); | |
46 | is($added[1]->title, "test2", "check title of second import"); | |
47 | ||
48 | END { | |
49 | $_->remove($cfg) for @added; | |
50 | } | |
51 | } | |
52 | ||
53 | { | |
54 | my $testa = bse_make_article(cfg => $cfg, title => "test updates", | |
55 | linkAlias => "alias$when"); | |
56 | ||
57 | my $fh = File::Temp->new; | |
58 | my $filename = $fh->filename; | |
59 | print $fh <<EOS; | |
60 | linkAlias\tbody | |
61 | "alias$when"\t"This is the body text with multiple lines | |
62 | ||
63 | Yes, multiple lines with CSV!" | |
64 | EOS | |
65 | close $fh; | |
66 | my $imp = BSE::Importer->new(cfg => $cfg, profile => "simpleupdate$when", callback => sub { note @_ }); | |
67 | $imp->process($filename); | |
68 | my $testb = Articles->getByPkey($testa->id); | |
69 | like($testb->body, qr/This is the body/, "check the body is updated"); | |
70 | ||
71 | END { | |
72 | $testa->remove($cfg) if $testa; | |
73 | } | |
74 | } |