|
Line 0
Link Here
|
| 0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
use Test::More tests => 20; |
| 3 |
|
| 4 |
use C4::Circulation; |
| 5 |
use C4::Context; |
| 6 |
use C4::Record; |
| 7 |
|
| 8 |
my $dbh = C4::Context->dbh; |
| 9 |
$dbh->{AutoCommit} = 0; |
| 10 |
$dbh->{RaiseError} = 1; |
| 11 |
|
| 12 |
my $originalBranchTransferLimitsType = C4::Context->preference('BranchTransferLimitsType'); |
| 13 |
|
| 14 |
### Preparing our tests we want to run ### |
| 15 |
sub runTestsForCCode { |
| 16 |
my ($itemCPLFull, $itemCPLLite, $biblioitem) = @_; |
| 17 |
|
| 18 |
print 'Running tests for '.C4::Context->preference("BranchTransferLimitsType")."\n"; |
| 19 |
|
| 20 |
#howto use: CheckBranchTransferAllowed( $toBranch, $fromBranch, $item, $biblioitem] ); |
| 21 |
my $result = C4::Circulation::CheckBranchTransferAllowed( 'CPL', 'IPT', $itemCPLFull, $biblioitem ); |
| 22 |
is ( $result, 1, "Successful branch transfer, full parameters" ); |
| 23 |
|
| 24 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'IPT', 'CPL', $itemCPLFull, $biblioitem ); |
| 25 |
is ( $result, 'CPL->IPT->FANTASY', "Failing branch transfer, full parameters" ); |
| 26 |
|
| 27 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'CPL', 'IPT', $itemCPLFull, undef ); |
| 28 |
is ( $result, 1, "Successful branch transfer, full parameters, no Biblio defined" ); |
| 29 |
|
| 30 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'IPT', 'CPL', $itemCPLFull, undef ); |
| 31 |
is ( $result, 'CPL->IPT->FANTASY', "Failing branch transfer, full parameters, no Biblio defined" ); |
| 32 |
|
| 33 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'FFL', undef, $itemCPLFull, $biblioitem ); |
| 34 |
is ( $result, 1, "Successful branch transfer, using defaults for \$fromBranch" ); |
| 35 |
|
| 36 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'IPT', undef, $itemCPLFull, $biblioitem ); |
| 37 |
is ( $result, 'CPL->IPT->FANTASY', "Failing branch transfer, using defaults for \$fromBranch" ); |
| 38 |
|
| 39 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'FFL', undef, $itemCPLFull, undef ); |
| 40 |
is ( $result, 1, "Successful branch transfer, using minimum parameters" ); |
| 41 |
|
| 42 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'IPT', undef, $itemCPLFull, undef ); |
| 43 |
is ( $result, 'CPL->IPT->FANTASY', "Failing branch transfer, using minimum parameters" ); |
| 44 |
|
| 45 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'FFL', undef, $itemCPLLite, undef ); |
| 46 |
is ( $result, 1, "Successful branch transfer, using minimum parameters" ); |
| 47 |
|
| 48 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'IPT', undef, $itemCPLLite, undef ); |
| 49 |
is ( $result, 1, "Not failing branch transfer, because CCODE cannot be found from the item and it is not a part of the biblio." ); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
sub runTestsForItype { |
| 54 |
my ($itemCPLFull, $itemCPLLite, $biblioitem) = @_; |
| 55 |
|
| 56 |
print 'Running tests for '.C4::Context->preference("BranchTransferLimitsType")."\n"; |
| 57 |
|
| 58 |
#howto use: CheckBranchTransferAllowed( $toBranch, $fromBranch, $item, $biblioitem] ); |
| 59 |
my $result = C4::Circulation::CheckBranchTransferAllowed( 'CPL', 'IPT', $itemCPLFull, $biblioitem ); |
| 60 |
is ( $result, 1, "Successful branch transfer, full parameters" ); |
| 61 |
|
| 62 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'IPT', 'CPL', $itemCPLFull, $biblioitem ); |
| 63 |
is ( $result, 'CPL->IPT->BK', "Failing branch transfer, full parameters" ); |
| 64 |
|
| 65 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'CPL', 'IPT', $itemCPLFull, undef ); |
| 66 |
is ( $result, 1, "Successful branch transfer, full parameters, no Biblio defined" ); |
| 67 |
|
| 68 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'IPT', 'CPL', $itemCPLFull, undef ); |
| 69 |
is ( $result, 'CPL->IPT->BK', "Failing branch transfer, full parameters, no Biblio defined" ); |
| 70 |
|
| 71 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'FFL', undef, $itemCPLFull, $biblioitem ); |
| 72 |
is ( $result, 1, "Successful branch transfer, using defaults for \$fromBranch" ); |
| 73 |
|
| 74 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'IPT', undef, $itemCPLFull, $biblioitem ); |
| 75 |
is ( $result, 'CPL->IPT->BK', "Failing branch transfer, using defaults for \$fromBranch" ); |
| 76 |
|
| 77 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'FFL', undef, $itemCPLFull, undef ); |
| 78 |
is ( $result, 1, "Successful branch transfer, using minimum parameters" ); |
| 79 |
|
| 80 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'IPT', undef, $itemCPLFull, undef ); |
| 81 |
is ( $result, 'CPL->IPT->BK', "Failing branch transfer, using minimum parameters" ); |
| 82 |
|
| 83 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'FFL', undef, $itemCPLLite, undef ); |
| 84 |
is ( $result, 1, "Successful branch transfer, using minimum parameters, itemtype is pulled from Biblio" ); |
| 85 |
|
| 86 |
$result = C4::Circulation::CheckBranchTransferAllowed( 'IPT', undef, $itemCPLLite, undef ); |
| 87 |
is ( $result, 'CPL->IPT->BK', "Failing branch transfer, using minimum parameters, itemtype is pulled from Biblio" ); |
| 88 |
} |
| 89 |
### Tests prepared |
| 90 |
|
| 91 |
### Preparing our generic testing data ### |
| 92 |
|
| 93 |
#Set the item variables |
| 94 |
my $ccode = 'FANTASY'; |
| 95 |
my $itemtype = 'BK'; |
| 96 |
|
| 97 |
## Add a example Bibliographic record |
| 98 |
my $bibFramework = ''; #Using the default bibliographic framework. |
| 99 |
my $marcxml=qq(<?xml version="1.0" encoding="UTF-8"?> |
| 100 |
<record format="MARC21" type="Bibliographic"> |
| 101 |
<leader>00000cim a22000004a 4500</leader> |
| 102 |
<controlfield tag="001">1001</controlfield> |
| 103 |
<controlfield tag="005">2013-06-03 07:04:07+02</controlfield> |
| 104 |
<controlfield tag="007">ss||||j|||||||</controlfield> |
| 105 |
<controlfield tag="008"> uuuu xxk|||||||||||||||||eng|c</controlfield> |
| 106 |
<datafield tag="020" ind1=" " ind2=" "> |
| 107 |
<subfield code="a">0-00-103147-3</subfield> |
| 108 |
<subfield code="c">14.46 EUR</subfield> |
| 109 |
</datafield> |
| 110 |
<datafield tag="041" ind1="0" ind2=" "> |
| 111 |
<subfield code="d">eng</subfield> |
| 112 |
</datafield> |
| 113 |
<datafield tag="084" ind1=" " ind2=" "> |
| 114 |
<subfield code="a">83.5</subfield> |
| 115 |
<subfield code="2">ykl</subfield> |
| 116 |
</datafield> |
| 117 |
<datafield tag="100" ind1="1" ind2=" "> |
| 118 |
<subfield code="a">SHAKESPEARE, WILLIAM.</subfield> |
| 119 |
</datafield> |
| 120 |
<datafield tag="245" ind1="1" ind2="4"> |
| 121 |
<subfield code="a">THE TAMING OF THE SHREW /</subfield> |
| 122 |
<subfield code="c">WILLIAM SHAKESPEARE</subfield> |
| 123 |
<subfield code="h">[ÄÄNITE].</subfield> |
| 124 |
</datafield> |
| 125 |
<datafield tag="260" ind1=" " ind2=" "> |
| 126 |
<subfield code="a">LONDON :</subfield> |
| 127 |
<subfield code="b">COLLINS.</subfield> |
| 128 |
</datafield> |
| 129 |
<datafield tag="300" ind1=" " ind2=" "> |
| 130 |
<subfield code="a">2 ÄÄNIKASETTIA.</subfield> |
| 131 |
</datafield> |
| 132 |
<datafield tag="852" ind1=" " ind2=" "> |
| 133 |
<subfield code="a">FI-Jm</subfield> |
| 134 |
<subfield code="h">83.5</subfield> |
| 135 |
</datafield> |
| 136 |
<datafield tag="852" ind1=" " ind2=" "> |
| 137 |
<subfield code="a">FI-Konti</subfield> |
| 138 |
<subfield code="h">83.5</subfield> |
| 139 |
</datafield> |
| 140 |
</record> |
| 141 |
); |
| 142 |
my $record=C4::Record::marcxml2marc($marcxml); |
| 143 |
|
| 144 |
# Add a itemtype definition to the Record. |
| 145 |
my ( $biblioitemtypeTagid, $biblioitemtypeSubfieldid ) = |
| 146 |
C4::Biblio::GetMarcFromKohaField( 'biblioitems.itemtype', $bibFramework ); |
| 147 |
my $itemtypeField = MARC::Field->new($biblioitemtypeTagid, '', '', |
| 148 |
$biblioitemtypeSubfieldid => $itemtype); |
| 149 |
$record->append_fields( $itemtypeField ); |
| 150 |
|
| 151 |
my ( $newBiblionumber, $newBiblioitemnumber ) = C4::Biblio::AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } ); |
| 152 |
|
| 153 |
## Add an item with a ccode. |
| 154 |
my ($item_bibnum, $item_bibitemnum); |
| 155 |
my ($itemCPLFull, $itemCPLFullId); #Item with a itemtype and ccode in its data. |
| 156 |
my ($itemCPLLite, $itemCPLLiteId); #Item with no itemtype nor ccode in its data. Forces to look for it from the biblio. |
| 157 |
($item_bibnum, $item_bibitemnum, $itemCPLFullId) = C4::Items::AddItem({ barcode => 'CPLFull', homebranch => 'CPL', holdingbranch => 'CPL', ccode => $ccode, itemtype => $itemtype}, $newBiblionumber);#, biblioitemnumber => $newBiblioitemnumber, biblionumber => $newBiblioitemnumber }); |
| 158 |
($item_bibnum, $item_bibitemnum, $itemCPLLiteId) = C4::Items::AddItem({ barcode => 'CPLLite', homebranch => 'CPL', holdingbranch => 'CPL'}, $newBiblionumber);# biblioitemnumber => $newBiblioitemnumber, biblionumber => $newBiblioitemnumber }); |
| 159 |
|
| 160 |
|
| 161 |
### Created the generic testing material. ### |
| 162 |
### Setting preferences for ccode use-case ### |
| 163 |
|
| 164 |
C4::Context->set_preference("BranchTransferLimitsType", 'ccode'); |
| 165 |
|
| 166 |
## Add the TransferLimit rules: |
| 167 |
## IPT -> CPL -> FFL -> IPT |
| 168 |
# to from |
| 169 |
C4::Circulation::CreateBranchTransferLimit( 'IPT', 'CPL', $ccode ); |
| 170 |
C4::Circulation::CreateBranchTransferLimit( 'CPL', 'FFL', $ccode ); |
| 171 |
C4::Circulation::CreateBranchTransferLimit( 'FFL', 'IPT', $ccode ); |
| 172 |
|
| 173 |
## Ready to start testing ccode use-case ## |
| 174 |
|
| 175 |
$itemCPLFull = C4::Items::GetItem($itemCPLFullId); |
| 176 |
$itemCPLLite = C4::Items::GetItem($itemCPLLiteId); |
| 177 |
my $biblioitem = C4::Biblio::GetBiblioFromItemNumber( $itemCPLFull->{itemnumber} ); |
| 178 |
|
| 179 |
|
| 180 |
runTestsForCCode($itemCPLFull, $itemCPLLite, $biblioitem); |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
### ccode tested |
| 185 |
### Setting preferences for itemtype use-case ### |
| 186 |
|
| 187 |
C4::Context->set_preference("BranchTransferLimitsType", 'itemtype'); |
| 188 |
|
| 189 |
## Add the TransferLimit rules: |
| 190 |
## IPT -> CPL -> FFL -> IPT |
| 191 |
# to from |
| 192 |
C4::Circulation::CreateBranchTransferLimit( 'IPT', 'CPL', $itemtype ); |
| 193 |
C4::Circulation::CreateBranchTransferLimit( 'CPL', 'FFL', $itemtype ); |
| 194 |
C4::Circulation::CreateBranchTransferLimit( 'FFL', 'IPT', $itemtype ); |
| 195 |
|
| 196 |
## Ready to start testing itemtype use-case ## |
| 197 |
|
| 198 |
$itemCPLFull = C4::Items::GetItem($itemCPLFullId); |
| 199 |
$itemCPLLite = C4::Items::GetItem($itemCPLLiteId); |
| 200 |
$biblioitem = C4::Biblio::GetBiblioFromItemNumber( $itemCPLFull->{itemnumber} ); |
| 201 |
|
| 202 |
|
| 203 |
runTestsForItype($itemCPLFull, $itemCPLLite, $biblioitem); |
| 204 |
|
| 205 |
### itemtype tested |
| 206 |
|
| 207 |
### Reset default preferences |
| 208 |
C4::Context->set_preference("BranchTransferLimitsType", $originalBranchTransferLimitsType); |
| 209 |
|
| 210 |
$dbh->rollback; |