Bugzilla – Attachment 54208 Details for
Bug 17089
Move the star ratings related code to Koha::Ratings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17089: Koha::Ratings - move tests
Bug-17089-KohaRatings---move-tests.patch (text/plain), 6.64 KB, created by
Jonathan Druart
on 2016-08-09 14:13:50 UTC
(
hide
)
Description:
Bug 17089: Koha::Ratings - move tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-08-09 14:13:50 UTC
Size:
6.64 KB
patch
obsolete
>From 1049014686c7cf255b62f9a5f090dfe813a98ff2 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 12 Jul 2016 11:28:42 +0100 >Subject: [PATCH] Bug 17089: Koha::Ratings - move tests > >Rewrite and move the tests. >--- > t/db_dependent/Koha/Ratings.t | 52 ++++++++++++++++++ > t/db_dependent/Ratings.t | 121 ------------------------------------------ > 2 files changed, 52 insertions(+), 121 deletions(-) > create mode 100755 t/db_dependent/Koha/Ratings.t > delete mode 100755 t/db_dependent/Ratings.t > >diff --git a/t/db_dependent/Koha/Ratings.t b/t/db_dependent/Koha/Ratings.t >new file mode 100755 >index 0000000..2d99e94 >--- /dev/null >+++ b/t/db_dependent/Koha/Ratings.t >@@ -0,0 +1,52 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 4; >+ >+use Koha::Database; >+use Koha::Rating; >+use Koha::Ratings; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->schema; >+$schema->storage->txn_begin; >+my $builder = t::lib::TestBuilder->new; >+ >+my $patron_1 = $builder->build( { source => 'Borrower', } ); >+my $patron_2 = $builder->build( { source => 'Borrower', } ); >+my $biblio_1 = $builder->build( { source => 'Biblio', } ); >+my $biblionumber = $biblio_1->{biblionumber}; >+ >+my $rating_1 = Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $patron_1->{borrowernumber}, rating_value => 3 } )->store; >+my $rating_2 = Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $patron_2->{borrowernumber}, rating_value => 4 } )->store; >+ >+is( Koha::Ratings->search( { biblionumber => $biblionumber } )->get_avg_rating, 3.5, ); >+ >+$rating_1->rating_value(5)->store; >+ >+is( Koha::Ratings->search( { biblionumber => $biblionumber } )->get_avg_rating, 4.5, ); >+ >+Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $patron_1->{borrowernumber} } )->delete; >+Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $patron_2->{borrowernumber} } )->delete; >+is( Koha::Ratings->search( { biblionumber => $biblionumber } )->count, 0, 'Delete should have deleted the ratings' ); >+ >+is( int(Koha::Ratings->search( { biblionumber => $biblionumber } )->get_avg_rating), 0, 'get_avg_rating should return 0 if no rating exist' ); >+ >+1; >diff --git a/t/db_dependent/Ratings.t b/t/db_dependent/Ratings.t >deleted file mode 100755 >index 1f5db0e..0000000 >--- a/t/db_dependent/Ratings.t >+++ /dev/null >@@ -1,121 +0,0 @@ >-#!/usr/bin/perl >- >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use Test::More tests => 14; >- >-use C4::Biblio qw/AddBiblio/; >-use C4::Members; >-use C4::Context; >-use C4::Category; >-use Koha::Database; >- >-use t::lib::TestBuilder; >- >-use_ok('C4::Ratings'); >- >-my $schema = Koha::Database->schema; >-$schema->storage->txn_begin; >-my $builder = t::lib::TestBuilder->new; >-my $dbh = C4::Context->dbh; >-$dbh->{RaiseError} = 1; >- >-my $library = $builder->build({ >- source => 'Branch', >-}); >- >-my ($biblionumber) = AddBiblio( MARC::Record->new, '' ); >- >-my @categories = C4::Category->all; >-my $categorycode = $categories[0]->categorycode; >-my $branchcode = $library->{branchcode}; >- >-my %john_doe = ( >- cardnumber => '123456', >- firstname => 'John', >- surname => 'Doe', >- categorycode => $categorycode, >- branchcode => $branchcode, >- dateofbirth => '', >- dateexpiry => '9999-12-31', >- userid => 'john.doe' >-); >- >-my %jane_doe = ( >- cardnumber => '345678', >- firstname => 'Jane', >- surname => 'Doe', >- categorycode => $categorycode, >- branchcode => $branchcode, >- dateofbirth => '', >- dateexpiry => '9999-12-31', >- userid => 'jane.doe' >-); >- >-my $borrowernumber1 = AddMember(%john_doe); >-my $borrowernumber2 = AddMember(%jane_doe); >- >-my $rating1 = AddRating( $biblionumber, $borrowernumber1, 3 ); >-my $rating2 = AddRating( $biblionumber, $borrowernumber2, 4 ); >-my $rating3 = ModRating( $biblionumber, $borrowernumber1, 5 ); >-my $rating4 = GetRating( $biblionumber, $borrowernumber2 ); >-my $rating5 = GetRating( $biblionumber ); >- >-ok( defined $rating1, 'add a rating' ); >-ok( defined $rating2, 'add another rating' ); >-ok( defined $rating3, 'update a rating' ); >-ok( defined $rating4, 'get a rating, with borrowernumber' ); >- >-ok( $rating3->{'rating_avg'} == '4', "get a bib's average(float) rating" ); >-ok( $rating3->{'rating_avg_int'} == 4.5, "get a bib's average(int) rating" ); >-ok( $rating3->{'rating_total'} == 2, "get a bib's total number of ratings" ); >-ok( $rating3->{'rating_value'} == 5, "verify user's bib rating" ); >- >-my $rating_1 = GetRating( $biblionumber ); >-my $rating_1_1 = GetRating( $biblionumber, $borrowernumber1 ); >-is_deeply( >- $rating_1, >- { >- rating_avg_int => 4.5, >- rating_total => 2, >- rating_avg => 4, >- rating_value => undef, >- }, >- 'GetRating should return total, avg_int and avg if biblionumber is given' >-); >-is_deeply( >- $rating_1_1, >- { >- rating_avg_int => 4.5, >- rating_total => 2, >- rating_avg => 4, >- rating_value => 5, >- }, >-'GetRating should return total, avg_int, avg and value if biblionumber is given' >-); >- >-my $rating6 = DelRating( $biblionumber, $borrowernumber1 ); >-my $rating7 = DelRating( $biblionumber, $borrowernumber2 ); >- >-ok( defined $rating6, 'delete a rating' ); >-ok( defined $rating7, 'delete another rating' ); >- >-is( GetRating( $biblionumber, $borrowernumber1 ), >- undef, 'GetRating should return undef if no rating exist' ); >- >-1; >-- >2.8.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 17089
:
54207
|
54208
|
54209
|
54210
|
54211
|
54212
|
54213
|
54214
|
54225
|
54230
|
54231
|
54232
|
54233
|
54234
|
54235
|
54236
|
54237
|
54238
|
54332
|
54333
|
54334
|
54335
|
54336
|
54337
|
54338
|
54339
|
54340
|
54341