Bugzilla – Attachment 96920 Details for
Bug 23893
Add ->new_from_api and ->set_from_api methods to Koha::Object
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23893: Unit tests
Bug-23893-Unit-tests.patch (text/plain), 4.59 KB, created by
Kyle M Hall (khall)
on 2020-01-07 18:02:45 UTC
(
hide
)
Description:
Bug 23893: Unit tests
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2020-01-07 18:02:45 UTC
Size:
4.59 KB
patch
obsolete
>From d49ee7d3c2930bcc08d3bdcd96a75d03b96010cc Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 11 Nov 2019 15:03:29 -0300 >Subject: [PATCH] Bug 23893: Unit tests > >This patch introduces tests for the implemented methods. > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: John Doe <you@example.com> >--- > t/db_dependent/Koha/Object.t | 124 ++++++++++++++++++++++++++++++++++- > 1 file changed, 122 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index a37695bc1f..4474b3ac21 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 12; >+use Test::More tests => 16; > use Test::Exception; > use Test::Warn; > use DateTime; >@@ -260,7 +260,127 @@ subtest "to_api() tests" => sub { > > # Pick a class that won't have a mapping for the API > my $illrequest = $builder->build_object({ class => 'Koha::Illrequests' }); >- is_deeply( $illrequest->to_api, $illrequest->TO_JSON, 'If no to_api_method present, return TO_JSON' ); >+ is_deeply( $illrequest->to_api, $illrequest->TO_JSON, 'If no overloaded to_api_mapping method, return TO_JSON' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest "to_api_mapping() tests" => sub { >+ >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $illrequest = $builder->build_object({ class => 'Koha::Illrequests' }); >+ is_deeply( $illrequest->to_api_mapping, {}, 'If no to_api_mapping present, return empty hashref' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest "from_api_mapping() tests" => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $city = $builder->build_object({ class => 'Koha::Cities' }); >+ >+ # Lets emulate an undef >+ my $city_class = Test::MockModule->new('Koha::City'); >+ $city_class->mock( 'to_api_mapping', >+ sub { >+ return { >+ cityid => 'city_id', >+ city_country => 'country', >+ city_zipcode => undef >+ }; >+ } >+ ); >+ >+ is_deeply( >+ $city->from_api_mapping, >+ { >+ city_id => 'cityid', >+ country => 'city_country' >+ }, >+ 'Mapping returns correctly, undef ommited' >+ ); >+ >+ $city_class->unmock( 'to_api_mapping'); >+ $city_class->mock( 'to_api_mapping', >+ sub { >+ return { >+ cityid => 'city_id', >+ city_country => 'country', >+ city_zipcode => 'postal_code' >+ }; >+ } >+ ); >+ >+ is_deeply( >+ $city->from_api_mapping, >+ { >+ city_id => 'cityid', >+ country => 'city_country' >+ }, >+ 'Reverse mapping is cached' >+ ); >+ >+ # Get a fresh object >+ $city = $builder->build_object({ class => 'Koha::Cities' }); >+ is_deeply( >+ $city->from_api_mapping, >+ { >+ city_id => 'cityid', >+ country => 'city_country', >+ postal_code => 'city_zipcode' >+ }, >+ 'Fresh mapping loaded' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'set_from_api() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $city = $builder->build_object({ class => 'Koha::Cities' }); >+ my $city_unblessed = $city->unblessed; >+ my $attrs = { >+ name => 'Cordoba', >+ country => 'Argentina', >+ postal_code => '5000' >+ }; >+ $city->set_from_api($attrs); >+ >+ is( $city->city_state, $city_unblessed->{city_state}, 'Untouched attributes are preserved' ); >+ is( $city->city_name, $attrs->{name}, 'city_name updated correctly' ); >+ is( $city->city_country, $attrs->{country}, 'city_country updated correctly' ); >+ is( $city->city_zipcode, $attrs->{postal_code}, 'city_zipcode updated correctly' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'new_from_api() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $attrs = { >+ name => 'Cordoba', >+ country => 'Argentina', >+ postal_code => '5000' >+ }; >+ my $city = Koha::City->new_from_api($attrs); >+ >+ is( ref($city), 'Koha::City', 'Object type is correct' ); >+ is( $city->city_name, $attrs->{name}, 'city_name updated correctly' ); >+ is( $city->city_country, $attrs->{country}, 'city_country updated correctly' ); >+ is( $city->city_zipcode, $attrs->{postal_code}, 'city_zipcode updated correctly' ); > > $schema->storage->txn_rollback; > }; >-- >2.21.0 (Apple Git-122.2)
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 23893
:
95276
|
95277
|
95278
|
95311
|
95312
|
95313
|
95314
|
95315
|
96126
|
96127
|
96128
|
96129
|
96130
|
96652
|
96655
|
96656
|
96657
|
96658
|
96659
|
96660
|
96661
|
96662
|
96665
|
96666
|
96920
|
96921
|
96922
|
96923
|
96924
|
96925
|
96926
|
96927
|
96928
|
96929
|
96930
|
96931
|
96932
|
96933
|
96934
|
96935
|
96936
|
96937
|
97391