From 08cd46080a5c8566f5cc4de7b841554fd06b0e78 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Fri, 10 Mar 2017 14:46:46 +0000 Subject: [PATCH] Bug 18247 - Added 3 successfully working unit tests for each new subroutine --- t/db_dependent/AuthorisedValues.t | 27 +++++++++++++++++++++++++-- t/db_dependent/Koha/ItemTypes.t | 12 +++++++++++- t/db_dependent/Koha/Libraries.t | 13 ++++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/AuthorisedValues.t b/t/db_dependent/AuthorisedValues.t index 6d44a72..74b2886 100644 --- a/t/db_dependent/AuthorisedValues.t +++ b/t/db_dependent/AuthorisedValues.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 15; +use Test::More tests => 17; use C4::Context; use Koha::AuthorisedValue; @@ -20,6 +20,8 @@ $dbh->do("DELETE FROM authorised_value_categories"); Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store; Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store; Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store; +Koha::AuthorisedValueCategory->new({ category_name => 'CCODE' })->store; + my $av1 = Koha::AuthorisedValue->new( { category => 'av_for_testing', @@ -76,6 +78,13 @@ my $av_0 = Koha::AuthorisedValue->new( } )->store(); +my $CatAuthValue = Koha::AuthorisedValue->new( + { + category => 'CCODE', + authorised_value => 'value 5', + } +)->store(); + ok( $av1->id(), 'AV 1 is inserted' ); ok( $av2->id(), 'AV 2 is inserted' ); ok( $av3->id(), 'AV 3 is inserted' ); @@ -114,7 +123,7 @@ my $limits = $av1->branch_limitations; is( @$limits, 2, 'branch_limitations functions correctly both as setter and getter' ); my @categories = Koha::AuthorisedValues->new->categories; -is( @categories, 3, 'There should have 2 categories inserted' ); +is( @categories, 4, 'There should have 4 categories inserted' ); is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' ); is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' ); @@ -225,3 +234,17 @@ subtest 'search_by_*_field + find_by_koha_field + get_description' => sub { ); }; }; + +ok( $CatAuthValue->id(), 'CatAuthValue is inserted' ); + +sub GetCatAuthValues { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"'); + $sth->execute(); + return $sth->rows; +} + +my $AuthValues = GetCatAuthValues(); +is($AuthValues, 1, "Correct number of authorised_value's with category=CCODE"); + + diff --git a/t/db_dependent/Koha/ItemTypes.t b/t/db_dependent/Koha/ItemTypes.t index 9ce1ad6..7adf112 100755 --- a/t/db_dependent/Koha/ItemTypes.t +++ b/t/db_dependent/Koha/ItemTypes.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 18; +use Test::More tests => 19; use Data::Dumper; use Koha::Database; @@ -76,4 +76,14 @@ is( $type->summary, 'summary', 'summary' ); is( $type->checkinmsg, 'checkinmsg', 'checkinmsg' ); is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' ); +sub GetItemTypes { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare('SELECT itemtype FROM itemtypes'); + $sth->execute(); + return $sth->rows; +} + +my $ItemTypes = GetItemTypes(); +is($ItemTypes,10, "Correct number of itemtypes"); + $schema->txn_rollback; diff --git a/t/db_dependent/Koha/Libraries.t b/t/db_dependent/Koha/Libraries.t index 8126b8c..3090735 100644 --- a/t/db_dependent/Koha/Libraries.t +++ b/t/db_dependent/Koha/Libraries.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 9; +use Test::More tests => 10; use Koha::Library; use Koha::Libraries; @@ -86,5 +86,16 @@ is( Koha::Libraries->search->count, $nb_of_libraries + 1, 'Delete should have de $retrieved_category_2->delete; is( Koha::LibraryCategories->search->count, $nb_of_categories + 2, 'Delete should have deleted the library category' ); +sub GetBranchCodes { + my $dbh = C4::Context->dbh; + my $query = qq{ SELECT branchcode FROM branches }; + my $sth = $dbh->prepare($query); + $sth->execute(); + return $sth->rows; +} + +my $BranchCodes = GetBranchCodes(); +is($BranchCodes, 13, "Correct number of branchcodes"); + $schema->storage->txn_rollback; 1; -- 2.1.4