Bugzilla – Attachment 25286 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[s] packages
Bug-10363-Adds-unit-tests-for-KohaAuthorisedValues.patch (text/plain), 6.28 KB, created by
Marcel de Rooy
on 2014-02-14 17:49:47 UTC
(
hide
)
Description:
Bug 10363: Adds unit tests for Koha::AuthorisedValue[s] packages
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2014-02-14 17:49:47 UTC
Size:
6.28 KB
patch
obsolete
>From 3293b20b768fdf865edc4c955ced0be12e8ff698 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 28 May 2013 16:10:18 +0200 >Subject: [PATCH] Bug 10363: Adds unit tests for Koha::AuthorisedValue[s] > packages >Content-Type: text/plain; charset=utf-8 > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >--- > t/db_dependent/AuthorisedValues.t | 154 +++++++++++++++++++++++++++++++++++++ > 1 files changed, 154 insertions(+), 0 deletions(-) > 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..2b5cc96 >--- /dev/null >+++ b/t/db_dependent/AuthorisedValues.t >@@ -0,0 +1,154 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+use Test::More tests => 31; >+ >+use Koha::AuthorisedValue; >+use Koha::AuthorisedValues; >+ >+use Data::Dumper; # FIXME REMOVEME >+ >+# 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::AuthorisedValues->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->filter({category => 'av_for_testing_1'} ); >+my $avs2 = $avs->filter({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' ); >+ >+# select >+$avs->select('value 5'); >+my $selected = $avs->filter( { selected => 1 } ); >+is( scalar(@$selected), 1, 'There is just 1 AV selected' ); >+$selected = shift @$selected; >+is( $selected->{selected}, 1, 'av is selected' ); >+is( $selected->{authorised_value}, 'value 5', 'av selected is "value 5"'); >+ >+ >+$av1->delete; >+$av2->delete; >+$av3->delete; >+$av4->delete; >+$av5->delete; >-- >1.7.7.6
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