Lines 19-27
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 7; |
22 |
use Test::More tests => 8; |
23 |
|
23 |
|
24 |
use Koha::Review; |
24 |
use Koha::Patrons; |
25 |
use Koha::Reviews; |
25 |
use Koha::Reviews; |
26 |
use Koha::Database; |
26 |
use Koha::Database; |
27 |
|
27 |
|
Lines 31-54
my $schema = Koha::Database->new->schema;
Link Here
|
31 |
$schema->storage->txn_begin; |
31 |
$schema->storage->txn_begin; |
32 |
|
32 |
|
33 |
my $builder = t::lib::TestBuilder->new; |
33 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $patron_1 = $builder->build({ source => 'Borrower' }); |
34 |
my $patron_1 = $builder->build({ source => 'Borrower', value => { flags => undef } }); |
35 |
my $patron_2 = $builder->build({ source => 'Borrower' }); |
35 |
my $patron_2 = $builder->build({ source => 'Borrower' }); |
|
|
36 |
$patron_1 = Koha::Patrons->find( $patron_1->{borrowernumber} ); |
37 |
$patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} ); |
36 |
my $biblio_1 = $builder->build({ source => 'Biblio' }); |
38 |
my $biblio_1 = $builder->build({ source => 'Biblio' }); |
37 |
my $biblio_2 = $builder->build({ source => 'Biblio' }); |
39 |
my $biblio_2 = $builder->build({ source => 'Biblio' }); |
38 |
my $nb_of_reviews = Koha::Reviews->search->count; |
40 |
my $nb_of_reviews = Koha::Reviews->search->count; |
39 |
my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count; |
41 |
my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count; |
40 |
my $new_review_1_1 = Koha::Review->new({ |
42 |
my $new_review_1_1 = Koha::Review->new({ |
41 |
borrowernumber => $patron_1->{borrowernumber}, |
43 |
borrowernumber => $patron_1->borrowernumber, |
42 |
biblionumber => $biblio_1->{biblionumber}, |
44 |
biblionumber => $biblio_1->{biblionumber}, |
43 |
review => 'a kind review', |
45 |
review => 'a kind review', |
44 |
})->store; |
46 |
})->store; |
45 |
my $new_review_1_2 = Koha::Review->new({ |
47 |
my $new_review_1_2 = Koha::Review->new({ |
46 |
borrowernumber => $patron_1->{borrowernumber}, |
48 |
borrowernumber => $patron_1->borrowernumber, |
47 |
biblionumber => $biblio_2->{biblionumber}, |
49 |
biblionumber => $biblio_2->{biblionumber}, |
48 |
review => 'anoter kind review', |
50 |
review => 'anoter kind review', |
49 |
})->store; |
51 |
})->store; |
50 |
my $new_review_2_1 = Koha::Review->new({ |
52 |
my $new_review_2_1 = Koha::Review->new({ |
51 |
borrowernumber => $patron_2->{borrowernumber}, |
53 |
borrowernumber => $patron_2->borrowernumber, |
52 |
biblionumber => $biblio_1->{biblionumber}, |
54 |
biblionumber => $biblio_1->{biblionumber}, |
53 |
review => 'just anoter review', |
55 |
review => 'just anoter review', |
54 |
})->store; |
56 |
})->store; |
Lines 65-73
is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews, 'The
Link Here
|
65 |
my $retrieved_review_1_1 = Koha::Reviews->find( $new_review_1_1->reviewid ); |
67 |
my $retrieved_review_1_1 = Koha::Reviews->find( $new_review_1_1->reviewid ); |
66 |
is( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id should return the correct review' ); |
68 |
is( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id should return the correct review' ); |
67 |
|
69 |
|
|
|
70 |
subtest 'search_limited' => sub { |
71 |
plan tests => 2; |
72 |
C4::Context->_new_userenv('xxx'); |
73 |
my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1' } )->store; |
74 |
my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store; |
75 |
Koha::Library::Group->new({ parent_id => $group_1->id, branchcode => $patron_1->branchcode })->store(); |
76 |
Koha::Library::Group->new({ parent_id => $group_2->id, branchcode => $patron_2->branchcode })->store(); |
77 |
set_logged_in_user( $patron_1 ); |
78 |
is( Koha::Reviews->search->count, $nb_of_approved_reviews + 3, 'Koha::Reviews->search should return all reviews' ); |
79 |
is( Koha::Reviews->search_limited->count, $nb_of_approved_reviews + 2, 'Koha::Reviews->search_limited should return reviews depending on patron permissions' ); |
80 |
}; |
81 |
|
68 |
$retrieved_review_1_1->delete; |
82 |
$retrieved_review_1_1->delete; |
69 |
is( Koha::Reviews->search->count, $nb_of_reviews + 2, 'Delete should have deleted the review' ); |
83 |
is( Koha::Reviews->search->count, $nb_of_reviews + 2, 'Delete should have deleted the review' ); |
70 |
|
84 |
|
71 |
$schema->storage->txn_rollback; |
85 |
$schema->storage->txn_rollback; |
72 |
|
86 |
|
|
|
87 |
sub set_logged_in_user { |
88 |
my ($patron) = @_; |
89 |
C4::Context->set_userenv( |
90 |
$patron->borrowernumber, $patron->userid, |
91 |
$patron->cardnumber, 'firstname', |
92 |
'surname', $patron->library->branchcode, |
93 |
'Midway Public Library', $patron->flags, |
94 |
'', '' |
95 |
); |
96 |
} |
97 |
|
73 |
1; |
98 |
1; |