Bugzilla – Attachment 30583 Details for
Bug 10363
Move authorised value related code into its own package
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10363: Adds unit tests for Koha::AuthorisedValue package
Bug-10363-Adds-unit-tests-for-KohaAuthorisedValue-.patch (text/plain), 5.85 KB, created by
Yohann Dufour
on 2014-08-07 14:42:05 UTC
(
hide
)
Description:
Bug 10363: Adds unit tests for Koha::AuthorisedValue package
Filename:
MIME Type:
Creator:
Yohann Dufour
Created:
2014-08-07 14:42:05 UTC
Size:
5.85 KB
patch
obsolete
>From 950b068a533cc24848ee4e5a9f43e26956d6a5f5 Mon Sep 17 00:00:00 2001 >From: Yohann Dufour <dufour.yohann@gmail.com> >Date: Thu, 7 Aug 2014 16:39:50 +0200 >Subject: [PATCH] Bug 10363: Adds unit tests for Koha::AuthorisedValue package > >--- > t/db_dependent/AuthorisedValues.t | 147 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 147 insertions(+) > create mode 100644 t/db_dependent/AuthorisedValues.t > >diff --git a/t/db_dependent/AuthorisedValues.t b/t/db_dependent/AuthorisedValues.t >new file mode 100644 >index 0000000..76dab8b >--- /dev/null >+++ b/t/db_dependent/AuthorisedValues.t >@@ -0,0 +1,147 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+use Test::More tests => 29; >+ >+use C4::Context; >+use Koha::AuthorisedValue; >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+$dbh->do("DELETE FROM authorised_values"); >+ >+# Tests for Koha::AuthorisedValue >+ >+# insert >+my $av1 = Koha::AuthorisedValue->new({ >+ category => 'av_for_testing', >+ authorised_value => 'value 1', >+ lib => 'display value 1', >+ lib_opac => 'opac display value 1', >+ imageurl => 'image1.png', >+}); >+ >+eval {$av1->insert}; >+ok( ! $@, 'AV 1 is inserted without error'); >+ >+my $av1_bis = Koha::AuthorisedValue->new({ >+ category => 'av_for_testing', >+ authorised_value => 'value 1', >+ lib => 'display value 2', >+ lib_opac => 'opac display value 2', >+ imageurl => 'image2.png', >+}); >+ >+eval {$av1_bis->insert}; >+ok( $@, 'AV 2 is not inserted (error raised) : Unique key category-authorised_value'); >+ >+my $id = $av1->{id}; >+ok( $av1->{id}, 'AV 1 is inserted' ); >+ >+my $new_av1 = Koha::AuthorisedValue->new( { id => $id } )->fetch; >+ >+is( $new_av1->{id}, $id, "insert: id has been correctly get back" ); >+is( $new_av1->{authorised_value}, $av1->{authorised_value}, "insert: authorised_value has been correctly get back" ); >+is( $new_av1->{lib}, $av1->{lib}, "insert: lib has been correctly get back" ); >+is( $new_av1->{lib_opac}, $av1->{lib_opac}, "insert: lib_opac has been correctly get back" ); >+is( $new_av1->{imageurl}, $av1->{imageurl}, "insert: imageurl has been correctly get back" ); >+is( $new_av1->{branches_limitations}, undef, "insert: branches_limitations is not get back with fetch" ); >+is_deeply( $new_av1->branches_limitations, [], "insert: The branches_limitations method returns the branches limitations" ); >+is_deeply( $new_av1->{branches_limitations}, [], "insert: The branches_limitations method set the branches_limitations key" ); >+ >+# update >+$av1->{authorised_value} = 'new value 1'; >+$av1->{lib} = 'new lib 1'; >+$av1->{lib_opac} = 'new lib opac 1'; >+$av1->{imageurl} = 'new_image2.png'; >+my $branches_limitations = [ >+ {branchcode => 'CPL', branchname => 'Centerville'}, >+ {branchcode => 'MPL', branchname => 'Midway'}, >+]; >+$av1->{branches_limitations} = $branches_limitations; >+eval{$av1->update}; >+ok( ! $@, 'AV 1 is updated without error'); >+ >+$new_av1 = Koha::AuthorisedValue->new( { id => $id } )->fetch; >+is( $new_av1->{id}, $id, "update: id has been correctly get back" ); >+is( $new_av1->{authorised_value}, 'new value 1', "update: authorised_value has been correctly get back" ); >+is( $new_av1->{lib}, 'new lib 1', "update: lib has been correctly get back" ); >+is( $new_av1->{lib_opac}, 'new lib opac 1', "update: lib_opac has been correctly get back" ); >+is( $new_av1->{imageurl}, 'new_image2.png', "update: imageurl has been correctly get back" ); >+is( $new_av1->{branches_limitations}, undef, "update: branches_limitations is not get back with fetch" ); >+is_deeply( $new_av1->branches_limitations, $branches_limitations, "update: The branches_limitations method returns the branches limitations" ); >+is_deeply( $new_av1->{branches_limitations}, $branches_limitations, "update: The branches_limitations method set the branches_limitations key" ); >+ >+# delete >+eval{$av1->delete}; >+ok( ! $@, 'AV 1 is deleted without error' ); >+ >+eval{ >+ $new_av1 = Koha::AuthorisedValue->new( { id => $id } )->fetch; >+}; >+ok( $@, 'AV 1 is removed from the database' ); >+ >+ >+# Tests for Koha::AuthorisedValues >+$av1 = Koha::AuthorisedValue->new({ >+ category => 'av_for_testing_1', >+ authorised_value => 'value 1', >+ lib => 'display value 1', >+ lib_opac => 'opac display value 1', >+ imageurl => 'image1.png', >+}); >+my $av2 = Koha::AuthorisedValue->new({ >+ category => 'av_for_testing_1', >+ authorised_value => 'value 2', >+ lib => 'display value 2', >+ lib_opac => 'opac display value 2', >+ imageurl => 'image2.png', >+}); >+my $av3 = Koha::AuthorisedValue->new({ >+ category => 'av_for_testing_1', >+ authorised_value => 'value 3', >+ lib => 'display value 3', >+ lib_opac => 'opac display value 3', >+ imageurl => 'image3.png', >+}); >+my $av4 = Koha::AuthorisedValue->new({ >+ category => 'av_for_testing_2', >+ authorised_value => 'value 4', >+ lib => 'display value 4', >+ lib_opac => 'opac display value 4', >+ imageurl => 'image4.png', >+}); >+my $av5 = Koha::AuthorisedValue->new({ >+ category => 'av_for_testing_2', >+ authorised_value => 'value 5', >+ lib => 'display value 5', >+ lib_opac => 'opac display value 5', >+ imageurl => 'image5.png', >+}); >+eval { >+ $av1->insert; >+ $av2->insert; >+ $av3->insert; >+ $av4->insert; >+ $av5->insert; >+}; >+ok( ! $@, "5 AV inserted with success" ); >+my $avs = Koha::AuthorisedValue->new; >+ >+# get categories >+my $categories = $avs->categories; >+is( grep ({/av_for_testing_1/} @$categories), 1, "av_for_testing_1 is a category"); >+is( grep ({/av_for_testing_2/} @$categories), 1, "av_for_testing_2 is a category"); >+is( grep ({/av_for_testing_3/} @$categories), 0, "av_for_testing_3 is not a category"); >+ >+# filter >+my $avs1 = $avs->search({category => 'av_for_testing_1'} ); >+my $avs2 = $avs->search({category => 'av_for_testing_2'} ); >+is( scalar(@$avs1), 3, 'There are 3 AVs for category 1' ); >+is( scalar(@$avs2), 2, 'There are 2 AVs for category 2' ); >+ >+is( $av1->delete, 1, "Delete 1 AV" ); >+ >+$dbh->rollback; >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10363
:
18430
|
18431
|
18432
|
18751
|
18752
|
18753
|
20729
|
21833
|
21834
|
21835
|
21836
|
25284
|
25285
|
25286
|
25287
|
30583
|
30584
|
30585
|
30710
|
30711
|
30712
|
31565
|
32632
|
32633
|
32634
|
33416
|
33417
|
33422
|
33423
|
33860
|
33861
|
33862
|
33889
|
33949
|
35838
|
35839
|
35840
|
35841
|
41290
|
41291
|
41292
|
41293
|
41294
|
41302
|
41343
|
41344
|
41345
|
43112
|
43113
|
43114
|
43550
|
43551
|
43552
|
43553
|
43554
|
43555
|
43556
|
43557
|
43558
|
43559
|
43696
|
43827