]> git.imager.perl.org - bse.git/blame - t/130-importer/020-article.t
implement (and basically test) update_only for import specs
[bse.git] / t / 130-importer / 020-article.t
CommitLineData
57e4a9c7
TC
1#!perl -w
2use strict;
3use BSE::Test qw(base_url);
4use File::Spec;
5use File::Temp;
6
7use Test::More tests => 5;
8
9BEGIN {
10 unshift @INC, File::Spec->catdir(BSE::Test::base_dir(), "cgi-bin", "modules");
11}
12
13use BSE::Importer;
14use BSE::API qw(bse_init bse_make_article);
15
16my $base_cgi = File::Spec->catdir(BSE::Test::base_dir(), "cgi-bin");
17ok(bse_init($base_cgi), "initialize api")
18 or print "# failed to bse_init in $base_cgi\n";
19
20my $when = time;
21
22my $cfg = BSE::Cfg->new(path => $base_cgi, extra_text => <<CFG);
23[import profile simple$when]
24map_title=1
25source=CSV
26target=Article
27
28[import profile simpleupdate$when]
29map_linkAlias=1
30map_body=2
31source=CSV
32target=Article
33update_only=1
34sep_char=\\t
35CFG
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;
60linkAlias\tbody
61"alias$when"\t"This is the body text with multiple lines
62
63Yes, multiple lines with CSV!"
64EOS
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}