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

(-)a/t/db_dependent/Koha/Object.t (-24 / +28 lines)
Lines 32-38 use Koha::Acquisition::Orders; Link Here
32
use Koha::DateUtils qw( dt_from_string );
32
use Koha::DateUtils qw( dt_from_string );
33
use Koha::Libraries;
33
use Koha::Libraries;
34
use Koha::Patrons;
34
use Koha::Patrons;
35
use Koha::ApiKeys;
35
use Koha::Library::Groups;
36
36
37
use JSON;
37
use JSON;
38
use Scalar::Util qw( isvstring );
38
use Scalar::Util qw( isvstring );
Lines 628-651 subtest 'store() tests' => sub { Link Here
628
628
629
    plan tests => 16;
629
    plan tests => 16;
630
630
631
    # Using Koha::ApiKey to test Koha::Object>-store
631
    # Using Koha::Library::Groups to test Koha::Object>-store
632
    # Simple object with foreign keys and unique key
632
    # Simple object with foreign keys and unique key
633
633
634
    $schema->storage->txn_begin;
634
    $schema->storage->txn_begin;
635
635
636
    # Create a patron to make sure its ID doesn't exist on the DB
636
    # Create a library to make sure its ID doesn't exist on the DB
637
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
637
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
638
    my $patron_id = $patron->id;
638
    my $branchcode = $library->branchcode;
639
    $patron->delete;
639
    $library->delete;
640
640
641
    my $api_key = Koha::ApiKey->new({ patron_id => $patron_id, secret => 'a secret', description => 'a description' });
641
    my $library_group = Koha::Library::Group->new(
642
        {
643
            branchcode      => $library->branchcode,
644
            title => 'a title',
645
        }
646
    );
642
647
643
    my $dbh = $schema->storage->dbh;
648
    my $dbh = $schema->storage->dbh;
644
    {
649
    {
645
        local *STDERR;
650
        local *STDERR;
646
        open STDERR, '>', '/dev/null';
651
        open STDERR, '>', '/dev/null';
647
        throws_ok
652
        throws_ok
648
            { $api_key->store }
653
            { $library_group->store }
649
            'Koha::Exceptions::Object::FKConstraint',
654
            'Koha::Exceptions::Object::FKConstraint',
650
            'Exception is thrown correctly';
655
            'Exception is thrown correctly';
651
        is(
656
        is(
Lines 655-675 subtest 'store() tests' => sub { Link Here
655
        );
660
        );
656
        is(
661
        is(
657
            $@->broken_fk,
662
            $@->broken_fk,
658
            'patron_id',
663
            'branchcode',
659
            'Exception field is correct'
664
            'Exception field is correct'
660
        );
665
        );
661
666
662
        $patron = $builder->build_object({ class => 'Koha::Patrons' });
667
        $library_group = $builder->build_object({ class => 'Koha::Library::Groups' });
663
        $api_key = $builder->build_object({ class => 'Koha::ApiKeys' });
664
668
665
        my $new_api_key = Koha::ApiKey->new({
669
        my $new_library_group = Koha::Library::Group->new(
666
            patron_id => $patron_id,
670
            {
667
            secret => $api_key->secret,
671
                branchcode      => $library_group->branchcode,
668
            description => 'a description',
672
                title        => $library_group->title,
669
        });
673
            }
674
        );
670
675
671
        throws_ok
676
        throws_ok
672
            { $new_api_key->store }
677
            { $new_library_group->store }
673
            'Koha::Exceptions::Object::DuplicateID',
678
            'Koha::Exceptions::Object::DuplicateID',
674
            'Exception is thrown correctly';
679
            'Exception is thrown correctly';
675
680
Lines 681-698 subtest 'store() tests' => sub { Link Here
681
686
682
        like(
687
        like(
683
           $@->duplicate_id,
688
           $@->duplicate_id,
684
           qr/(api_keys\.)?secret/,
689
           qr/(library_groups\.)?title/,
685
           'Exception field is correct (note that MySQL 8 is displaying the tablename)'
690
           'Exception field is correct (note that MySQL 8 is displaying the tablename)'
686
        );
691
        );
687
        close STDERR;
692
        close STDERR;
688
    }
693
    }
689
694
690
    # Successful test
695
    # Successful test
691
    $api_key->set({ secret => 'Manuel' });
696
    $library_group->set({ title => 'Manuel' });
692
    my $ret = $api_key->store;
697
    my $ret = $library_group->store;
693
    is( ref($ret), 'Koha::ApiKey', 'store() returns the object on success' );
698
    is( ref($ret), 'Koha::Library::Group', 'store() returns the object on success' );
694
699
695
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
700
    $library = $builder->build_object( { class => 'Koha::Libraries' } );
696
    my $patron_category = $builder->build_object(
701
    my $patron_category = $builder->build_object(
697
        {
702
        {
698
            class => 'Koha::Patron::Categories',
703
            class => 'Koha::Patron::Categories',
Lines 700-706 subtest 'store() tests' => sub { Link Here
700
        }
705
        }
701
    );
706
    );
702
707
703
    $patron = eval {
708
    my $patron = eval {
704
        Koha::Patron->new(
709
        Koha::Patron->new(
705
            {
710
            {
706
                categorycode    => $patron_category->categorycode,
711
                categorycode    => $patron_category->categorycode,
707
- 

Return to bug 28772