1 package KohaTest::Members::GetMemberDetails;
2 use base qw( KohaTest::Members );
11 sub testing_class { 'C4::Members' }
13 =head3 STARTUP METHODS
15 These are run once, before the main test methods in this module.
17 =head2 startup_create_detailed_borrower
19 Creates a new borrower to be used by the testing methods. Also
20 populates the class hash with values to be compared from the database
25 sub startup_create_detailed_borrower : Test( startup => 2 ) {
27 my ( $description, $type, $amount, $user );
30 surname => 'surname' . $self->random_string(),
31 firstname => 'firstname' . $self->random_string(),
32 address => 'address' . $self->random_string(),
33 city => 'city' . $self->random_string(),
34 cardnumber => 'card' . $self->random_string(),
37 dateexpiry => '2020-01-01',
38 password => 'testpassword',
41 dateofbirth => $self->random_date(),
44 my $borrowernumber = AddMember( %$memberinfo );
45 ok( $borrowernumber, "created member: $borrowernumber" );
46 $self->{detail_borrowernumber} = $borrowernumber;
47 $self->{detail_cardnumber} = $memberinfo->{cardnumber};
49 #values for adding a record to accounts
50 $description = 'Test account';
56 C4::Accounts::manualinvoice( $borrowernumber, undef, $description, $type, $amount,
59 ok( $acct_added == 0, 'added account for borrower' );
61 $self->{amountoutstanding} = $amount;
66 =head2 TESTING METHODS
68 =head3 borrower_detail_get
70 Tests the functionality of the GetMemberDetails method in C4::Members.
71 Validates the join on categories table works as well as the extra fields
72 the method gets from outside of either the borrowers and categories table like
73 amountoutstanding and user flags.
77 sub borrower_detail_get : Test( 8 ) {
80 ok( $self->{detail_borrowernumber},
81 'we have a valid detailed borrower to test with' );
83 my $details = C4::Members::GetMemberDetails( $self->{detail_borrowernumber} );
84 ok( $details, 'we successfully called GetMemberDetails' );
85 ok( exists $details->{categorycode},
86 'member details has a "categorycode" attribute' );
87 ok( $details->{categorycode}, '...and it is set to something' );
89 ok( exists $details->{category_type}, "categories in the join returned values" );
91 ok( $details->{category_type}, '...and category_type is valid' );
93 ok( $details->{amountoutstanding}, 'an amountoutstanding exists' );
94 is( $details->{amountoutstanding},
95 $self->{amountoutstanding},
96 '...and matches inserted account record'
101 =head3 cardnumber_detail_get
103 This method tests the capability of GetMemberDetails to search on cardnumber. There doesn't seem to be any
104 current calls to GetMemberDetail using cardnumber though, so this test may not be necessary.
108 sub cardnumber_detail_get : Test( 8 ) {
111 ok( $self->{detail_cardnumber},
112 "we have a valid detailed borrower to test with $self->{detail_cardnumber}" );
114 my $details = C4::Members::GetMemberDetails( undef, $self->{detail_cardnumber} );
115 ok( $details, 'we successfully called GetMemberDetails' );
116 ok( exists $details->{categorycode},
117 "member details has a 'categorycode' attribute $details->{categorycode}" );
118 ok( $details->{categorycode}, '...and it is set to something' );
120 ok( exists $details->{category_type}, "categories in the join returned values" );
122 ok( $details->{category_type}, '...and category_type is valid' );
124 #FIXME These 2 methods will fail as borrowernumber is not set in GetMemberDetails when cardnumber is used instead.
125 #ok( $details->{amountoutstanding}, 'an amountoutstanding exists' );
126 #is( $details->{amountoutstanding}, $self->{amountoutstanding}, '...and matches inserted account record' );
129 =head2 SHUTDOWN METHDOS
131 These get run once, after the main test methods in this module.
133 =head3 shutdown_remove_new_borrower
135 Removes references in the Class to the new borrower created
136 in the startup methods.
140 sub shutdown_remove_new_borrower : Test( shutdown => 0 ) {
143 delete $self->{detail_borrowernumber};
144 delete $self->{detail_cardnumber};
145 delete $self->{amountoutstanding};