| Lines 360-382
          HERE
      
      
        Link Here | 
        
          | 360 |         eval { | 360 |         eval { | 
        
          | 361 |             $preference->message_transport_types('email')->store; | 361 |             $preference->message_transport_types('email')->store; | 
        
          | 362 |         }; | 362 |         }; | 
          
            
              | 363 |         is (ref $@, 'Koha::Exceptions::BadParameter', | 363 |         is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired', | 
        
          | 364 |             'Adding a message preference with invalid message_transport_type' | 364 |             'Adding a message preference with invalid message_transport_type' | 
          
            
              | 365 |             .' => Koha::Exceptions::BadParameter'); | 365 |             .' => Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired'); | 
            
              | 366 |         is ($@->parameter, 'message_transport_types', 'The previous exception ' | 366 |         is ($@->message_name, $preference->message_name, 'The previous exception ' | 
            
              | 367 |             .' tells us it was the message_transport_types'); | 367 |             .' tells us it which message name it was.'); | 
            
              | 368 |         like ($@->error, qr/^Patron has not set email address/, 'Exception ' | 368 |         is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' | 
            
              | 369 |             .' is because of patron has not set email address.'); | 369 |             .' tells us which patron it was.'); | 
        
          | 370 |         eval { | 370 |         eval { | 
        
          | 371 |             $preference->message_transport_types('sms')->store; | 371 |             $preference->message_transport_types('sms')->store; | 
        
          | 372 |         }; | 372 |         }; | 
          
            
              | 373 |         is (ref $@, 'Koha::Exceptions::BadParameter', | 373 |         is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired', | 
        
          | 374 |             'Adding a message preference with invalid message_transport_type' | 374 |             'Adding a message preference with invalid message_transport_type' | 
          
            
              | 375 |             .' => Koha::Exceptions::BadParameter'); | 375 |             .' => Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired'); | 
            
              | 376 |         is ($@->parameter, 'message_transport_types', 'The previous exception ' | 376 |         is ($@->message_name, $preference->message_name, 'The previous exception ' | 
            
              | 377 |             .' tells us it was the message_transport_types'); | 377 |             .' tells us it which message name it was.'); | 
            
              | 378 |         like ($@->error, qr/^Patron has not set sms number/, 'Exception ' | 378 |         is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' | 
            
              | 379 |             .' is because of patron has not set sms number.'); | 379 |             .' tells us which patron it was.'); | 
        
          | 380 |  | 380 |  | 
        
          | 381 |         $schema->storage->txn_rollback; | 381 |         $schema->storage->txn_rollback; | 
        
          | 382 |     }; | 382 |     }; | 
  
    | Lines 466-492
          subtest 'Test adding a new preference with invalid parameters' => sub {
      
      
        Link Here | 
        
          | 466 |     }; | 466 |     }; | 
        
          | 467 |  | 467 |  | 
        
          | 468 |     subtest 'Bad parameter' => sub { | 468 |     subtest 'Bad parameter' => sub { | 
          
            
              | 469 |         plan tests => 22; | 469 |         plan tests => 18; | 
        
          | 470 |  | 470 |  | 
        
          | 471 |         $schema->storage->txn_begin; | 471 |         $schema->storage->txn_begin; | 
        
          | 472 |  | 472 |  | 
        
          | 473 |         eval { Koha::Patron::Message::Preference->new({ | 473 |         eval { Koha::Patron::Message::Preference->new({ | 
        
          | 474 |                 borrowernumber => -999, | 474 |                 borrowernumber => -999, | 
        
          | 475 |             })->store }; | 475 |             })->store }; | 
          
            
              | 476 |         is(ref $@, 'Koha::Exceptions::BadParameter', | 476 |         is(ref $@, 'Koha::Exceptions::Patron::NotFound', | 
        
          | 477 |             'Adding a message preference with invalid borrowernumber' | 477 |             'Adding a message preference with invalid borrowernumber' | 
          
            
              | 478 |             .' => Koha::Exceptions::BadParameter'); | 478 |             .' => Koha::Exceptions::Patron::NotFound'); | 
            
              | 479 |         is ($@->parameter, 'borrowernumber', 'The previous exception tells us it' |  |  | 
            
              | 480 |             .' was the borrowernumber.'); | 
        
          | 481 |  | 479 |  | 
        
          | 482 |         eval { Koha::Patron::Message::Preference->new({ | 480 |         eval { Koha::Patron::Message::Preference->new({ | 
        
          | 483 |                 categorycode => 'nonexistent', | 481 |                 categorycode => 'nonexistent', | 
        
          | 484 |             })->store }; | 482 |             })->store }; | 
          
            
              | 485 |         is(ref $@, 'Koha::Exceptions::BadParameter', | 483 |         is(ref $@, 'Koha::Exceptions::Patron::Category::NotFound', | 
        
          | 486 |             'Adding a message preference with invalid categorycode' | 484 |             'Adding a message preference with invalid categorycode' | 
          
            
              | 487 |             .' => Koha::Exceptions::BadParameter'); | 485 |             .' => Koha::Exceptions::Patron::Category::NotFound'); | 
            
              | 488 |         is($@->parameter, 'categorycode', 'The previous exception tells us it' |  |  | 
            
              | 489 |             .' was the categorycode.'); | 
        
          | 490 |  | 486 |  | 
        
          | 491 |         my $attribute = build_a_test_attribute({ takes_days => 0 }); | 487 |         my $attribute = build_a_test_attribute({ takes_days => 0 }); | 
        
          | 492 |         my $patron    = $builder->build_object({ class => 'Koha::Patrons' }); | 488 |         my $patron    = $builder->build_object({ class => 'Koha::Patrons' }); | 
  
    | Lines 495-527
          subtest 'Test adding a new preference with invalid parameters' => sub {
      
      
        Link Here | 
        
          | 495 |                 message_attribute_id => $attribute->message_attribute_id, | 491 |                 message_attribute_id => $attribute->message_attribute_id, | 
        
          | 496 |                 days_in_advance => 10, | 492 |                 days_in_advance => 10, | 
        
          | 497 |             })->store }; | 493 |             })->store }; | 
          
            
              | 498 |         is(ref $@, 'Koha::Exceptions::BadParameter', | 494 |         is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable', | 
        
          | 499 |             'Adding a message preference with days in advance option when not' | 495 |             'Adding a message preference with days in advance option when not' | 
          
            
              | 500 |             .' available => Koha::Exceptions::BadParameter'); | 496 |             .' available => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable'); | 
            
              | 501 |         is($@->parameter, 'days_in_advance', 'The previous exception tells us it' |  |  | 
            
              | 502 |             .' was the days_in_advance.'); | 
        
          | 503 |  | 497 |  | 
        
          | 504 |         $attribute->set({ takes_days => 1 })->store; | 498 |         $attribute->set({ takes_days => 1 })->store; | 
            
              |  |  | 499 |         eval { Koha::Patron::Message::Preference->new({ | 
            
              | 500 |                 borrowernumber => $patron->borrowernumber, | 
            
              | 501 |                 message_attribute_id => $attribute->message_attribute_id, | 
            
              | 502 |                 days_in_advance => -1, | 
            
              | 503 |             })->store }; | 
            
              | 504 |         is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange', | 
            
              | 505 |             'Adding a message preference with days in advance option is out of range' | 
            
              | 506 |             .' => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange'); | 
            
              | 507 |         is ($@->min, 0, 'The previous exception min value is 0.'); | 
            
              | 508 |  | 
        
          | 505 |         eval { Koha::Patron::Message::Preference->new({ | 509 |         eval { Koha::Patron::Message::Preference->new({ | 
        
          | 506 |                 borrowernumber => $patron->borrowernumber, | 510 |                 borrowernumber => $patron->borrowernumber, | 
        
          | 507 |                 message_attribute_id => $attribute->message_attribute_id, | 511 |                 message_attribute_id => $attribute->message_attribute_id, | 
        
          | 508 |                 days_in_advance => 31, | 512 |                 days_in_advance => 31, | 
        
          | 509 |             })->store }; | 513 |             })->store }; | 
          
            
              | 510 |         is(ref $@, 'Koha::Exceptions::BadParameter', | 514 |         is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange', | 
            
              | 511 |             'Adding a message preference with days in advance option too large' | 515 |             'Adding a message preference with days in advance option is out of range' | 
            
              | 512 |             .' => Koha::Exceptions::BadParameter'); | 516 |             .' => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange'); | 
            
              | 513 |         is($@->parameter, 'days_in_advance', 'The previous exception tells us it' | 517 |         is ($@->max, 30, 'The previous exception max value is 30.'); | 
            
              | 514 |             .' was the days_in_advance.'); |  |  | 
        
          | 515 |  | 518 |  | 
        
          | 516 |         eval { Koha::Patron::Message::Preference->new({ | 519 |         eval { Koha::Patron::Message::Preference->new({ | 
        
          | 517 |                 borrowernumber => $patron->borrowernumber, | 520 |                 borrowernumber => $patron->borrowernumber, | 
        
          | 518 |                 message_transport_types => ['nonexistent'] | 521 |                 message_transport_types => ['nonexistent'] | 
        
          | 519 |             })->store }; | 522 |             })->store }; | 
          
            
              | 520 |         is (ref $@, 'Koha::Exceptions::BadParameter', | 523 |         is (ref $@, 'Koha::Exceptions::Patron::Message::Transport::TypeNotFound', | 
        
          | 521 |             'Adding a message preference with invalid message_transport_type' | 524 |             'Adding a message preference with invalid message_transport_type' | 
          
            
              | 522 |             .' => Koha::Exceptions::BadParameter'); | 525 |             .' => Koha::Exceptions::Patron::Message::Transport::TypeNotFound'); | 
            
              | 523 |         is ($@->parameter, 'message_transport_types', 'The previous exception ' | 526 |         is ($@->transport_type, 'nonexistent', 'The previous exception ' | 
            
              | 524 |             .'tells us it was the message_transport_types.'); | 527 |             .'tells us it which transport type it was.'); | 
        
          | 525 |  | 528 |  | 
        
          | 526 |         my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); | 529 |         my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); | 
        
          | 527 |         eval { | 530 |         eval { | 
  
    | Lines 531-543
          subtest 'Test adding a new preference with invalid parameters' => sub {
      
      
        Link Here | 
        
          | 531 |                 message_transport_types => [$mtt_new->message_transport_type], | 534 |                 message_transport_types => [$mtt_new->message_transport_type], | 
        
          | 532 |                 wants_digest => 1, | 535 |                 wants_digest => 1, | 
        
          | 533 |             })->store }; | 536 |             })->store }; | 
          
            
              | 534 |         is (ref $@, 'Koha::Exceptions::BadParameter', | 537 |         is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::NoTransportType', | 
        
          | 535 |             'Adding a message preference with invalid message_transport_type' | 538 |             'Adding a message preference with invalid message_transport_type' | 
          
            
              | 536 |            .' => Koha::Exceptions::BadParameter'); | 539 |            .' => Koha::Exceptions::Patron::Message::Preference::NoTransportType'); | 
            
              | 537 |         is ($@->parameter, 'message_transport_types', 'The previous exception ' | 540 |         is ($@->message_name, $attribute->message_name, 'The previous exception ' | 
            
              | 538 |             .'tells us it was the message_transport_types.'); | 541 |             .'tells us which message it was.'); | 
            
              | 539 |         like ($@->error, qr/^No transport configured/, 'Exception is because of ' | 542 |         is ($@->transport_type, $mtt_new->message_transport_type, 'The previous exception ' | 
            
              | 540 |             .'given message_transport_type is not a valid option.'); | 543 |             .'tells us which message transport type it was.'); | 
        
          | 541 |  | 544 |  | 
        
          | 542 |         eval { | 545 |         eval { | 
        
          | 543 |             Koha::Patron::Message::Preference->new({ | 546 |             Koha::Patron::Message::Preference->new({ | 
  
    | Lines 546-558
          subtest 'Test adding a new preference with invalid parameters' => sub {
      
      
        Link Here | 
        
          | 546 |                 message_transport_types => [], | 549 |                 message_transport_types => [], | 
        
          | 547 |                 wants_digest => 1, | 550 |                 wants_digest => 1, | 
        
          | 548 |             })->store }; | 551 |             })->store }; | 
          
            
              | 549 |         is (ref $@, 'Koha::Exceptions::BadParameter', | 552 |         is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable', | 
            
              | 550 |             'Adding a message preference with invalid message_transport_type' | 553 |             'Adding a message preference that has no digest setting' | 
            
              | 551 |             .' => Koha::Exceptions::BadParameter'); | 554 |             .' => Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable'); | 
            
              | 552 |         is ($@->parameter, 'wants_digest', 'The previous exception tells us it' | 555 |         is ($@->message_name, $attribute->message_name, 'The previous exception tells us' | 
            
              | 553 |             .' was the wants_digest'); | 556 |             .' which message it was'); | 
            
              | 554 |         like ($@->error, qr/^Digest cannot be selected/, 'Exception s because of' |  |  | 
            
              | 555 |             .' given digest is not available for this transport.'); | 
        
          | 556 |  | 557 |  | 
        
          | 557 |         eval { | 558 |         eval { | 
        
          | 558 |             Koha::Patron::Message::Preference->new({ | 559 |             Koha::Patron::Message::Preference->new({ | 
  
    | Lines 561-587
          subtest 'Test adding a new preference with invalid parameters' => sub {
      
      
        Link Here | 
        
          | 561 |                 message_transport_types => [], | 562 |                 message_transport_types => [], | 
        
          | 562 |                 wants_digest => 0, | 563 |                 wants_digest => 0, | 
        
          | 563 |             })->store }; | 564 |             })->store }; | 
          
            
              | 564 |         is (ref $@, 'Koha::Exceptions::BadParameter', | 565 |         is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::DigestRequired', | 
            
              | 565 |             'Adding a message preference with invalid message_transport_type' | 566 |             'Adding a message preference, that requires digest, with no digest' | 
            
              | 566 |             .' => Koha::Exceptions::BadParameter'); | 567 |             .' => Koha::Exceptions::Patron::Message::Preference::DigestRequired'); | 
            
              | 567 |         is ($@->parameter, 'wants_digest', 'The previous exception tells us it' | 568 |         is ($@->message_name, $attribute->message_name, 'The previous exception tells us' | 
            
              | 568 |             .' was the wants_digest'); | 569 |             .' which message it was'); | 
            
              | 569 |         like ($@->error, qr/^Digest must be selected/, 'Exception s because of' |  |  | 
            
              | 570 |             .' digest has to be on for this transport.'); | 
            
              | 571 |  | 
        
          | 572 |         eval { | 570 |         eval { | 
        
          | 573 |             Koha::Patron::Message::Preference->new({ | 571 |             Koha::Patron::Message::Preference->new({ | 
        
          | 574 |                 borrowernumber => $patron->borrowernumber, | 572 |                 borrowernumber => $patron->borrowernumber, | 
        
          | 575 |                 message_attribute_id => -1, | 573 |                 message_attribute_id => -1, | 
        
          | 576 |                 message_transport_types => [], | 574 |                 message_transport_types => [], | 
        
          | 577 |             })->store }; | 575 |             })->store }; | 
          
            
              | 578 |         is (ref $@, 'Koha::Exceptions::BadParameter', | 576 |         is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::AttributeNotFound', | 
        
          | 579 |             'Adding a message preference with invalid message_transport_type' | 577 |             'Adding a message preference with invalid message_transport_type' | 
          
            
              | 580 |             .' => Koha::Exceptions::BadParameter'); | 578 |             .' => KKoha::Exceptions::Patron::Message::Preference::AttributeNotFound'); | 
            
              | 581 |         is ($@->parameter, 'message_attribute_id', 'The previous exception tells' | 579 |         is ($@->message_attribute_id, -1, 'The previous exception tells' | 
            
              | 582 |             .' us it was the message_attribute_id'); | 580 |             .' us which message attribute id it was.'); | 
            
              | 583 |         like ($@->error, qr/^Message attribute with id -1 not found/, 'Exception ' |  |  | 
            
              | 584 |             .' is because of given message attribute id is not found.'); | 
        
          | 585 |  | 581 |  | 
        
          | 586 |         $schema->storage->txn_rollback; | 582 |         $schema->storage->txn_rollback; | 
        
          | 587 |     }; | 583 |     }; | 
            
              | 588 | -  |  |  |