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

(-)a/C4/Installer/PerlDependencies.pm (+5 lines)
Lines 652-657 our $PERL_DEPS = { Link Here
652
        'required' => '0',
652
        'required' => '0',
653
        'min_ver'  => '2.07',
653
        'min_ver'  => '2.07',
654
    },
654
    },
655
    'File::Fu::File' => {
656
        'usage'    => 'Core',
657
        'required' => '1',
658
        'min_ver'  => '0.08',
659
    },
655
    'Archive::Extract' => {
660
    'Archive::Extract' => {
656
        'usage'    => 'Plugins',
661
        'usage'    => 'Plugins',
657
        'required' => '0',
662
        'required' => '0',
(-)a/t/lib/TestObjects/Acquisition/Bookseller/ContactFactory.pm (+3 lines)
Lines 38-43 sub new { Link Here
38
sub getDefaultHashKey {
38
sub getDefaultHashKey {
39
    return 'name';
39
    return 'name';
40
}
40
}
41
sub getObjectType {
42
    return 'Koha::Acquisition::Bookseller::Contact';
43
}
41
44
42
=head createTestGroup( $data [, $hashKey, $testContexts...] )
45
=head createTestGroup( $data [, $hashKey, $testContexts...] )
43
@OVERLOADED
46
@OVERLOADED
(-)a/t/lib/TestObjects/Acquisition/BooksellerFactory.pm (+3 lines)
Lines 38-43 sub new { Link Here
38
sub getDefaultHashKey {
38
sub getDefaultHashKey {
39
    return 'name';
39
    return 'name';
40
}
40
}
41
sub getObjectType {
42
    return 'Koha::Acquisition::Bookseller2';
43
}
41
44
42
=head createTestGroup( $data [, $hashKey, $testContexts...] )
45
=head createTestGroup( $data [, $hashKey, $testContexts...] )
43
@OVERLOADED
46
@OVERLOADED
(-)a/t/lib/TestObjects/BiblioFactory.pm (-3 / +21 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use C4::Biblio;
24
use C4::Biblio;
25
use Koha::Database;
25
26
26
use Koha::Exception::BadParameter;
27
use Koha::Exception::BadParameter;
27
28
Lines 30-35 use base qw(t::lib::TestObjects::ObjectFactory); Link Here
30
sub getDefaultHashKey {
31
sub getDefaultHashKey {
31
    return 'biblioitems.isbn';
32
    return 'biblioitems.isbn';
32
}
33
}
34
sub getObjectType {
35
    return 'MARC::Record';
36
}
33
37
34
=head t::lib::TestObjects::createTestGroup
38
=head t::lib::TestObjects::createTestGroup
35
39
Lines 50-55 The biblionumber is injected to the MARC::Record-object to be easily accessable, Link Here
50
so we can get it like this:
54
so we can get it like this:
51
    $records->{$key}->{biblionumber};
55
    $records->{$key}->{biblionumber};
52
56
57
There is a duplication check to first look for Records with the same ISBN.
58
If a matching ISBN is found, then we use the existing Record instead of adding a new one.
59
53
See C4::Biblio::TransformKohaToMarc() for how the biblio- or biblioitem-tables'
60
See C4::Biblio::TransformKohaToMarc() for how the biblio- or biblioitem-tables'
54
columns need to be given.
61
columns need to be given.
55
62
Lines 61-74 See t::lib::TestObjects::ObjectFactory for more documentation Link Here
61
sub handleTestObject {
68
sub handleTestObject {
62
    my ($class, $object, $stashes) = @_;
69
    my ($class, $object, $stashes) = @_;
63
70
64
    my $record = C4::Biblio::TransformKohaToMarc($object);
71
    ##First see if the given Record already exists in the DB. For testing purposes we use the isbn as the UNIQUE identifier.
65
    my ($biblionumber, $biblioitemnumber) = C4::Biblio::AddBiblio($record,'');
72
    my $resultset = Koha::Database->new()->schema()->resultset('Biblioitem');
73
    my $existingBiblio = $resultset->search({isbn => $object->{"biblioitems.isbn"}})->next();
74
    my ($record, $biblionumber, $biblioitemnumber);
75
    unless ($existingBiblio) {
76
        $record = C4::Biblio::TransformKohaToMarc($object);
77
        ($biblionumber, $biblioitemnumber) = C4::Biblio::AddBiblio($record,'');
78
    }
79
    else {
80
        $record = C4::Biblio::GetMarcBiblio($existingBiblio->biblionumber->biblionumber); #Funny!
81
    }
66
82
67
    #Clone all the parameters of $object to $record
83
    #Clone all the parameters of $object to $record
68
    foreach my $key (keys(%$object)) {
84
    foreach my $key (keys(%$object)) {
69
        $record->{$key} = $object->{$key};
85
        $record->{$key} = $object->{$key};
70
    }
86
    }
71
    $record->{biblionumber} = $biblionumber;
87
    $record->{biblionumber} = $biblionumber || $existingBiblio->biblionumber->biblionumber;
72
88
73
    return $record;
89
    return $record;
74
}
90
}
Lines 109-114 sub validateAndPopulateDefaultValues { Link Here
109
    unless ($object->{'biblio.title'}) {
125
    unless ($object->{'biblio.title'}) {
110
        Koha::Exception::BadParameter->throw(error => __PACKAGE__."->createTestGroup():> 'biblio.title' is a mandatory parameter!");
126
        Koha::Exception::BadParameter->throw(error => __PACKAGE__."->createTestGroup():> 'biblio.title' is a mandatory parameter!");
111
    }
127
    }
128
    $object->{'biblioitems.isbn'} = '971-972-call-me' unless $object->{'biblioitems.isbn'};
129
112
    $self->SUPER::validateAndPopulateDefaultValues($object, $hashKey);
130
    $self->SUPER::validateAndPopulateDefaultValues($object, $hashKey);
113
}
131
}
114
132
(-)a/t/lib/TestObjects/BorrowerFactory.pm (-15 / +29 lines)
Lines 21-26 package t::lib::TestObjects::BorrowerFactory; Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
use Carp;
22
use Carp;
23
use Scalar::Util qw(blessed);
23
use Scalar::Util qw(blessed);
24
use Encode;
24
25
25
use C4::Members;
26
use C4::Members;
26
use Koha::Borrowers;
27
use Koha::Borrowers;
Lines 38-43 sub new { Link Here
38
sub getDefaultHashKey {
39
sub getDefaultHashKey {
39
    return 'cardnumber';
40
    return 'cardnumber';
40
}
41
}
42
sub getObjectType {
43
    return 'Koha::Borrower';
44
}
41
45
42
=head createTestGroup( $data [, $hashKey, $testContexts...] )
46
=head createTestGroup( $data [, $hashKey, $testContexts...] )
43
@OVERLOADED
47
@OVERLOADED
Lines 79-104 See t::lib::TestObjects::ObjectFactory for more documentation Link Here
79
sub handleTestObject {
83
sub handleTestObject {
80
    my ($class, $object, $stashes) = @_;
84
    my ($class, $object, $stashes) = @_;
81
85
82
    #Try to add the Borrower, but it might fail because of the barcode or other UNIQUE constraint.
86
    my $borrower;
83
    #Catch the error and try looking for the Borrower if we suspect it is present in the DB.
84
    my $borrowernumber;
85
    eval {
87
    eval {
86
        $borrowernumber = C4::Members::AddMember(%$object);
88
        $borrower = Koha::Borrowers->cast($object); #Try getting the borrower first
87
    };
89
    };
88
    if ($@) {
90
89
        if (blessed($@) && $@->isa('DBIx::Class::Exception') &&
91
    my $borrowernumber;
90
            $@->{msg} =~ /Duplicate entry '.+?' for key 'cardnumber'/) { #DBIx should throw other types of exceptions instead of this general type :(
92
    unless ($borrower) {
91
            #This exception type is OK, we ignore this and try fetching the existing Object next.
93
        #Try to add the Borrower, but it might fail because of the barcode or other UNIQUE constraint.
92
            warn "Recovering from duplicate exception.\n";
94
        #Catch the error and try looking for the Borrower if we suspect it is present in the DB.
93
        }
95
        eval {
94
        else {
96
            $borrowernumber = C4::Members::AddMember(%$object);
95
            die $@;
97
        };
98
        if ($@) {
99
            if (blessed($@) && $@->isa('DBIx::Class::Exception') &&
100
                $@->{msg} =~ /Duplicate entry '.+?' for key 'cardnumber'/) { #DBIx should throw other types of exceptions instead of this general type :(
101
                #This exception type is OK, we ignore this and try fetching the existing Object next.
102
                warn "Recovering from duplicate exception.\n";
103
            }
104
            else {
105
                die $@;
106
            }
96
        }
107
        }
108
        #If adding failed, we still get some strange borrowernumber result.
109
        #Check for sure by finding the real borrower.
110
        $borrower = Koha::Borrowers->cast( $borrowernumber || $object );
97
    }
111
    }
98
112
99
    #If adding failed, we still get some strange borrowernumber result.
100
    #Check for sure by finding the real borrower.
101
    my $borrower = Koha::Borrowers->cast( $borrowernumber || $object );
102
    unless ($borrower) {
113
    unless ($borrower) {
103
        carp "BorrowerFactory:> No borrower for cardnumber '".$object->{cardnumber}."'";
114
        carp "BorrowerFactory:> No borrower for cardnumber '".$object->{cardnumber}."'";
104
        return();
115
        return();
Lines 118-123 sub validateAndPopulateDefaultValues { Link Here
118
    my ($self, $borrower, $hashKey) = @_;
129
    my ($self, $borrower, $hashKey) = @_;
119
    $self->SUPER::validateAndPopulateDefaultValues($borrower, $hashKey);
130
    $self->SUPER::validateAndPopulateDefaultValues($borrower, $hashKey);
120
131
132
    $borrower->{firstname} = 'Maija' unless $borrower->{firstname};
133
    $borrower->{surname} = Encode::decode('UTF-8', 'Meikäläinen') unless $borrower->{surname};
134
    $borrower->{cardnumber} = '167A000001TEST' unless $borrower->{cardnumber};
121
    $borrower->{categorycode} = 'PT' unless $borrower->{categorycode};
135
    $borrower->{categorycode} = 'PT' unless $borrower->{categorycode};
122
    $borrower->{branchcode}   = 'CPL' unless $borrower->{branchcode};
136
    $borrower->{branchcode}   = 'CPL' unless $borrower->{branchcode};
123
    $borrower->{dateofbirth}  = '1985-10-12' unless $borrower->{dateofbirth};
137
    $borrower->{dateofbirth}  = '1985-10-12' unless $borrower->{dateofbirth};
(-)a/t/lib/TestObjects/CheckoutFactory.pm (-12 / +26 lines)
Lines 27-32 use C4::Members; Link Here
27
use C4::Items;
27
use C4::Items;
28
use Koha::Borrowers;
28
use Koha::Borrowers;
29
use Koha::Items;
29
use Koha::Items;
30
use Koha::Checkouts;
31
32
use t::lib::TestObjects::BorrowerFactory;
33
use t::lib::TestObjects::ItemFactory;
30
34
31
use base qw(t::lib::TestObjects::ObjectFactory);
35
use base qw(t::lib::TestObjects::ObjectFactory);
32
36
Lines 41-46 sub new { Link Here
41
sub getDefaultHashKey {
45
sub getDefaultHashKey {
42
    return ['cardnumber', 'barcode'];
46
    return ['cardnumber', 'barcode'];
43
}
47
}
48
sub getObjectType {
49
    return 'Koha::Checkout';
50
}
44
51
45
=head t::lib::TestObjects::CheckoutFactory::createTestGroup( $data [, $hashKey], @stashes )
52
=head t::lib::TestObjects::CheckoutFactory::createTestGroup( $data [, $hashKey], @stashes )
46
53
Lines 75-89 sub getDefaultHashKey { Link Here
75
@PARAM4-6 HASHRef of test contexts. You can save the given objects to multiple
82
@PARAM4-6 HASHRef of test contexts. You can save the given objects to multiple
76
                test contexts. Usually one is enough. These test contexts are
83
                test contexts. Usually one is enough. These test contexts are
77
                used to help tear down DB changes.
84
                used to help tear down DB changes.
78
@RETURNS HASHRef of $hashKey => $checkout-objects.
85
@RETURNS HASHRef of $hashKey => Koha::Checkout-objects.
79
                The HASH is keyed with <cardnumber>-<barcode>, or the given $hashKey.
86
                The HASH is keyed with <cardnumber>-<barcode>, or the given $hashKey.
80
    Example: {
87
    Example: {
81
    '11A001-167N0212' => {
88
        '11A001-167N0212' => Koha::Checkout,
82
        cardnumber => <cardnumber>,
89
        ...
83
        barcode => <barcode>,
90
    }
84
        ...other Checkout-object columns...
85
    },
86
    ...
87
}
91
}
88
=cut
92
=cut
89
93
Lines 100-107 sub handleTestObject { Link Here
100
    }
104
    }
101
    my $oldContextBranch = C4::Context->userenv()->{branch};
105
    my $oldContextBranch = C4::Context->userenv()->{branch};
102
106
103
    my $borrower = Koha::Borrowers->cast($checkoutParams->{cardnumber});
107
    my $borrower = Koha::Borrowers->find({cardnumber => $checkoutParams->{cardnumber}});
104
    my $item =     Koha::Items->cast($checkoutParams->{barcode});
108
    unless($borrower) {
109
        my $borrowers = t::lib::TestObjects::BorrowerFactory->createTestGroup(
110
                                {cardnumber => $checkoutParams->{cardnumber}},
111
                                undef, @$stashes);
112
        $borrower = $borrowers->{ $checkoutParams->{cardnumber} };
113
    }
114
115
    my $item =     Koha::Items->find({barcode => $checkoutParams->{barcode}});
116
    unless($item) {
117
        my $items = t::lib::TestObjects::ItemFactory->createTestGroup(
118
                                {barcode => $checkoutParams->{barcode}},
119
                                undef, @$stashes);
120
        $item = $items->{ $checkoutParams->{barcode} };
121
    }
105
122
106
    my $duedate = DateTime->now(time_zone => C4::Context->tz());
123
    my $duedate = DateTime->now(time_zone => C4::Context->tz());
107
    if ($checkoutParams->{daysOverdue}) {
124
    if ($checkoutParams->{daysOverdue}) {
Lines 155-166 sub validateAndPopulateDefaultValues { Link Here
155
    unless ($object->{cardnumber}) {
172
    unless ($object->{cardnumber}) {
156
        croak __PACKAGE__.":> Mandatory parameter 'cardnumber' missing.";
173
        croak __PACKAGE__.":> Mandatory parameter 'cardnumber' missing.";
157
    }
174
    }
158
    $object->{borrower} = Koha::Borrowers->cast($object->{cardnumber});
159
160
    unless ($object->{barcode}) {
175
    unless ($object->{barcode}) {
161
        croak __PACKAGE__.":> Mandatory parameter 'barcode' missing.";
176
        croak __PACKAGE__.":> Mandatory parameter 'barcode' missing.";
162
    }
177
    }
163
    $object->{item} = Koha::Items->cast($object->{barcode});
164
178
165
    if ($object->{checkoutBranchRule} && not($object->{checkoutBranchRule} =~ m/(homebranch)|(holdingbranch)/)) {
179
    if ($object->{checkoutBranchRule} && not($object->{checkoutBranchRule} =~ m/(homebranch)|(holdingbranch)/)) {
166
        croak __PACKAGE__.":> Optional parameter 'checkoutBranchRule' must be one of these: homebranch, holdingbranch";
180
        croak __PACKAGE__.":> Optional parameter 'checkoutBranchRule' must be one of these: homebranch, holdingbranch";
(-)a/t/lib/TestObjects/FileFactory.pm (+118 lines)
Line 0 Link Here
1
package t::lib::TestObjects::FileFactory;
2
3
# Copyright Vaara-kirjastot 2015
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
#
20
21
use Modern::Perl;
22
use Carp;
23
use File::Spec;
24
use File::Path;
25
26
use Koha::AtomicUpdater;
27
use Koha::Database;
28
use File::Fu::File;
29
30
use Koha::Exception::BadParameter;
31
32
use base qw(t::lib::TestObjects::ObjectFactory);
33
34
my $tmpdir = File::Spec->tmpdir();
35
36
sub getDefaultHashKey {
37
    return 'OVERLOADED';
38
}
39
sub getObjectType {
40
    return 'File::Fu::File';
41
}
42
43
=head t::lib::TestObjects::createTestGroup
44
45
    my $files = t::lib::TestObjects::FileFactory->createTestGroup([
46
                    {'filepath' => 'atomicupdate/', #this is prepended with the system's default tmp directory, usually /tmp/
47
                     'filename' => '#30-RabiesIsMyDog.pl',
48
                     'content' => 'print "Mermaids are my only love\nI never let them down";',
49
                    },
50
                ], ['filepath', 'filename'], $testContext1, $testContext2, $testContext3);
51
52
Calls Koha::FileFactory to add files with content to your system, and clean up automatically.
53
54
The HASH is keyed with the 'filename', or the given $hashKeys.
55
56
@RETURNS HASHRef of File::Fu::File-objects
57
58
See t::lib::TestObjects::ObjectFactory for more documentation
59
=cut
60
61
sub handleTestObject {
62
    my ($class, $object, $stashes) = @_;
63
64
    my $absolutePath = $tmpdir.'/'.$object->{filepath};
65
    File::Path::make_path($absolutePath);
66
    my $file = File::Fu::File->new($absolutePath.'/'.$object->{filename});
67
68
    $file->write($object->{content}) if $object->{content};
69
70
    return $file;
71
}
72
73
=head validateAndPopulateDefaultValues
74
@OVERLOAD
75
76
Validates given Object parameters and makes sure that critical fields are given
77
and populates defaults for missing values.
78
=cut
79
80
sub validateAndPopulateDefaultValues {
81
    my ($self, $object, $hashKey) = @_;
82
83
    foreach my $param (('filename', 'filepath')) {
84
        unless ($object->{$param}) {
85
            Koha::Exception::BadParameter->throw(
86
                error => __PACKAGE__."->validateAndPopulateDefaultValues():> parameter '$param' is mandatory.");
87
        }
88
        if ($object->{$param} =~ m/(\$|\.\.|~|\s)/) {
89
            Koha::Exception::BadParameter->throw(
90
                error => __PACKAGE__."->validateAndPopulateDefaultValues():> parameter '$param' as '".$object->{$param}."'.".
91
                         'Disallowed characters present  ..  ~  $ + whitespace');
92
        }
93
    }
94
}
95
96
sub deleteTestGroup {
97
    my ($class, $objects) = @_;
98
99
    while( my ($key, $object) = each %$objects) {
100
        $object->remove if $object->e;
101
        #We could as well remove the complete subfolder but I am too afraid to automate "rm -r" here
102
    }
103
}
104
105
=head getHashKey
106
@OVERLOADED
107
108
@RETURNS String, The test context/stash HASH key to differentiate this object
109
                 from all other such test objects.
110
=cut
111
112
sub getHashKey {
113
    my ($class, $fileObject, $primaryKey, $hashKeys) = @_;
114
115
    return $fileObject->get_file();
116
}
117
118
1;
(-)a/t/lib/TestObjects/ItemFactory.pm (-2 / +28 lines)
Lines 22-30 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use C4::Items;
24
use C4::Items;
25
use Koha::Biblios;
25
use Koha::Items;
26
use Koha::Items;
26
use Koha::Checkouts;
27
use Koha::Checkouts;
27
28
29
use t::lib::TestObjects::BiblioFactory;
30
28
use base qw(t::lib::TestObjects::ObjectFactory);
31
use base qw(t::lib::TestObjects::ObjectFactory);
29
32
30
sub new {
33
sub new {
Lines 38-43 sub new { Link Here
38
sub getDefaultHashKey {
41
sub getDefaultHashKey {
39
    return 'barcode';
42
    return 'barcode';
40
}
43
}
44
sub getObjectType {
45
    return 'Koha::Item';
46
}
41
47
42
=head t::lib::TestObjects::ItemFactory::createTestGroup( $data [, $hashKey] )
48
=head t::lib::TestObjects::ItemFactory::createTestGroup( $data [, $hashKey] )
43
@OVERLOADED
49
@OVERLOADED
Lines 56-64 See t::lib::TestObjects::ObjectFactory for more documentation Link Here
56
sub handleTestObject {
62
sub handleTestObject {
57
    my ($class, $object, $stashes) = @_;
63
    my ($class, $object, $stashes) = @_;
58
64
65
    #Look for the parent biblio, if we don't find one, create a default one.
59
    my ($biblionumber, $biblioitemnumber, $itemnumber);
66
    my ($biblionumber, $biblioitemnumber, $itemnumber);
67
    my $biblio;
68
    $biblio = Koha::Biblios->find({biblionumber => $object->{biblionumber}}) if $object->{biblionumber};
69
    unless ($biblio) {
70
        my $biblios = t::lib::TestObjects::BiblioFactory->createTestGroup({"biblio.title" => "Test Items' Biblio",},
71
                                                                          undef, @$stashes);
72
        $biblio = $biblios->{'971-972-call-me'};
73
        $object->{biblionumber} = $biblio->{biblionumber};
74
    }
75
    else {
76
        $object->{biblionumber} = $biblio->biblionumber;
77
    }
78
79
    #Ok we got a biblio, now we can add an Item for it. First see if the Item already exists.
80
    my $item;
60
    eval {
81
    eval {
61
        ($biblionumber, $biblioitemnumber, $itemnumber) = C4::Items::AddItem($object, $object->{biblionumber});
82
        eval {
83
            $item = Koha::Items->cast($object);
84
        };
85
        unless ($item) {
86
            ($biblionumber, $biblioitemnumber, $itemnumber) = C4::Items::AddItem($object, $object->{biblionumber});
87
        }
62
    };
88
    };
63
    if ($@) {
89
    if ($@) {
64
        if (blessed($@) && $@->isa('DBIx::Class::Exception') &&
90
        if (blessed($@) && $@->isa('DBIx::Class::Exception') &&
Lines 70-76 sub handleTestObject { Link Here
70
            die $@;
96
            die $@;
71
        }
97
        }
72
    }
98
    }
73
    my $item = Koha::Items->cast($itemnumber || $object);
99
    $item = Koha::Items->cast($itemnumber || $object) unless $item;
74
    unless ($item) {
100
    unless ($item) {
75
        carp "ItemFactory:> No item for barcode '".$object->{barcode}."'";
101
        carp "ItemFactory:> No item for barcode '".$object->{barcode}."'";
76
        next();
102
        next();
(-)a/t/lib/TestObjects/LetterTemplateFactory.pm (+3 lines)
Lines 37-42 sub new { Link Here
37
sub getDefaultHashKey {
37
sub getDefaultHashKey {
38
    return ['module', 'code', 'branchcode', 'message_transport_type'];
38
    return ['module', 'code', 'branchcode', 'message_transport_type'];
39
}
39
}
40
sub getObjectType {
41
    return 'Koha::LetterTemplate';
42
}
40
43
41
=head t::lib::TestObjects::LetterTemplateFactory->createTestGroup
44
=head t::lib::TestObjects::LetterTemplateFactory->createTestGroup
42
Returns a HASH of Koha::LetterTemplate-objects
45
Returns a HASH of Koha::LetterTemplate-objects
(-)a/t/lib/TestObjects/ObjectFactory.pm (-7 / +89 lines)
Lines 79-85 sub createTestGroup { Link Here
79
79
80
        my $addedObject = $class->handleTestObject($o, $stashes);
80
        my $addedObject = $class->handleTestObject($o, $stashes);
81
        if (not($addedObject) ||
81
        if (not($addedObject) ||
82
            not(ref($addedObject) eq 'HASH' || $addedObject->isa('Koha::Object') || $addedObject->isa('MARC::Record') )
82
            (blessed($addedObject) && not($addedObject->isa($class->getObjectType()))) ||
83
            not(ref($addedObject) eq $class->getObjectType() )
83
           ) {
84
           ) {
84
            Koha::Exception::UnknownObject->throw(error => __PACKAGE__."->createTestGroup():> Subroutine '$class->handleTestObject()' must return a HASH or a Koha::Object");
85
            Koha::Exception::UnknownObject->throw(error => __PACKAGE__."->createTestGroup():> Subroutine '$class->handleTestObject()' must return a HASH or a Koha::Object");
85
        }
86
        }
Lines 130-135 sub tearDownTestContext { Link Here
130
    my ($self, $stash) = @_;
131
    my ($self, $stash) = @_;
131
132
132
    ##You should introduce tearDowns in such an order that to not provoke FOREIGN KEY issues.
133
    ##You should introduce tearDowns in such an order that to not provoke FOREIGN KEY issues.
134
    if ($stash->{'file'}) {
135
        require t::lib::TestObjects::FileFactory;
136
        t::lib::TestObjects::FileFactory->deleteTestGroup($stash->{'file'});
137
        delete $stash->{'file'};
138
    }
133
    if ($stash->{'serial-subscription'}) {
139
    if ($stash->{'serial-subscription'}) {
134
        require t::lib::TestObjects::Serial::SubscriptionFactory;
140
        require t::lib::TestObjects::Serial::SubscriptionFactory;
135
        t::lib::TestObjects::Serial::SubscriptionFactory->deleteTestGroup($stash->{'serial-subscription'});
141
        t::lib::TestObjects::Serial::SubscriptionFactory->deleteTestGroup($stash->{'serial-subscription'});
Lines 206-211 sub getHashKey { Link Here
206
    return join('-', @collectedHashKeys);
212
    return join('-', @collectedHashKeys);
207
}
213
}
208
214
215
=head
216
217
=cut
218
219
sub addToContext {
220
    my ($class, $objects, $hashKeys, $featureStash, $scenarioStash, $stepStash) = @_;
221
    my @stashes = ($featureStash, $scenarioStash, $stepStash);
222
223
    if (ref($objects) eq 'ARRAY') {
224
        foreach my $object (@$objects) {
225
            $class->addToContext($object, $hashKeys, @stashes);
226
        }
227
        return undef; #End recursion
228
    }
229
    elsif (ref($objects) eq 'HASH') {
230
        #Apparently we get a HASH of keyed objects.
231
        $class->_persistToStashes($objects, $class->getHashGroupName(), @stashes);
232
        return undef; #End recursion
233
    }
234
    else {
235
        #Here $objects is verified to be a single object, instead of a group of objects.
236
        #We create a hash key for it and append it to the stashes.
237
        my $hash = { $class->getHashKey($objects, undef, $class->getDefaultHashKey) => $objects};
238
        $class->_persistToStashes($hash, $class->getHashGroupName(), @stashes);
239
    }
240
}
241
209
=head validateAndPopulateDefaultValues
242
=head validateAndPopulateDefaultValues
210
@INTERFACE
243
@INTERFACE
211
244
Lines 225-230 sub validateAndPopulateDefaultValues { Link Here
225
    }
258
    }
226
}
259
}
227
260
261
=head validateObjectType
262
263
    try {
264
        $object = $class->validateObjectType($object);
265
    } catch {
266
        ...
267
    }
268
269
Validates if the given Object matches the expected type of the subclassing TestObjectFactory.
270
@PARAM1 Object that needs to be validated.
271
@THROWS Koha::Exception::UnknownObject, if the given object is not of the same type that the object factory creates.
272
273
=cut
274
275
sub validateObjectType {
276
    my ($class, $object) = @_;
277
278
    my $invalid = 0;
279
    if (blessed($object)) {
280
        unless ($object->isa( $class->getObjectType() )) {
281
            $invalid = 1;
282
        }
283
    }
284
    else {
285
        unless (ref($object) eq $class->getObjectType()) {
286
            $invalid = 1;
287
        }
288
    }
289
290
    Koha::Exception::UnknownObject->throw(
291
        error => "$class->validateObjectType():> Given object '$object' isn't a '".$class->getObjectType()."'-object."
292
    ) if $invalid;
293
294
    return $object;
295
}
296
297
=head getObjectType
298
@OVERLOAD
299
Get the type of objects this factory creates.
300
@RETURN String, the object package this factory creates. eg. Koha::Borrower
301
=cut
302
303
sub getObjectType {
304
    my ($class) = @_;
305
    die "You must overload 'validateObjectType()' in the implementing ObjectFactory subclass '$class'.";
306
    return 'Koha::Object derivative or other Object';
307
}
308
228
=head _validateStashes
309
=head _validateStashes
229
310
230
    _validateStashes($featureStash, $scenarioStash, $stepStash);
311
    _validateStashes($featureStash, $scenarioStash, $stepStash);
Lines 255-269 Saves the given HASH to the given stashes using the given stash key. Link Here
255
=cut
336
=cut
256
337
257
sub _persistToStashes {
338
sub _persistToStashes {
258
    my ($self, $objects, $stashKey, $featureStash, $scenarioStash, $stepStash) = @_;
339
    my ($class, $objects, $stashKey, $featureStash, $scenarioStash, $stepStash) = @_;
259
340
260
    if ($featureStash || $scenarioStash || $stepStash) {
341
    if ($featureStash || $scenarioStash || $stepStash) {
261
        while( my ($key, $biblio) = each %$objects) {
342
        while( my ($key, $object) = each %$objects) {
262
            $featureStash->{$stashKey}->{ $key }  = $biblio if $featureStash;
343
            $class->validateObjectType($object); #Make sure we put in what we are expected to
263
            $scenarioStash->{$stashKey}->{ $key } = $biblio if $scenarioStash;
344
            $featureStash->{$stashKey}->{ $key }  = $object if $featureStash;
264
            $stepStash->{$stashKey}->{ $key }     = $biblio if $stepStash;
345
            $scenarioStash->{$stashKey}->{ $key } = $object if $scenarioStash;
346
            $stepStash->{$stashKey}->{ $key }     = $object if $stepStash;
265
        }
347
        }
266
    }
348
    }
267
}
349
}
268
350
269
1;
351
1;
(-)a/t/lib/TestObjects/Serial/FrequencyFactory.pm (+3 lines)
Lines 38-43 sub new { Link Here
38
sub getDefaultHashKey {
38
sub getDefaultHashKey {
39
    return 'description';
39
    return 'description';
40
}
40
}
41
sub getObjectType {
42
    return 'Koha::Serial::Subscription::Frequency';
43
}
41
44
42
=head createTestGroup( $data [, $hashKey, $testContexts...] )
45
=head createTestGroup( $data [, $hashKey, $testContexts...] )
43
@OVERLOADED
46
@OVERLOADED
(-)a/t/lib/TestObjects/Serial/SubscriptionFactory.pm (-7 / +16 lines)
Lines 21-27 package t::lib::TestObjects::Serial::SubscriptionFactory; Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
use Carp;
22
use Carp;
23
use Scalar::Util qw(blessed);
23
use Scalar::Util qw(blessed);
24
use DateTime;
24
25
26
use C4::Context;
25
use C4::Serials;
27
use C4::Serials;
26
28
27
use t::lib::TestObjects::BorrowerFactory;
29
use t::lib::TestObjects::BorrowerFactory;
Lines 40-45 use base qw(t::lib::TestObjects::ObjectFactory); Link Here
40
sub getDefaultHashKey {
42
sub getDefaultHashKey {
41
    return 'internalnotes';
43
    return 'internalnotes';
42
}
44
}
45
sub getObjectType {
46
    return 'Koha::Serial::Subscription';
47
}
43
48
44
=head createTestGroup( $data [, $hashKey, $testContexts...] )
49
=head createTestGroup( $data [, $hashKey, $testContexts...] )
45
50
Lines 54-60 sub getDefaultHashKey { Link Here
54
                aqbudgetid => undef, #DEFAULT
59
                aqbudgetid => undef, #DEFAULT
55
                biblio => 21 || Koha::Biblio, #DEFAULT creates a "Serial magazine" Record
60
                biblio => 21 || Koha::Biblio, #DEFAULT creates a "Serial magazine" Record
56
                startdate => '2015-01-01', #DEFAULTs to 1.1 this year, so the subscription is active by default.
61
                startdate => '2015-01-01', #DEFAULTs to 1.1 this year, so the subscription is active by default.
57
                periodicity => 7 || Koha::Serial::Subscription::Frequency, #DEFAULTS to a Frequency of 1/month.
62
                periodicity => 2 || Koha::Serial::Subscription::Frequency, #DEFAULTS to a Frequency of 1/week.
58
                numberlength => 12, #DEFAULT one year subscription, only one of ['numberlength', 'weeklength', 'monthlength'] is needed
63
                numberlength => 12, #DEFAULT one year subscription, only one of ['numberlength', 'weeklength', 'monthlength'] is needed
59
                weeklength => 52, #DEFAULT one year subscription
64
                weeklength => 52, #DEFAULT one year subscription
60
                monthlength => 12, #DEFAULT one year subscription
65
                monthlength => 12, #DEFAULT one year subscription
Lines 170-175 and populates defaults for missing values. Link Here
170
sub validateAndPopulateDefaultValues {
175
sub validateAndPopulateDefaultValues {
171
    my ($self, $object, $hashKey, $stashes) = @_;
176
    my ($self, $object, $hashKey, $stashes) = @_;
172
177
178
    #Get this year so we can use it to populate always active Objects.
179
    my $now = DateTime->now(time_zone => C4::Context->tz());
180
    my $year = $now->year();
181
173
    if ($object->{librarian}) {
182
    if ($object->{librarian}) {
174
        $object->{librarian} = Koha::Borrowers->cast($object->{librarian});
183
        $object->{librarian} = Koha::Borrowers->cast($object->{librarian});
175
    }
184
    }
Lines 195-221 sub validateAndPopulateDefaultValues { Link Here
195
        $object->{biblio} = t::lib::TestObjects::BiblioFactory->createTestGroup([
204
        $object->{biblio} = t::lib::TestObjects::BiblioFactory->createTestGroup([
196
                                    {'biblio.title' => 'Serial magazine',
205
                                    {'biblio.title' => 'Serial magazine',
197
                                     'biblio.author'   => 'Pertti Kurikka',
206
                                     'biblio.author'   => 'Pertti Kurikka',
198
                                     'biblio.copyrightdate' => '2015',
207
                                     'biblio.copyrightdate' => $year,
199
                                     'biblioitems.isbn'     => 'isbnisnotsocoolnowadays!',
208
                                     'biblioitems.isbn'     => 'isbnisnotsocoolnowadays!',
200
                                     'biblioitems.itemtype' => 'CR',
209
                                     'biblioitems.itemtype' => 'CR',
201
                                    },
210
                                    },
202
                                ], undef, @$stashes)
211
                                ], undef, @$stashes)
203
                                ->{'isbnisnotsocoolnowadays!'};
212
                                ->{'isbnisnotsocoolnowadays!'};
204
    }
213
    }
205
206
    unless ($object->{internalnotes}) {
214
    unless ($object->{internalnotes}) {
207
        croak __PACKAGE__.":> Mandatory parameter 'internalnotes' missing. This is used as the returning hash-key!";
215
        croak __PACKAGE__.":> Mandatory parameter 'internalnotes' missing. This is used as the returning hash-key!";
208
    }
216
    }
209
    $object->{periodicity}   = 7 unless $object->{periodicity};
217
218
    $object->{periodicity}   = 4 unless $object->{periodicity};
210
    $object->{numberpattern} = 2 unless $object->{numberpattern};
219
    $object->{numberpattern} = 2 unless $object->{numberpattern};
211
    $object->{branchcode}    = 'CPL' unless $object->{branchcode};
220
    $object->{branchcode}    = 'CPL' unless $object->{branchcode};
212
    $object->{cost}          = undef unless $object->{cost};
221
    $object->{cost}          = undef unless $object->{cost};
213
    $object->{aqbudgetid}    = undef unless $object->{aqbudgetid};
222
    $object->{aqbudgetid}    = undef unless $object->{aqbudgetid};
214
    $object->{startdate}     = '2015-01-01' unless $object->{startdate};
223
    $object->{startdate}     = "$year-01-01" unless $object->{startdate};
215
    $object->{numberlength}  = undef unless $object->{numberlength};
224
    $object->{numberlength}  = undef unless $object->{numberlength};
216
    $object->{weeklength}    = undef unless $object->{weeklength} || $object->{numberlength};
225
    $object->{weeklength}    = undef unless $object->{weeklength} || $object->{numberlength};
217
    $object->{monthlength}   = 12 unless $object->{monthlength} || $object->{weeklength} || $object->{numberlength};
226
    $object->{monthlength}   = 12 unless $object->{monthlength} || $object->{weeklength} || $object->{numberlength};
218
    $object->{lastvalue1}    = 2015 unless $object->{lastvalue1};
227
    $object->{lastvalue1}    = $year unless $object->{lastvalue1};
219
    $object->{innerloop1}    = undef unless $object->{innerloop1};
228
    $object->{innerloop1}    = undef unless $object->{innerloop1};
220
    $object->{lastvalue2}    = 1 unless $object->{lastvalue2};
229
    $object->{lastvalue2}    = 1 unless $object->{lastvalue2};
221
    $object->{innerloop2}    = undef unless $object->{innerloop2};
230
    $object->{innerloop2}    = undef unless $object->{innerloop2};
Lines 224-230 sub validateAndPopulateDefaultValues { Link Here
224
    $object->{status}        = 1 unless $object->{status};
233
    $object->{status}        = 1 unless $object->{status};
225
    $object->{notes}         = 'Public note' unless $object->{notes};
234
    $object->{notes}         = 'Public note' unless $object->{notes};
226
    $object->{letter}        = 'RLIST' unless $object->{letter};
235
    $object->{letter}        = 'RLIST' unless $object->{letter};
227
    $object->{firstacquidate} = '2015-01-01' unless $object->{firstacquidate};
236
    $object->{firstacquidate} = "$year-01-01" unless $object->{firstacquidate};
228
    $object->{irregularity}  = undef unless $object->{irregularity};
237
    $object->{irregularity}  = undef unless $object->{irregularity};
229
    $object->{locale}        = undef unless $object->{locale};
238
    $object->{locale}        = undef unless $object->{locale};
230
    $object->{callnumber}    = 'MAG 10.2 AZ' unless $object->{callnumber};
239
    $object->{callnumber}    = 'MAG 10.2 AZ' unless $object->{callnumber};
(-)a/t/lib/TestObjects/SystemPreferenceFactory.pm (+3 lines)
Lines 40-45 sub new { Link Here
40
sub getDefaultHashKey {
40
sub getDefaultHashKey {
41
    return 'preference';
41
    return 'preference';
42
}
42
}
43
sub getObjectType {
44
    return 'HASH';
45
}
43
46
44
=head createTestGroup( $data [, $hashKey, $testContexts...] )
47
=head createTestGroup( $data [, $hashKey, $testContexts...] )
45
@OVERLOADED
48
@OVERLOADED
(-)a/t/lib/TestObjects/objectFactories.t (-14 / +82 lines)
Lines 40-45 use t::lib::TestObjects::Acquisition::Bookseller::ContactFactory; Link Here
40
use Koha::Acquisition::Bookseller::Contacts;
40
use Koha::Acquisition::Bookseller::Contacts;
41
use t::lib::TestObjects::Acquisition::BooksellerFactory;
41
use t::lib::TestObjects::Acquisition::BooksellerFactory;
42
use Koha::Acquisition::Booksellers;
42
use Koha::Acquisition::Booksellers;
43
use t::lib::TestObjects::FileFactory;
44
use File::Slurp;
45
use File::Fu::File;
43
use t::lib::TestObjects::Serial::SubscriptionFactory;
46
use t::lib::TestObjects::Serial::SubscriptionFactory;
44
use Koha::Serial::Subscriptions;
47
use Koha::Serial::Subscriptions;
45
use Koha::Serial::Subscription::Frequencies;
48
use Koha::Serial::Subscription::Frequencies;
Lines 53-76 my $testContext = {}; #Gather all created Objects here so we can finally remove Link Here
53
56
54
57
55
58
59
########## FileFactory subtests ##########
60
subtest 't::lib::TestObjects::FileFactory' => \&testFileFactory;
61
sub testFileFactory {
62
    my ($files);
63
    my $subtestContext = {};
64
65
    $files = t::lib::TestObjects::FileFactory->createTestGroup([
66
                        {'filepath' => 'atomicupdate',
67
                         'filename' => '#30-RabiesIsMyDog.pl',
68
                         'content' => 'print "Mermaids are my only love\nI never let them down";',
69
                        },
70
                        {'filepath' => 'atomicupdate',
71
                         'filename' => '#31-FrogsArePeopleToo.pl',
72
                         'content' => 'print "Listen to the Maker!";',
73
                        },
74
                        {'filepath' => 'atomicupdate',
75
                         'filename' => '#32-AnimalLover.pl',
76
                         'content' => "print 'Do not hurt them!;",
77
                        },
78
                    ], undef, $subtestContext);
79
80
    my $file30content = File::Slurp::read_file( $files->{'#30-RabiesIsMyDog.pl'}->absolutely );
81
    ok($file30content =~ m/Mermaids are my only love/,
82
       "'#30-RabiesIsMyDog.pl' created and content matches");
83
    my $file31content = File::Slurp::read_file( $files->{'#31-FrogsArePeopleToo.pl'}->absolutely );
84
    ok($file31content =~ m/Listen to the Maker!/,
85
       "'#31-FrogsArePeopleToo.pl' created and content matches");
86
    my $file32content = File::Slurp::read_file( $files->{'#32-AnimalLover.pl'}->absolutely );
87
    ok($file32content =~ m/Do not hurt them!/,
88
       "'#32-AnimalLover.pl' created and content matches");
89
90
    ##addToContext() test, create new file
91
    my $dir = $files->{'#32-AnimalLover.pl'}->dirname();
92
    my $file = File::Fu::File->new("$dir/addToContext.txt");
93
    $file->touch;
94
    t::lib::TestObjects::FileFactory->addToContext($file, undef, $subtestContext);
95
    ok($file->e,
96
       "'addToContext.txt' created");
97
98
    t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext);
99
100
    ok(not(-e $files->{'#30-RabiesIsMyDog.pl'}->absolutely),
101
       "'#30-RabiesIsMyDog.pl' deleted");
102
    ok(not(-e $files->{'#31-FrogsArePeopleToo.pl'}->absolutely),
103
       "'#31-FrogsArePeopleToo.pl' deleted");
104
    ok(not(-e $files->{'#32-AnimalLover.pl'}->absolutely),
105
       "'#32-AnimalLover.pl' deleted");
106
    ok(not(-e $file->absolutely),
107
       "'addToContext.txt' deleted");
108
};
109
110
111
56
########## Serial subtests ##########
112
########## Serial subtests ##########
57
subtest 't::lib::TestObjects::Serial' => sub {
113
subtest 't::lib::TestObjects::Serial' => \&testSerialFactory;
58
    my ($subscriptions, $subscription, $frequency, $numberpattern, $biblio, $borrower, $bookseller, $items, $serials);
114
sub testSerialFactory {
115
    my ($subscriptions, $subscription, $frequency, $numberpattern, $biblio, $sameBiblio, $borrower, $bookseller, $items, $serials);
59
    my $subtestContext = {};
116
    my $subtestContext = {};
60
    my $dontDeleteTestContext = {};
117
    my $dontDeleteTestContext = {};
61
    ##Create and delete
118
    ##Create and delete
62
    $subscriptions = t::lib::TestObjects::Serial::SubscriptionFactory->createTestGroup([
119
    $subscriptions = t::lib::TestObjects::Serial::SubscriptionFactory->createTestGroup([
63
                                {internalnotes => 'TESTDEFAULTS',
120
                                {internalnotes => 'TESTDEFAULTS',
64
                                 receiveSerials => 3},
121
                                 receiveSerials => 3},
122
                                {internalnotes => 'SAMEBIBLIO',},
65
                                ], undef, $subtestContext);
123
                                ], undef, $subtestContext);
66
    $subscription = Koha::Serial::Subscriptions->find( $subscriptions->{'TESTDEFAULTS'}->subscriptionid );
124
    $subscription = Koha::Serial::Subscriptions->find( $subscriptions->{'TESTDEFAULTS'}->subscriptionid );
67
    $frequency = $subscription->periodicity();
125
    $frequency = $subscription->periodicity();
68
    $numberpattern = $subscription->numberpattern();
126
    $numberpattern = $subscription->numberpattern();
69
    $biblio = $subscription->biblio();
127
    $biblio = $subscription->biblio();
128
    $sameBiblio = $subscriptions->{SAMEBIBLIO}->biblio;
70
    $borrower = $subscription->borrower();
129
    $borrower = $subscription->borrower();
71
    $bookseller = $subscription->bookseller();
130
    $bookseller = $subscription->bookseller();
72
    $items = $subscription->items();
131
    $items = $subscription->items();
73
    $serials = $subscription->serials();
132
    $serials = $subscription->serials();
133
    is($biblio->biblionumber,
134
       $sameBiblio->biblionumber,
135
       "Default Subscriptions use the same default Biblio");
74
    ok(($subscriptions->{'TESTDEFAULTS'}->callnumber eq $subscription->callnumber &&
136
    ok(($subscriptions->{'TESTDEFAULTS'}->callnumber eq $subscription->callnumber &&
75
        $subscriptions->{'TESTDEFAULTS'}->subscriptionid eq $subscription->subscriptionid),
137
        $subscriptions->{'TESTDEFAULTS'}->subscriptionid eq $subscription->subscriptionid),
76
       "Default Subscription created.");
138
       "Default Subscription created.");
Lines 163-169 subtest 't::lib::TestObjects::Serial' => sub { Link Here
163
225
164
226
165
########## Acquisition subtests ##########
227
########## Acquisition subtests ##########
166
subtest 't::lib::TestObjects::Acquisition' => sub {
228
subtest 't::lib::TestObjects::Acquisition' => \&testAcquisitionFactories;
229
sub testAcquisitionFactories {
167
    my ($booksellers, $bookseller, $contacts, $contact);
230
    my ($booksellers, $bookseller, $contacts, $contact);
168
    my $subtestContext = {};
231
    my $subtestContext = {};
169
    ##Create and delete
232
    ##Create and delete
Lines 198-204 subtest 't::lib::TestObjects::Acquisition' => sub { Link Here
198
261
199
262
200
########## BorrowerFactory subtests ##########
263
########## BorrowerFactory subtests ##########
201
subtest 't::lib::TestObjects::BorrowerFactory' => sub {
264
subtest 't::lib::TestObjects::BorrowerFactory' => \&testBorrowerFactory;
265
sub testBorrowerFactory {
202
    my $subtestContext = {};
266
    my $subtestContext = {};
203
    ##Create and Delete. Add one
267
    ##Create and Delete. Add one
204
    my $f = t::lib::TestObjects::BorrowerFactory->new();
268
    my $f = t::lib::TestObjects::BorrowerFactory->new();
Lines 223-232 subtest 't::lib::TestObjects::BorrowerFactory' => sub { Link Here
223
287
224
    ##Delete objects
288
    ##Delete objects
225
    t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext);
289
    t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext);
226
    my $object11A001 = Koha::Borrowers->find({cardnumber => '11A001'});
290
    foreach my $cn (('11A001', '11A002')) {
227
    ok (not($object11A001), "Borrower '11A001' deleted");
291
        ok (not(Koha::Borrowers->find({cardnumber => $cn})),
228
    my $object11A002 = Koha::Borrowers->find({cardnumber => '11A002'});
292
            "Borrower '11A001' deleted");
229
    ok (not($object11A002), "Borrower '11A002' deleted");
293
    }
230
294
231
    #Prepare for global autoremoval.
295
    #Prepare for global autoremoval.
232
    $objects = $f->createTestGroup([
296
    $objects = $f->createTestGroup([
Lines 246-252 subtest 't::lib::TestObjects::BorrowerFactory' => sub { Link Here
246
310
247
311
248
########## BiblioFactory and ItemFactory subtests ##########
312
########## BiblioFactory and ItemFactory subtests ##########
249
subtest 't::lib::TestObjects::BiblioFactory and ::ItemFactory' => sub {
313
subtest 't::lib::TestObjects::BiblioFactory and ::ItemFactory' => \&testBiblioItemFactories;
314
sub testBiblioItemFactories {
250
    my $subtestContext = {};
315
    my $subtestContext = {};
251
    ##Create and Delete. Add one
316
    ##Create and Delete. Add one
252
    my $biblios = t::lib::TestObjects::BiblioFactory->createTestGroup([
317
    my $biblios = t::lib::TestObjects::BiblioFactory->createTestGroup([
Lines 302-308 subtest 't::lib::TestObjects::BiblioFactory and ::ItemFactory' => sub { Link Here
302
367
303
368
304
########## CheckoutFactory subtests ##########
369
########## CheckoutFactory subtests ##########
305
subtest 't::lib::TestObjects::CheckoutFactory' => sub {
370
subtest 't::lib::TestObjects::CheckoutFactory' => \&testCheckoutFactory;
371
sub testCheckoutFactory {
306
    my $subtestContext = {};
372
    my $subtestContext = {};
307
    ##Create and Delete using dependencies in the $testContext instantiated in previous subtests.
373
    ##Create and Delete using dependencies in the $testContext instantiated in previous subtests.
308
    my $biblios = t::lib::TestObjects::BiblioFactory->createTestGroup([
374
    my $biblios = t::lib::TestObjects::BiblioFactory->createTestGroup([
Lines 376-382 subtest 't::lib::TestObjects::CheckoutFactory' => sub { Link Here
376
442
377
443
378
########## LetterTemplateFactory subtests ##########
444
########## LetterTemplateFactory subtests ##########
379
subtest 't::lib::TestObjects::LetterTemplateFactory' => sub {
445
subtest 't::lib::TestObjects::LetterTemplateFactory' => \&testLetterTemplateFactory;
446
sub testLetterTemplateFactory {
380
    my $subtestContext = {};
447
    my $subtestContext = {};
381
    ##Create and Delete using dependencies in the $testContext instantiated in previous subtests.
448
    ##Create and Delete using dependencies in the $testContext instantiated in previous subtests.
382
    my $f = t::lib::TestObjects::LetterTemplateFactory->new();
449
    my $f = t::lib::TestObjects::LetterTemplateFactory->new();
Lines 406-412 subtest 't::lib::TestObjects::LetterTemplateFactory' => sub { Link Here
406
473
407
474
408
########## SystemPreferenceFactory subtests ##########
475
########## SystemPreferenceFactory subtests ##########
409
subtest 't::lib::TestObjects::SystemPreferenceFactory' => sub {
476
subtest 't::lib::TestObjects::SystemPreferenceFactory' => \&testSystemPreferenceFactory;
477
sub testSystemPreferenceFactory {
410
    my $subtestContext = {};
478
    my $subtestContext = {};
411
479
412
    # take syspref 'opacuserlogin' and save its current value
480
    # take syspref 'opacuserlogin' and save its current value
Lines 443-449 subtest 't::lib::TestObjects::SystemPreferenceFactory' => sub { Link Here
443
511
444
512
445
########## Global test context subtests ##########
513
########## Global test context subtests ##########
446
subtest 't::lib::TestObjects::ObjectFactory clearing global test context' => sub {
514
subtest 't::lib::TestObjects::ObjectFactory clearing global test context' => \&testGlobalSubtestContext;
515
sub testGlobalSubtestContext {
447
    my $object11A001 = Koha::Borrowers->find({cardnumber => '11A001'});
516
    my $object11A001 = Koha::Borrowers->find({cardnumber => '11A001'});
448
    ok ($object11A001, "Global Borrower '11A001' exists");
517
    ok ($object11A001, "Global Borrower '11A001' exists");
449
    my $object11A002 = Koha::Borrowers->find({cardnumber => '11A002'});
518
    my $object11A002 = Koha::Borrowers->find({cardnumber => '11A002'});
450
- 

Return to bug 13906