View | Details | Raw Unified | Return to bug 26635
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Object.t (-1 / +42 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 20;
20
use Test::More tests => 21;
21
use Test::Exception;
21
use Test::Exception;
22
use Test::Warn;
22
use Test::Warn;
23
use DateTime;
23
use DateTime;
Lines 33-38 use Koha::DateUtils qw( dt_from_string ); Link Here
33
use Koha::Libraries;
33
use Koha::Libraries;
34
use Koha::Patrons;
34
use Koha::Patrons;
35
use Koha::ApiKeys;
35
use Koha::ApiKeys;
36
use Koha::AuthorisedValueCategories;
37
use Koha::AuthorisedValues;
36
38
37
use JSON;
39
use JSON;
38
use Scalar::Util qw( isvstring );
40
use Scalar::Util qw( isvstring );
Lines 867-869 subtest 'set_or_blank' => sub { Link Here
867
869
868
    $schema->storage->txn_rollback;
870
    $schema->storage->txn_rollback;
869
};
871
};
872
873
subtest 'Authorised values expansion' => sub {
874
    plan tests => 4;
875
876
    $schema->storage->txn_begin;
877
878
    Koha::AuthorisedValues->search({category => 'Countries'})->delete;
879
    Koha::AuthorisedValueCategories->search({category_name =>'Countries'})->delete;
880
881
    my $cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories', value => {category_name =>'Countries'} });
882
    my $fr = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'FR', lib=>'France', category=>$cat->category_name} });
883
    my $us = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'US', lib=>'United States of America', category=>$cat->category_name} });
884
    my $ar = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'AR', lib=>'Argentina', category=>$cat->category_name} });
885
886
    my $city_class = Test::MockModule->new('Koha::City');
887
    $city_class->mock( '_fetch_authorised_values',
888
        sub {
889
            my ($self) = @_;
890
            use Koha::AuthorisedValues;
891
            my $av = Koha::AuthorisedValues->find({authorised_value => $self->city_country, category => 'Countries'});
892
            return {country => $av->unblessed};
893
        }
894
    );
895
896
    my $marseille = $builder->build_object({ class => 'Koha::Cities', value => {city_country => 'FR', city_name => 'Marseille'} });
897
    my $cordoba = $builder->build_object({ class => 'Koha::Cities', value => {city_country => 'AR', city_name => 'Córdoba'} });
898
899
    my $mobj = $marseille->to_api({av_expand => 1});
900
    my $cobj = $cordoba->to_api({av_expand => 1});
901
902
    isnt($mobj->{_authorised_values}, undef, '_authorised_values exists for Marseille');
903
    isnt($cobj->{_authorised_values}, undef, '_authorised_values exists for Córdoba');
904
905
    is($mobj->{_authorised_values}->{country}->{lib}, $fr->lib, 'Authorised value for country expanded');
906
    is($cobj->{_authorised_values}->{country}->{lib}, $ar->lib, 'Authorised value for country expanded');
907
908
909
    $schema->storage->txn_rollback;
