|
Lines 610-659
subtest 'store() tests' => sub {
Link Here
|
| 610 |
|
610 |
|
| 611 |
my $api_key = Koha::ApiKey->new({ patron_id => $patron_id, secret => 'a secret', description => 'a description' }); |
611 |
my $api_key = Koha::ApiKey->new({ patron_id => $patron_id, secret => 'a secret', description => 'a description' }); |
| 612 |
|
612 |
|
| 613 |
my $print_error = $schema->storage->dbh->{PrintError}; |
613 |
my $dbh = $schema->storage->dbh; |
| 614 |
$schema->storage->dbh->{PrintError} = 0; |
614 |
{ |
| 615 |
throws_ok |
615 |
local $dbh->{PrintError} = 0; |
| 616 |
{ $api_key->store } |
616 |
local $dbh->{RaiseError} = 0; |
| 617 |
'Koha::Exceptions::Object::FKConstraint', |
617 |
throws_ok |
| 618 |
'Exception is thrown correctly'; |
618 |
{ $api_key->store } |
| 619 |
is( |
619 |
'Koha::Exceptions::Object::FKConstraint', |
| 620 |
$@->message, |
620 |
'Exception is thrown correctly'; |
| 621 |
"Broken FK constraint", |
621 |
is( |
| 622 |
'Exception message is correct' |
622 |
$@->message, |
| 623 |
); |
623 |
"Broken FK constraint", |
| 624 |
is( |
624 |
'Exception message is correct' |
| 625 |
$@->broken_fk, |
625 |
); |
| 626 |
'patron_id', |
626 |
is( |
| 627 |
'Exception field is correct' |
627 |
$@->broken_fk, |
| 628 |
); |
628 |
'patron_id', |
| 629 |
|
629 |
'Exception field is correct' |
| 630 |
$patron = $builder->build_object({ class => 'Koha::Patrons' }); |
630 |
); |
| 631 |
$api_key = $builder->build_object({ class => 'Koha::ApiKeys' }); |
631 |
|
| 632 |
|
632 |
$patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 633 |
my $new_api_key = Koha::ApiKey->new({ |
633 |
$api_key = $builder->build_object({ class => 'Koha::ApiKeys' }); |
| 634 |
patron_id => $patron_id, |
634 |
|
| 635 |
secret => $api_key->secret, |
635 |
my $new_api_key = Koha::ApiKey->new({ |
| 636 |
description => 'a description', |
636 |
patron_id => $patron_id, |
| 637 |
}); |
637 |
secret => $api_key->secret, |
| 638 |
|
638 |
description => 'a description', |
| 639 |
throws_ok |
639 |
}); |
| 640 |
{ $new_api_key->store } |
|
|
| 641 |
'Koha::Exceptions::Object::DuplicateID', |
| 642 |
'Exception is thrown correctly'; |
| 643 |
|
| 644 |
is( |
| 645 |
$@->message, |
| 646 |
'Duplicate ID', |
| 647 |
'Exception message is correct' |
| 648 |
); |
| 649 |
|
| 650 |
like( |
| 651 |
$@->duplicate_id, |
| 652 |
qr/(api_keys\.)?secret/, |
| 653 |
'Exception field is correct (note that MySQL 8 is displaying the tablename)' |
| 654 |
); |
| 655 |
|
640 |
|
| 656 |
$schema->storage->dbh->{PrintError} = $print_error; |
641 |
throws_ok |
|
|
642 |
{ $new_api_key->store } |
| 643 |
'Koha::Exceptions::Object::DuplicateID', |
| 644 |
'Exception is thrown correctly'; |
| 645 |
|
| 646 |
is( |
| 647 |
$@->message, |
| 648 |
'Duplicate ID', |
| 649 |
'Exception message is correct' |
| 650 |
); |
| 651 |
|
| 652 |
like( |
| 653 |
$@->duplicate_id, |
| 654 |
qr/(api_keys\.)?secret/, |
| 655 |
'Exception field is correct (note that MySQL 8 is displaying the tablename)' |
| 656 |
); |
| 657 |
} |
| 657 |
|
658 |
|
| 658 |
# Successful test |
659 |
# Successful test |
| 659 |
$api_key->set({ secret => 'Manuel' }); |
660 |
$api_key->set({ secret => 'Manuel' }); |
|
Lines 705-722
subtest 'store() tests' => sub {
Link Here
|
| 705 |
|
706 |
|
| 706 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
707 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 707 |
|
708 |
|
| 708 |
my $print_error = $schema->storage->dbh->{PrintError}; |
|
|
| 709 |
$schema->storage->dbh->{PrintError} = 0; |
| 710 |
|
| 711 |
try { |
709 |
try { |
|
|
710 |
local $schema->storage->dbh->{RaiseError} = 0; |
| 711 |
local $schema->storage->dbh->{PrintError} = 0; |
| 712 |
$patron->lastseen('wrong_value')->store; |
712 |
$patron->lastseen('wrong_value')->store; |
| 713 |
} catch { |
713 |
} catch { |
| 714 |
ok( $_->isa('Koha::Exceptions::Object::BadValue'), 'Exception thrown correctly' ); |
714 |
ok( $_->isa('Koha::Exceptions::Object::BadValue'), 'Exception thrown correctly' ); |
| 715 |
like( $_->property, qr/(borrowers\.)?lastseen/, 'Column should be the expected one' ); # The table name is not always displayed, it depends on the DBMS version |
715 |
like( $_->property, qr/(borrowers\.)?lastseen/, 'Column should be the expected one' ); # The table name is not always displayed, it depends on the DBMS version |
| 716 |
is( $_->value, 'wrong_value', 'Value should be the expected one' ); |
716 |
is( $_->value, 'wrong_value', 'Value should be the expected one' ); |
| 717 |
}; |
717 |
}; |
| 718 |
|
|
|
| 719 |
$schema->storage->dbh->{PrintError} = $print_error; |
| 720 |
}; |
718 |
}; |
| 721 |
|
719 |
|
| 722 |
$schema->storage->txn_rollback; |
720 |
$schema->storage->txn_rollback; |
| 723 |
- |
|
|