Bugzilla – Attachment 178690 Details for
Bug 30657
Make patron attributes available via Template Toolkit in notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30657: Further unit tests
Bug-30657-Further-unit-tests.patch (text/plain), 4.14 KB, created by
Martin Renvoize (ashimema)
on 2025-02-25 16:41:22 UTC
(
hide
)
Description:
Bug 30657: Further unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-02-25 16:41:22 UTC
Size:
4.14 KB
patch
obsolete
>From cce07c440217c4fdd3221d40d926cf4117f4537d Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 4 Nov 2024 11:57:24 +0000 >Subject: [PATCH] Bug 30657: Further unit tests > >Test the repeatable handling and error rethrow. There's also an attempt >at counting calls to the database for subsequent attribute accessors, >but it fails in an odd way I'm struggling to understand, so that test is >commented for now >--- > t/db_dependent/Koha/Patron.t | 53 ++++++++++++++++++++++++++++++++++-- > 1 file changed, 51 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index 07cbbc3edea..6fdd5518c40 100755 >--- a/t/db_dependent/Koha/Patron.t >+++ b/t/db_dependent/Koha/Patron.t >@@ -1197,27 +1197,76 @@ subtest 'extended_attributes' => sub { > }; > > subtest 'attribute accessor tests' => sub { >- plan tests => 2; >+ plan tests => 4; > > $schema->storage->txn_begin; > >+ # Cleanup previous attribute types > Koha::Patron::Attribute::Types->search->delete; > >+ # Create a non-repeatable attribute type and a repeatable attribute type > my $attribute_type_1 = $builder->build_object( > { > class => 'Koha::Patron::Attribute::Types', > value => { code => 'smartnumber', repeatable => 0 } > } > ); >+ my $attribute_type_2 = $builder->build_object( >+ { >+ class => 'Koha::Patron::Attribute::Types', >+ value => { code => 'favbooks', repeatable => 1 } >+ } >+ ); > >+ # Create a test patron > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); > >+ # Test non-existing attribute (should return undef and not throw an error) > is( $patron->smartnumber, undef, 'smartnumber accessor returns undef when not set' ); > >+ # Test setting and retrieving a non-repeatable attribute > $patron->extended_attributes( [ { code => 'smartnumber', attribute => 'SM1234' } ] ); >- > is( $patron->smartnumber, 'SM1234', 'smartnumber accessor returns value when set' ); > >+ # Test setting and retrieving a repeatable attribute >+ $patron->extended_attributes( >+ [ >+ { code => 'favbooks', attribute => 'Book1' }, >+ { code => 'favbooks', attribute => 'Book2' } >+ ] >+ ); >+ is_deeply( >+ $patron->favbooks, [ 'Book1', 'Book2' ], >+ 'favbooks accessor returns an array of values for repeatable attribute' >+ ); >+ >+ # Test for a non-existing method to confirm it throws an error >+ throws_ok { $patron->nonexistentattribute } 'Koha::Exceptions::Object::MethodNotCoveredByTests', >+ 'Calling a non-existent attribute method throws an error'; >+ >+ # # Count DBI calls to confirm once one attribute accessor is called, we trigger AUTOLOAD again >+ # # for subsequent attribute accessor calls for any valid attribute types. >+ # # Enable DBI tracing and count search queries for attribute types >+ # my $trace_output = ''; >+ # open my $fh, '>', \$trace_output or die "Can't open scalar for writing: $!"; >+ # >+ # # Enable tracing with a callback to capture the output >+ # my $dbh = $schema->storage->dbh; >+ # $dbh->trace(0, $fh); >+ # >+ # # Call each accessor method and confirm the search call count >+ # my $refetched_patron = Koha::Patron->find( $patron->id ); >+ # $refetched_patron->smartnumber; # First access >+ # $refetched_patron->favbooks; # Access a different attribute type >+ # >+ # # Disable tracing >+ # $dbh->trace(0); >+ # >+ # # Count occurrences of the attribute types query in trace output >+ # my $search_query_count = () = $trace_output =~ /SELECT .* FROM patron_attribute_types/i; >+ # >+ # is( $search_query_count, 1, 'attributes->search is only called once per attribute type' ); >+ > $schema->storage->txn_rollback; > }; > }; >-- >2.48.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30657
:
169049
|
169050
|
169056
|
169057
|
173817
|
173818
|
173819
|
173901
|
173902
|
173910
|
173911
|
173912
|
173913
|
173914
|
178686
|
178687
|
178688
|
178689
| 178690