910
};
(-)a/t/db_dependent/Koha/REST/Plugin/Objects.t (-8 / +64 lines)
Lines 21-26 use Koha::Acquisition::Orders; Link Here
21
use Koha::Cities;
21
use Koha::Cities;
22
use Koha::Holds;
22
use Koha::Holds;
23
use Koha::Biblios;
23
use Koha::Biblios;
24
use Koha::AuthorisedValueCategories;
25
use Koha::AuthorisedValues;
24
26
25
# Dummy app for testing the plugin
27
# Dummy app for testing the plugin
26
use Mojolicious::Lite;
28
use Mojolicious::Lite;
Lines 77-83 get '/biblios' => sub { Link Here
77
79
78
80
79
# The tests
81
# The tests
80
use Test::More tests => 10;
82
use Test::More tests => 11;
81
use Test::Mojo;
83
use Test::Mojo;
82
84
83
use t::lib::Mocks;
85
use t::lib::Mocks;
Lines 305-311 subtest 'objects.search helper, with path parameters and _match' => sub { Link Here
305
    $schema->storage->txn_rollback;
307
    $schema->storage->txn_rollback;
306
};
308
};
307
309
308
subtest 'object.search helper with query parameter' => sub {
310
subtest 'objects.search helper with query parameter' => sub {
309
    plan tests => 4;
311
    plan tests => 4;
310
312
311
    $schema->storage->txn_begin;
313
    $schema->storage->txn_begin;
Lines 328-334 subtest 'object.search helper with query parameter' => sub { Link Here
328
    $schema->storage->txn_rollback;
330
    $schema->storage->txn_rollback;
329
};
331
};
330
332
331
subtest 'object.search helper with q parameter' => sub {
333
subtest 'objects.search helper with q parameter' => sub {
332
    plan tests => 4;
334
    plan tests => 4;
333
335
334
    $schema->storage->txn_begin;
336
    $schema->storage->txn_begin;
Lines 351-357 subtest 'object.search helper with q parameter' => sub { Link Here
351
    $schema->storage->txn_rollback;
353
    $schema->storage->txn_rollback;
352
};
354
};
353
355
354
subtest 'object.search helper with x-koha-query header' => sub {
356
subtest 'objects.search helper with x-koha-query header' => sub {
355
    plan tests => 4;
357
    plan tests => 4;
356
358
357
    $schema->storage->txn_begin;
359
    $schema->storage->txn_begin;
Lines 374-380 subtest 'object.search helper with x-koha-query header' => sub { Link Here
374
    $schema->storage->txn_rollback;
376
    $schema->storage->txn_rollback;
375
};
377
};
376
378
377
subtest 'object.search helper with all query methods' => sub {
379
subtest 'objects.search helper with all query methods' => sub {
378
    plan tests => 6;
380
    plan tests => 6;
379
381
380
    $schema->storage->txn_begin;
382
    $schema->storage->txn_begin;
Lines 400-408 subtest 'object.search helper with all query methods' => sub { Link Here
400
    $schema->storage->txn_rollback;
402
    $schema->storage->txn_rollback;
401
};
403
};
402
404
403
subtest 'object.search helper order by embedded columns' => sub {
405
subtest 'objects.search helper order by embedded columns' => sub {
404
    plan tests => 3;
406
    plan tests => 3;
405
407
408
    $schema->storage->txn_begin;
409
406
    my $patron1 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron1'} } );
410
    my $patron1 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron1'} } );
407
    my $patron2 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron2'} } );
411
    my $patron2 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron2'} } );
408
    my $biblio1 = $builder->build_sample_biblio;
412
    my $biblio1 = $builder->build_sample_biblio;
Lines 414-418 subtest 'object.search helper order by embedded columns' => sub { Link Here
414
      ->json_is('/biblios/0/biblio_id' => $biblio2->biblionumber, 'Biblio 2 should be first')
418
      ->json_is('/biblios/0/biblio_id' => $biblio2->biblionumber, 'Biblio 2 should be first')
415
      ->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second');
419
      ->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second');
416
420
421
    $schema->storage->txn_rollback;
422
};
423
424
subtest 'objects.search helper with expanded authorised values' => sub {
425
    plan tests => 11;
426
417
    $schema->storage->txn_begin;
427
    $schema->storage->txn_begin;
418
}
428
429
    Koha::AuthorisedValues->search({category => 'Countries'})->delete;
430
    Koha::AuthorisedValueCategories->search({category_name =>'Countries'})->delete;
431
432
    my $cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories', value => {category_name =>'Countries'} });
433
    my $fr = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'FR', lib=>'France', category=>$cat->category_name} });
434
    my $us = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'US', lib=>'United States of America', category=>$cat->category_name} });
435
    my $ar = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'AR', lib=>'Argentina', category=>$cat->category_name} });
436
437
    my $city_class = Test::MockModule->new('Koha::City');
438
    $city_class->mock( '_fetch_authorised_values',
439
        sub {
440
            my ($self) = @_;
441
            use Koha::AuthorisedValues;
442
            my $av = Koha::AuthorisedValues->find({authorised_value => $self->city_country, category => 'Countries'});
443
            return {country => $av->unblessed};
444
        }
445
    );
446
447
    $builder->build_object({
448
        class => 'Koha::Cities',
449
        value => {
450
            city_name => 'Manuel',
451
            city_country => 'AR'
452
        }
453
    });
454
    $builder->build_object({
455
        class => 'Koha::Cities',
456
        value => {
457
            city_name => 'Manuela',
458
            city_country => 'US'
459
        }
460
    });
461
462
    $t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=starts_with' => { 'x-koha-av' => 1 })
463
        ->status_is(200)
464
        ->json_has('/0')
465
        ->json_has('/1')
466
        ->json_hasnt('/2')
467
        ->json_is('/0/name' => 'Manuel')
468
        ->json_has('/0/_authorised_values')
469
        ->json_is('/0/_authorised_values/country/lib' => $ar->lib)
470
        ->json_is('/1/name' => 'Manuela')
471
        ->json_has('/1/_authorised_values')
472
        ->json_is('/1/_authorised_values/country/lib' => $us->lib);
473
474
    $schema->storage->txn_rollback;
475
};
419
- 

Return to bug 26635