@@ -, +, @@ --- Koha/Object.pm | 15 +++++++++++++++ t/db_dependent/Koha/Object.t | 12 ++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) --- a/Koha/Object.pm +++ a/Koha/Object.pm @@ -375,6 +375,21 @@ sub add_message { return $self; } +=head3 $object->reset_messages + + $object->reset_messages; + +Reset the current object's messages. + +=cut + +sub reset_messages { + my ( $self ) = @_; + + $self->{_messages} = []; + return $self; +} + =head3 $object->TO_JSON Returns an unblessed representation of the object, suitable for JSON output. --- a/t/db_dependent/Koha/Object.t +++ a/t/db_dependent/Koha/Object.t @@ -868,9 +868,9 @@ subtest 'set_or_blank' => sub { $schema->storage->txn_rollback; }; -subtest 'messages() and add_message() tests' => sub { +subtest 'messages(), add_message() and reset_messages() tests' => sub { - plan tests => 6; + plan tests => 8; my $patron = Koha::Patron->new; @@ -887,4 +887,12 @@ subtest 'messages() and add_message() tests' => sub { is( ref($messages[1]), 'Koha::Object::Message', 'Right type returned' ); is( $messages[0]->message, 'message_1', 'Right message recorded' ); is( $messages[1]->message, 'message_2', 'Right message recorded' ); + + $patron->reset_messages; + @messages = @{ $patron->messages }; + is( scalar @messages, 0, 'No messages are returned' ); + + $patron->reset_messages; + @messages = @{ $patron->messages }; + is( scalar @messages, 0, 'No messages are returned, things ok when calling on already empty list' ); }; --