use Modern::Perl;
-use Test::More tests => 18;
+use Test::More;
use Test::Warn;
use t::lib::Mocks;
+use Module::Load::Conditional qw/check_install/;
+
BEGIN {
- t::lib::Mocks::mock_dbh;
+ if ( check_install( module => 'Test::DBIx::Class' ) ) {
+ plan tests => 11;
+ } else {
+ plan skip_all => "Need Test::DBIx::Class"
+ }
use_ok('Koha::Object');
use_ok('Koha::Patron');
}
+use Test::DBIx::Class;
+my $db = Test::MockModule->new('Koha::Database');
+$db->mock( _new_schema => sub { return Schema(); } );
+
my $object = Koha::Patron->new( { surname => 'Test Patron' } );
is( $object->surname(), 'Test Patron', "Accessor returns correct value" );
$object->surname('Test Patron Surname');
is( $object2->surname(), "Test Patron Surname 3", "Set sets first field correctly" );
is( $object2->firstname(), "Test Firstname", "Set sets second field correctly" );
-warning_is { $ret = $object->set({ surname => "Test Patron Surname 4", bork => "bork" }) }
- "No property bork!",
- "Expected 'No property bork!' caught";
-is( $object2->surname(), "Test Patron Surname 3", "Bad Set does not set field" );
-is( $ret, 0, "Set returns 0 when passed a bad property" );
-
-warning_is { $ret = $object->bork() }
- "No method bork!",
- "Expected 'No method bork!' caught for getter.";
-ok( ! defined $ret, 'Bad getter returns undef' );
-
-warning_is { $ret = $object->bork('bork') }
- "No method bork!",
- "Expected 'No method bork!' caught for setter.";
-ok( ! defined $ret, 'Bad setter returns undef' );
-
my $patron = Koha::Patron->new(
{
borrowernumber => '12345',
lost => '0',
debarred => '2015-04-19',
debarredcomment => 'You are debarred',
- contactname => 'myContactname',
- contactfirstname => 'myContactfirstname',
- contacttitle => 'myContacttitle',
- guarantorid => '123454321',
borrowernotes => 'borrowernotes',
- relationship => 'myRelationship',
sex => 'M',
password => 'hfkurhfe976634èj!',
flags => '55555',
# patron Accessor tests
subtest 'Accessor tests' => sub {
- plan tests => 65;
+ plan tests => 60;
is( $patron->borrowernumber, '12345', 'borrowernumber accessor returns correct value' );
is( $patron->cardnumber, '1234567890', 'cardnumber accessor returns correct value' );
is( $patron->surname, 'mySurname', 'surname accessor returns correct value' );
is( $patron->lost, '0', 'lost accessor returns correct value' );
is( $patron->debarred, '2015-04-19', 'debarred accessor returns correct value' );
is( $patron->debarredcomment, 'You are debarred', 'debarredcomment accessor returns correct value' );
- is( $patron->contactname, 'myContactname', 'contactname accessor returns correct value' );
- is( $patron->contactfirstname, 'myContactfirstname', 'contactfirstname accessor returns correct value' );
- is( $patron->contacttitle, 'myContacttitle', 'contacttitle accessor returns correct value' );
- is( $patron->guarantorid, '123454321', 'guarantorid accessor returns correct value' );
is( $patron->borrowernotes, 'borrowernotes', 'borrowernotes accessor returns correct value' );
- is( $patron->relationship, 'myRelationship', 'relationship accessor returns correct value' );
is( $patron->sex, 'M', 'sex accessor returns correct value' );
is( $patron->password, 'hfkurhfe976634èj!', 'password accessor returns correct value' );
is( $patron->flags, '55555', 'flags accessor returns correct value' );
# patron Set tests
subtest 'Set tests' => sub {
- plan tests => 65;
+ plan tests => 60;
$patron->set(
{
lost => '1',
debarred => '2016-04-19',
debarredcomment => 'You are still debarred',
- contactname => 'SmyContactname',
- contactfirstname => 'SmyContactfirstname',
- contacttitle => 'SmyContacttitle',
- guarantorid => '223454321',
borrowernotes => 'Sborrowernotes',
- relationship => 'SmyRelationship',
sex => 'F',
password => 'zerzerzer#',
flags => '666666',
is( $patron->lost, '1', 'lost field set ok' );
is( $patron->debarred, '2016-04-19', 'debarred field set ok' );
is( $patron->debarredcomment, 'You are still debarred', 'debarredcomment field set ok' );
- is( $patron->contactname, 'SmyContactname', 'contactname field set ok' );
- is( $patron->contactfirstname, 'SmyContactfirstname', 'contactfirstname field set ok' );
- is( $patron->contacttitle, 'SmyContacttitle', 'contacttitle field set ok' );
- is( $patron->guarantorid, '223454321', 'guarantorid field set ok' );
is( $patron->borrowernotes, 'Sborrowernotes', 'borrowernotes field set ok' );
- is( $patron->relationship, 'SmyRelationship', 'relationship field set ok' );
is( $patron->sex, 'F', 'sex field set ok' );
is( $patron->password, 'zerzerzer#', 'password field set ok' );
is( $patron->flags, '666666', 'flags field set ok' );
is( $patron->privacy, '667789', 'privacy field set ok' );
};
-1;