Lines 23-71
use Test::MockModule;
Link Here
|
23 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
25 |
|
25 |
|
|
|
26 |
use Koha::ArticleRequests; |
27 |
|
26 |
my $schema = Koha::Database->new->schema; |
28 |
my $schema = Koha::Database->new->schema; |
27 |
my $builder = t::lib::TestBuilder->new; |
29 |
my $builder = t::lib::TestBuilder->new; |
28 |
|
30 |
|
29 |
subtest 'request() tests' => sub { |
31 |
subtest 'request() tests' => sub { |
30 |
|
32 |
|
31 |
plan tests => 2; |
33 |
plan tests => 3; |
32 |
|
34 |
|
33 |
$schema->storage->txn_begin; |
35 |
$schema->storage->txn_begin; |
34 |
|
36 |
|
|
|
37 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
38 |
my $biblio = $builder->build_sample_biblio; |
39 |
|
35 |
my $ar_mock = Test::MockModule->new('Koha::ArticleRequest'); |
40 |
my $ar_mock = Test::MockModule->new('Koha::ArticleRequest'); |
36 |
$ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } ); |
41 |
$ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } ); |
37 |
|
42 |
|
38 |
my $ar = $builder->build_object( |
43 |
my $ar = Koha::ArticleRequest->new( |
39 |
{ class => 'Koha::ArticleRequests', |
44 |
{ |
40 |
value => { status => Koha::ArticleRequest::Status::Pending } |
45 |
borrowernumber => $patron->id, |
|
|
46 |
biblionumber => $biblio->id, |
41 |
} |
47 |
} |
42 |
); |
48 |
); |
43 |
|
49 |
|
44 |
$ar->request()->discard_changes; |
50 |
$ar->request()->discard_changes; |
45 |
|
51 |
|
46 |
is( $ar->status, Koha::ArticleRequest::Status::Requested ); |
52 |
is( $ar->status, Koha::ArticleRequest::Status::Requested ); |
|
|
53 |
ok( defined $ar->created_on, 'created_on is set' ); |
47 |
|
54 |
|
48 |
$schema->storage->txn_rollback; |
55 |
$schema->storage->txn_rollback; |
49 |
}; |
56 |
}; |
50 |
|
57 |
|
51 |
subtest 'set_pending() tests' => sub { |
58 |
subtest 'set_pending() tests' => sub { |
52 |
|
59 |
|
53 |
plan tests => 2; |
60 |
plan tests => 3; |
54 |
|
61 |
|
55 |
$schema->storage->txn_begin; |
62 |
$schema->storage->txn_begin; |
56 |
|
63 |
|
|
|
64 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
65 |
my $biblio = $builder->build_sample_biblio; |
66 |
|
57 |
my $ar_mock = Test::MockModule->new('Koha::ArticleRequest'); |
67 |
my $ar_mock = Test::MockModule->new('Koha::ArticleRequest'); |
58 |
$ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } ); |
68 |
$ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } ); |
59 |
|
69 |
|
60 |
my $ar = $builder->build_object( |
70 |
my $ar = Koha::ArticleRequest->new( |
61 |
{ class => 'Koha::ArticleRequests', |
71 |
{ |
62 |
value => { status => Koha::ArticleRequest::Status::Requested } |
72 |
borrowernumber => $patron->id, |
|
|
73 |
biblionumber => $biblio->id, |
63 |
} |
74 |
} |
64 |
); |
75 |
); |
65 |
|
76 |
|
66 |
$ar->set_pending()->discard_changes; |
77 |
$ar->set_pending()->discard_changes; |
67 |
|
78 |
|
68 |
is( $ar->status, Koha::ArticleRequest::Status::Pending ); |
79 |
is( $ar->status, Koha::ArticleRequest::Status::Pending ); |
|
|
80 |
ok( defined $ar->created_on, 'created_on is set' ); |
69 |
|
81 |
|
70 |
$schema->storage->txn_rollback; |
82 |
$schema->storage->txn_rollback; |
71 |
}; |
83 |
}; |
72 |
- |
|
|