View | Details | Raw Unified | Return to bug 34825
Collapse All | Expand All

(-)a/t/Letters.t (-36 / +41 lines)
Lines 1-5 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright Koha development team 2007
4
#
3
# This file is part of Koha.
5
# This file is part of Koha.
4
#
6
#
5
# Koha is free software; you can redistribute it and/or modify it
7
# Koha is free software; you can redistribute it and/or modify it
Lines 18-66 Link Here
18
use Modern::Perl;
20
use Modern::Perl;
19
21
20
use Test::MockModule;
22
use Test::MockModule;
21
use Test::More;
23
use Test::More tests => 3;
22
24
23
use Module::Load::Conditional qw/check_install/;
25
use t::lib::Mocks;
26
use t::lib::TestBuilder;
24
27
25
BEGIN {
28
use Koha::Database;
26
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
27
        plan tests => 6;
28
    } else {
29
        plan skip_all => "Need Test::DBIx::Class"
30
    }
31
}
32
29
33
use Test::DBIx::Class;
30
use_ok('C4::Letters', qw( GetLetters ));
34
use t::lib::Mocks;
35
31
36
fixtures_ok [
32
my $schema  = Koha::Database->new->schema;
37
    Letter => [
33
$schema->storage->txn_begin;
38
        [ 'module', 'code', 'branchcode', 'name', 'is_html', 'title', 'content', 'lang' ],
34
our $builder = t::lib::TestBuilder->new;
39
        [ 'blah',   'ISBN', 'NBSI',       'book', 1,         'green', 'blahblah', 'french' ],
40
        [ 'bleh',   'ISSN', 'NSSI',       'page', 0,         'blue',  'blehbleh', 'american' ]
41
    ],
42
], 'add fixtures';
43
35
44
my $db = Test::MockModule->new('Koha::Database');
36
subtest 'GetLetters' => sub {
45
$db->mock( _new_schema => sub { return Schema(); } );
37
    plan tests => 2;
38
    t::lib::Mocks::mock_preference( 'dateformat', 'metric' );
46
39
47
use_ok('C4::Letters', qw( GetLetters ));
40
    my $data_1 = {
41
        module  => 'blah',     code => 'ISBN', branchcode => 'NBSI', name => 'book', is_html => 1, title => 'green',
42
        content => 'blahblah', lang => 'french'
43
    };
44
    my $data_2 = {
45
        module  => 'blah',   code => 'ISSN', branchcode => 'NSSI', name => 'page', is_html => 0, title => 'blue',
46
        content => 'bleble', lang => 'american'
47
    };
48
    $builder->build_object( { class => 'Koha::Notice::Templates', value => $data_1 } );
49
    $builder->build_object( { class => 'Koha::Notice::Templates', value => $data_2 } );
48
50
49
t::lib::Mocks::mock_preference('dateformat', 'metric');
51
    my $letters = GetLetters( { module => 'blah' } );
52
    is( scalar(@$letters), 2, 'GetLetters returns the 2 inserted letters' );
50
53
51
my $letters = C4::Letters::GetLetters();
54
    my ($ISBN_letter) = grep { $_->{code} eq 'ISBN' } @$letters;
55
    is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
56
};
52
57
53
my ( $ISBN_letter ) = grep {$_->{code} eq 'ISBN'} @$letters;
58
subtest '_parseletter' => sub {
54
is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
59
    plan tests => 2;
55
is( scalar( @$letters ), 2, 'GetLetters returns the 2 inserted letters' );
56
60
57
# Regression test for bug 10843
61
    # Regression test for bug 10843
58
# $dt->add takes a scalar, not undef
62
    # $dt->add takes a scalar, not undef
59
my $letter;
63
    my $letter;
60
t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', undef);
64
    t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', undef );
61
$letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
65
    $letter = C4::Letters::_parseletter( undef, 'reserves', { waitingdate => "2013-01-01" } );
62
is( ref($letter), 'HASH');
66
    is( ref($letter), 'HASH' );
63
t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 1);
67
    t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 1 );
64
$letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
68
    $letter = C4::Letters::_parseletter( undef, 'reserves', { waitingdate => "2013-01-01" } );
65
is( ref($letter), 'HASH');
69
    is( ref($letter), 'HASH' );
70
};
66
71
67
- 
72
$schema->storage->txn_begin;

Return to bug 34825