2 use Test::More tests => 8;
5 use C4::Letters qw( GetLetterTemplates );
9 my $schema = Koha::Database->new->schema;
10 $schema->storage->txn_begin;
11 my $dbh = C4::Context->dbh;
13 $dbh->do(q|DELETE FROM letter|);
17 module => 'circulation',
20 name => 'B default name for code1 circ',
22 title => 'default title for code1 email',
23 content => 'default content for code1 email',
24 message_transport_type => 'email',
28 module => 'circulation',
31 name => 'B default name for code1 circ',
33 title => 'default title for code1 sms',
34 content => 'default content for code1 sms',
35 message_transport_type => 'sms',
39 module => 'circulation',
42 name => 'A default name for code2 circ',
44 title => 'default title for code2 email',
45 content => 'default content for code2 email',
46 message_transport_type => 'email',
50 module => 'circulation',
53 name => 'C default name for code3 circ',
55 title => 'default title for code3 email',
56 content => 'default content for code3 email',
57 message_transport_type => 'email',
62 module => 'cataloguing',
65 name => 'default name for code1 cat',
67 title => 'default title for code1 cat email',
68 content => 'default content for code1 cat email',
69 message_transport_type => 'email',
74 module => 'circulation',
77 name => 'B CPL name for code1 circ',
79 title => 'CPL title for code1 email',
80 content => 'CPL content for code1 email',
81 message_transport_type => 'email',
85 module => 'circulation',
88 name => 'A CPL name for code1 circ',
90 title => 'CPL title for code1 sms',
91 content => 'CPL content for code1 sms',
92 message_transport_type => 'sms',
97 my $sth = $dbh->prepare(
98 q|INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type, lang) VALUES (?, ?, ?, ?, ?, ?, ?, ?)|
100 for my $l (@$letters) {
101 $sth->execute( $l->{module}, $l->{code}, $l->{branchcode}, $l->{name},
102 $l->{title}, $l->{content}, $l->{message_transport_type}, $l->{lang} );
105 t::lib::Mocks::mock_preference('TranslateNotices', 1);
106 my $letter_templates;
107 $letter_templates = C4::Letters::GetLetterTemplates;
108 is_deeply( $letter_templates, [],
109 'GetLetterTemplates should not return templates if not param is given' );
111 $letter_templates = C4::Letters::GetLetterTemplates(
112 { module => 'circulation', code => 'code1', branchcode => '' } );
113 is( scalar( @$letter_templates ),
114 2, '2 default templates should exist for circulation code1' );
115 my $has_email = grep { $_->{message_transport_type} eq 'email' } @$letter_templates;
116 is( $has_email, 1, 'The mtt email should exist for circulation code1' );
117 my $has_sms = grep { $_->{message_transport_type} eq 'sms' } @$letter_templates;
118 is( $has_sms, 1, 'The mtt sms should exist for circulation code1' );
120 $letter_templates = C4::Letters::GetLetterTemplates(
121 { module => 'circulation', code => 'code1', branchcode => 'CPL' } );
122 is( scalar( @$letter_templates ),
123 1, '1 template should exist for circulation CPL code1' );
124 $has_email = grep { $_->{message_transport_type} eq 'email' } @$letter_templates;
125 is( $has_email, 1, 'The mtt should be email for circulation CPL code1' );
127 $letter_templates = C4::Letters::GetLetterTemplates(
128 { module => 'circulation', code => 'code1' } );
129 is( scalar( @$letter_templates ),
130 2, '2 default templates should exist for circulation code1 (even if branchcode is not given)' );
132 t::lib::Mocks::mock_preference('TranslateNotices', 0);
133 $letter_templates = C4::Letters::GetLetterTemplates(
134 { module => 'circulation', code => 'code1' } );
135 is( scalar( @$letter_templates ),
136 1, 'There should exist only 1 template circulation code1 for default language' );