| Lines 19-25
          
      
      
        Link Here | 
        
          | 19 |  | 19 |  | 
        
          | 20 | use Modern::Perl; | 20 | use Modern::Perl; | 
        
          | 21 |  | 21 |  | 
          
            
              | 22 | use Test::More tests => 2; | 22 | use Test::More tests => 3; | 
        
          | 23 |  | 23 |  | 
        
          | 24 | use t::lib::Mocks; | 24 | use t::lib::Mocks; | 
        
          | 25 | use t::lib::TestBuilder; | 25 | use t::lib::TestBuilder; | 
  
    | Lines 99-104
          subtest 'Test Koha::Patron::Message::Preferences' => sub {
      
      
        Link Here | 
        
          | 99 |     $schema->storage->txn_rollback; | 99 |     $schema->storage->txn_rollback; | 
        
          | 100 | }; | 100 | }; | 
        
          | 101 |  | 101 |  | 
            
              |  |  | 102 | subtest 'Test adding a new preference with invalid parameters' => sub { | 
            
              | 103 |     plan tests => 3; | 
            
              | 104 |  | 
            
              | 105 |     subtest 'Missing parameters' => sub { | 
            
              | 106 |         plan tests => 1; | 
            
              | 107 |  | 
            
              | 108 |         eval { Koha::Patron::Message::Preference->new->store }; | 
            
              | 109 |         is(ref $@, 'Koha::Exceptions::MissingParameter', | 
            
              | 110 |             'Adding a message preference without parameters' | 
            
              | 111 |             .' => Koha::Exceptions::MissingParameter'); | 
            
              | 112 |     }; | 
            
              | 113 |  | 
            
              | 114 |     subtest 'Too many parameters' => sub { | 
            
              | 115 |         plan tests => 1; | 
            
              | 116 |  | 
            
              | 117 |         $schema->storage->txn_begin; | 
            
              | 118 |  | 
            
              | 119 |         my $patron = build_a_test_patron(); | 
            
              | 120 |         eval { Koha::Patron::Message::Preference->new({ | 
            
              | 121 |             borrowernumber => $patron->borrowernumber, | 
            
              | 122 |             categorycode   => $patron->categorycode, | 
            
              | 123 |         })->store }; | 
            
              | 124 |         is(ref $@, 'Koha::Exceptions::TooManyParameters', | 
            
              | 125 |             'Adding a message preference for both borrowernumber and categorycode' | 
            
              | 126 |             .' => Koha::Exceptions::TooManyParameters'); | 
            
              | 127 |  | 
            
              | 128 |         $schema->storage->txn_rollback; | 
            
              | 129 |     }; | 
            
              | 130 |  | 
            
              | 131 |     subtest 'Bad parameter' => sub { | 
            
              | 132 |         plan tests => 8; | 
            
              | 133 |  | 
            
              | 134 |         $schema->storage->txn_begin; | 
            
              | 135 |  | 
            
              | 136 |         eval { Koha::Patron::Message::Preference->new({ | 
            
              | 137 |                 borrowernumber => -999, | 
            
              | 138 |             })->store }; | 
            
              | 139 |         is(ref $@, 'Koha::Exceptions::BadParameter', | 
            
              | 140 |             'Adding a message preference with invalid borrowernumber' | 
            
              | 141 |             .' => Koha::Exceptions::BadParameter'); | 
            
              | 142 |         is ($@->parameter, 'borrowernumber', 'The previous exception tells us it' | 
            
              | 143 |             .' was the borrowernumber.'); | 
            
              | 144 |  | 
            
              | 145 |         eval { Koha::Patron::Message::Preference->new({ | 
            
              | 146 |                 categorycode => 'nonexistent', | 
            
              | 147 |             })->store }; | 
            
              | 148 |         is(ref $@, 'Koha::Exceptions::BadParameter', | 
            
              | 149 |             'Adding a message preference with invalid categorycode' | 
            
              | 150 |             .' => Koha::Exceptions::BadParameter'); | 
            
              | 151 |         is($@->parameter, 'categorycode', 'The previous exception tells us it' | 
            
              | 152 |             .' was the categorycode.'); | 
            
              | 153 |  | 
            
              | 154 |         my $attribute = build_a_test_attribute({ takes_days => 0 }); | 
            
              | 155 |         my $patron    = build_a_test_patron(); | 
            
              | 156 |         eval { Koha::Patron::Message::Preference->new({ | 
            
              | 157 |                 borrowernumber => $patron->borrowernumber, | 
            
              | 158 |                 message_attribute_id => $attribute->message_attribute_id, | 
            
              | 159 |                 days_in_advance => 10, | 
            
              | 160 |             })->store }; | 
            
              | 161 |         is(ref $@, 'Koha::Exceptions::BadParameter', | 
            
              | 162 |             'Adding a message preference with days in advance option when not' | 
            
              | 163 |             .' available => Koha::Exceptions::BadParameter'); | 
            
              | 164 |         is($@->parameter, 'days_in_advance', 'The previous exception tells us it' | 
            
              | 165 |             .' was the days_in_advance.'); | 
            
              | 166 |  | 
            
              | 167 |         $attribute->set({ takes_days => 1 })->store; | 
            
              | 168 |         eval { Koha::Patron::Message::Preference->new({ | 
            
              | 169 |                 borrowernumber => $patron->borrowernumber, | 
            
              | 170 |                 message_attribute_id => $attribute->message_attribute_id, | 
            
              | 171 |                 days_in_advance => 31, | 
            
              | 172 |             })->store }; | 
            
              | 173 |         is(ref $@, 'Koha::Exceptions::BadParameter', | 
            
              | 174 |             'Adding a message preference with days in advance option too large' | 
            
              | 175 |             .' => Koha::Exceptions::BadParameter'); | 
            
              | 176 |         is($@->parameter, 'days_in_advance', 'The previous exception tells us it' | 
            
              | 177 |             .' was the days_in_advance.'); | 
            
              | 178 |  | 
            
              | 179 |         $schema->storage->txn_rollback; | 
            
              | 180 |     }; | 
            
              | 181 | }; | 
            
              | 182 |  | 
        
          | 102 | sub build_a_test_attribute { | 183 | sub build_a_test_attribute { | 
        
          | 103 |     my ($params) = @_; | 184 |     my ($params) = @_; | 
        
          | 104 |  | 185 |  | 
            
              | 105 | -  |  |  |