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

(-)a/t/db_dependent/Koha/Object.t (-24 / +28 lines)
Lines 30-36 use Koha::Database; Link Here
30
use Koha::DateUtils qw( dt_from_string );
30
use Koha::DateUtils qw( dt_from_string );
31
use Koha::Libraries;
31
use Koha::Libraries;
32
use Koha::Patrons;
32
use Koha::Patrons;
33
use Koha::ApiKeys;
33
use Koha::Library::Groups;
34
34
35
use Scalar::Util qw( isvstring );
35
use Scalar::Util qw( isvstring );
36
use Try::Tiny;
36
use Try::Tiny;
Lines 563-584 subtest 'store() tests' => sub { Link Here
563
563
564
    plan tests => 16;
564
    plan tests => 16;
565
565
566
    # Using Koha::ApiKey to test Koha::Object>-store
566
    # Using Koha::Library::Groups to test Koha::Object>-store
567
    # Simple object with foreign keys and unique key
567
    # Simple object with foreign keys and unique key
568
568
569
    $schema->storage->txn_begin;
569
    $schema->storage->txn_begin;
570
570
571
    # Create a patron to make sure its ID doesn't exist on the DB
571
    # Create a library to make sure its ID doesn't exist on the DB
572
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
572
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
573
    my $patron_id = $patron->id;
573
    my $branchcode = $library->branchcode;
574
    $patron->delete;
574
    $library->delete;
575
575
576
    my $api_key = Koha::ApiKey->new({ patron_id => $patron_id, secret => 'a secret', description => 'a description' });
576
    my $library_group = Koha::Library::Group->new(
577
        {
578
            branchcode      => $library->branchcode,
579
            title => 'a title',
580
        }
581
    );
577
582
578
    my $print_error = $schema->storage->dbh->{PrintError};
583
    my $print_error = $schema->storage->dbh->{PrintError};
579
    $schema->storage->dbh->{PrintError} = 0;
584
    $schema->storage->dbh->{PrintError} = 0;
580
    throws_ok
585
    throws_ok
581
        { $api_key->store }
586
        { $library_group->store }
582
        'Koha::Exceptions::Object::FKConstraint',
587
        'Koha::Exceptions::Object::FKConstraint',
583
        'Exception is thrown correctly';
588
        'Exception is thrown correctly';
584
    is(
589
    is(
Lines 588-608 subtest 'store() tests' => sub { Link Here
588
    );
593
    );
589
    is(
594
    is(
590
        $@->broken_fk,
595
        $@->broken_fk,
591
        'patron_id',
596
        'branchcode',
592
        'Exception field is correct'
597
        'Exception field is correct'
593
    );
598
    );
594
599
595
    $patron = $builder->build_object({ class => 'Koha::Patrons' });
600
    $library_group = $builder->build_object({ class => 'Koha::Library::Groups' });
596
    $api_key = $builder->build_object({ class => 'Koha::ApiKeys' });
597
601
598
    my $new_api_key = Koha::ApiKey->new({
602
    my $new_library_group = Koha::Library::Group->new(
599
        patron_id => $patron_id,
603
        {
600
        secret => $api_key->secret,
604
            branchcode      => $library_group->branchcode,
601
        description => 'a description',
605
            title        => $library_group->title,
602
    });
606
        }
607
    );
603
608
604
    throws_ok
609
    throws_ok
605
        { $new_api_key->store }
610
        { $new_library_group->store }
606
        'Koha::Exceptions::Object::DuplicateID',
611
        'Koha::Exceptions::Object::DuplicateID',
607
        'Exception is thrown correctly';
612
        'Exception is thrown correctly';
608
613
Lines 614-631 subtest 'store() tests' => sub { Link Here
614
619
615
    like(
620
    like(
616
       $@->duplicate_id,
621
       $@->duplicate_id,
617
       qr/(api_keys\.)?secret/,
622
       qr/(library_groups\.)?title/,
618
       'Exception field is correct (note that MySQL 8 is displaying the tablename)'
623
       'Exception field is correct (note that MySQL 8 is displaying the tablename)'
619
    );
624
    );
620
625
621
    $schema->storage->dbh->{PrintError} = $print_error;
626
    $schema->storage->dbh->{PrintError} = $print_error;
622
627
623
    # Successful test
628
    # Successful test
624
    $api_key->set({ secret => 'Manuel' });
629
    $library_group->set({ title => 'Manuel' });
625
    my $ret = $api_key->store;
630
    my $ret = $library_group->store;
626
    is( ref($ret), 'Koha::ApiKey', 'store() returns the object on success' );
631
    is( ref($ret), 'Koha::Library::Group', 'store() returns the object on success' );
627
632
628
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
633
    $library = $builder->build_object( { class => 'Koha::Libraries' } );
629
    my $patron_category = $builder->build_object(
634
    my $patron_category = $builder->build_object(
630
        {
635
        {
631
            class => 'Koha::Patron::Categories',
636
            class => 'Koha::Patron::Categories',
Lines 633-639 subtest 'store() tests' => sub { Link Here
633
        }
638
        }
634
    );
639
    );
635
640
636
    $patron = eval {
641
    my $patron = eval {
637
        Koha::Patron->new(
642
        Koha::Patron->new(
638
            {
643
            {
639
                categorycode    => $patron_category->categorycode,
644
                categorycode    => $patron_category->categorycode,
640
- 

Return to bug 28772