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

(-)a/t/db_dependent/Koha/Object.t (-23 / +29 lines)
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::Cash::Register 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 $cash_register = Koha::Cash::Register->new(
642
        {
643
            branch      => $library->branchcode,
644
            name        => 'a cash register',
645
            description => 'a description',
646
        }
647
    );
642
648
643
    my $dbh = $schema->storage->dbh;
649
    my $dbh = $schema->storage->dbh;
644
    {
650
    {
645
        local *STDERR;
651
        local *STDERR;
646
        open STDERR, '>', '/dev/null';
652
        open STDERR, '>', '/dev/null';
647
        throws_ok
653
        throws_ok
648
            { $api_key->store }
654
            { $cash_register->store }
649
            'Koha::Exceptions::Object::FKConstraint',
655
            'Koha::Exceptions::Object::FKConstraint',
650
            'Exception is thrown correctly';
656
            'Exception is thrown correctly';
651
        is(
657
        is(
Lines 655-675 subtest 'store() tests' => sub { Link Here
655
        );
661
        );
656
        is(
662
        is(
657
            $@->broken_fk,
663
            $@->broken_fk,
658
            'patron_id',
664
            'branch',
659
            'Exception field is correct'
665
            'Exception field is correct'
660
        );
666
        );
661
667
662
        $patron = $builder->build_object({ class => 'Koha::Patrons' });
668
        $cash_register = $builder->build_object({ class => 'Koha::Cash::Registers' });
663
        $api_key = $builder->build_object({ class => 'Koha::ApiKeys' });
664
669
665
        my $new_api_key = Koha::ApiKey->new({
670
        my $new_cash_register = Koha::Cash::Register->new(
666
            patron_id => $patron_id,
671
            {
667
            secret => $api_key->secret,
672
                branch      => $cash_register->branch,
668
            description => 'a description',
673
                name        => $cash_register->name,
669
        });
674
                description => 'a description',
675
            }
676
        );
670
677
671
        throws_ok
678
        throws_ok
672
            { $new_api_key->store }
679
            { $new_cash_register->store }
673
            'Koha::Exceptions::Object::DuplicateID',
680
            'Koha::Exceptions::Object::DuplicateID',
674
            'Exception is thrown correctly';
681
            'Exception is thrown correctly';
675
682
Lines 681-698 subtest 'store() tests' => sub { Link Here
681
688
682
        like(
689
        like(
683
           $@->duplicate_id,
690
           $@->duplicate_id,
684
           qr/(api_keys\.)?secret/,
691
           qr/(cash_register\.)?name/,
685
           'Exception field is correct (note that MySQL 8 is displaying the tablename)'
692
           'Exception field is correct (note that MySQL 8 is displaying the tablename)'
686
        );
693
        );
687
        close STDERR;
694
        close STDERR;
688
    }
695
    }
689
696
690
    # Successful test
697
    # Successful test
691
    $api_key->set({ secret => 'Manuel' });
698
    $cash_register->set({ name => 'Manuel' });
692
    my $ret = $api_key->store;
699
    my $ret = $cash_register->store;
693
    is( ref($ret), 'Koha::ApiKey', 'store() returns the object on success' );
700
    is( ref($ret), 'Koha::Cash::Register', 'store() returns the object on success' );
694
701
695
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
702
    $library = $builder->build_object( { class => 'Koha::Libraries' } );
696
    my $patron_category = $builder->build_object(
703
    my $patron_category = $builder->build_object(
697
        {
704
        {
698
            class => 'Koha::Patron::Categories',
705
            class => 'Koha::Patron::Categories',
Lines 700-706 subtest 'store() tests' => sub { Link Here
700
        }
707
        }
701
    );
708
    );
702
709
703
    $patron = eval {
710
    my $patron = eval {
704
        Koha::Patron->new(
711
        Koha::Patron->new(
705
            {
712
            {
706
                categorycode    => $patron_category->categorycode,
713
                categorycode    => $patron_category->categorycode,
707
- 

Return to bug 28772