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

(-)a/t/db_dependent/Koha/Object.t (-8 / +42 lines)
Lines 33-48 BEGIN { Link Here
33
    use_ok('Koha::Patron');
33
    use_ok('Koha::Patron');
34
}
34
}
35
35
36
my $schema = Koha::Database->new->schema;
36
my $schema  = Koha::Database->new->schema;
37
$schema->storage->txn_begin;
38
39
my $builder = t::lib::TestBuilder->new();
37
my $builder = t::lib::TestBuilder->new();
40
38
41
my $categorycode = $schema->resultset('Category')->first()->categorycode();
42
my $branchcode = $schema->resultset('Branch')->first()->branchcode();
43
44
subtest 'is_changed' => sub {
39
subtest 'is_changed' => sub {
45
    plan tests => 6;
40
    plan tests => 6;
41
42
    $schema->storage->txn_begin;
43
44
    my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
45
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
46
46
    my $object = Koha::Patron->new();
47
    my $object = Koha::Patron->new();
47
    $object->categorycode( $categorycode );
48
    $object->categorycode( $categorycode );
48
    $object->branchcode( $branchcode );
49
    $object->branchcode( $branchcode );
Lines 61-70 subtest 'is_changed' => sub { Link Here
61
    is( $object->is_changed(), 1, "Object is changed after Set" );
62
    is( $object->is_changed(), 1, "Object is changed after Set" );
62
    $object->store();
63
    $object->store();
63
    is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" );
64
    is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" );
65
66
    $schema->storage->txn_rollback;
64
};
67
};
65
68
66
subtest 'in_storage' => sub {
69
subtest 'in_storage' => sub {
67
    plan tests => 6;
70
    plan tests => 6;
71
72
    $schema->storage->txn_begin;
73
74
    my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
75
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
76
68
    my $object = Koha::Patron->new();
77
    my $object = Koha::Patron->new();
69
    is( $object->in_storage, 0, "Object is not in storage" );
78
    is( $object->in_storage, 0, "Object is not in storage" );
70
    $object->categorycode( $categorycode );
79
    $object->categorycode( $categorycode );
Lines 83-105 subtest 'in_storage' => sub { Link Here
83
    $patron = $schema->resultset('Borrower')->find( $borrowernumber );
92
    $patron = $schema->resultset('Borrower')->find( $borrowernumber );
84
    ok( ! $patron, "Object no longer found in database" );
93
    ok( ! $patron, "Object no longer found in database" );
85
    is( $object->in_storage, 0, "Object is not in storage" );
94
    is( $object->in_storage, 0, "Object is not in storage" );
95
96
    $schema->storage->txn_rollback;
86
};
97
};
87
98
88
subtest 'id' => sub {
99
subtest 'id' => sub {
89
    plan tests => 1;
100
    plan tests => 1;
101
102
    $schema->storage->txn_begin;
103
104
    my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
105
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
106
90
    my $patron = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode })->store;
107
    my $patron = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode })->store;
91
    is( $patron->id, $patron->borrowernumber );
108
    is( $patron->id, $patron->borrowernumber );
109
110
    $schema->storage->txn_rollback;
92
};
111
};
93
112
94
subtest 'get_column' => sub {
113
subtest 'get_column' => sub {
95
    plan tests => 1;
114
    plan tests => 1;
115
116
    $schema->storage->txn_begin;
117
118
    my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
119
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
120
96
    my $patron = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode })->store;
121
    my $patron = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode })->store;
97
    is( $patron->get_column('borrowernumber'), $patron->borrowernumber, 'get_column should retrieve the correct value' );
122
    is( $patron->get_column('borrowernumber'), $patron->borrowernumber, 'get_column should retrieve the correct value' );
123
124
    $schema->storage->txn_rollback;
98
};
125
};
99
126
100
subtest 'discard_changes' => sub {
127
subtest 'discard_changes' => sub {
101
    plan tests => 1;
128
    plan tests => 1;
102
    my $builder = t::lib::TestBuilder->new;
129
130
    $schema->storage->txn_begin;
131
103
    my $patron = $builder->build( { source => 'Borrower' } );
132
    my $patron = $builder->build( { source => 'Borrower' } );
104
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
133
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
105
    $patron->dateexpiry(dt_from_string);
134
    $patron->dateexpiry(dt_from_string);
Lines 109-120 subtest 'discard_changes' => sub { Link Here
109
        dt_from_string->truncate( to => 'day' ),
138
        dt_from_string->truncate( to => 'day' ),
110
        'discard_changes should refresh the object'
139
        'discard_changes should refresh the object'
111
    );
140
    );
141
142
    $schema->storage->txn_rollback;
112
};
143
};
113
144
114
subtest 'TO_JSON tests' => sub {
145
subtest 'TO_JSON tests' => sub {
115
146
116
    plan tests => 5;
147
    plan tests => 5;
117
148
149
    $schema->storage->txn_begin;
150
118
    my $borrowernumber = $builder->build(
151
    my $borrowernumber = $builder->build(
119
        { source => 'Borrower',
152
        { source => 'Borrower',
120
          value => { lost => 1,
153
          value => { lost => 1,
Lines 131-136 subtest 'TO_JSON tests' => sub { Link Here
131
    is( $gonenoaddress, 0, 'Boolean attribute value is correct (false)' );
164
    is( $gonenoaddress, 0, 'Boolean attribute value is correct (false)' );
132
165
133
    ok( !isvstring($patron->borrowernumber), 'Integer values are not coded as strings' );
166
    ok( !isvstring($patron->borrowernumber), 'Integer values are not coded as strings' );
167
168
    $schema->storage->txn_rollback;
134
};
169
};
135
170
136
171
137
- 

Return to bug 17932