| Lines 39-54
          subtest 'Koha::AdditionalContents basic test' => sub {
      
      
        Link Here | 
        
          | 39 |  | 39 |  | 
        
          | 40 |     my $library = $builder->build({ source => 'Branch'}); | 40 |     my $library = $builder->build({ source => 'Branch'}); | 
        
          | 41 |     my $nb_of_news = Koha::AdditionalContents->search->count; | 41 |     my $nb_of_news = Koha::AdditionalContents->search->count; | 
          
            
              | 42 |     my $new_news_item_1 = Koha::AdditionalContent->new({ | 42 |     my $new_news_item_1 = Koha::AdditionalContent->new( | 
            
              | 43 |         branchcode => $library->{branchcode}, | 43 |         { | 
            
              | 44 |         title => 'a news', | 44 |             category   => 'news', | 
            
              | 45 |         content => 'content for news 1', | 45 |             code       => 'news_1', | 
            
              | 46 |     })->store; | 46 |             location   => 'staff_only', | 
            
              | 47 |     my $new_news_item_2 = Koha::AdditionalContent->new({ | 47 |             branchcode => $library->{branchcode}, | 
            
              | 48 |         branchcode => $library->{branchcode}, | 48 |             title      => 'a news', | 
            
              | 49 |         title => 'another news', | 49 |             content    => 'content for news 1', | 
            
              | 50 |         content => 'content for news 2', | 50 |         } | 
            
              | 51 |     })->store; | 51 |     )->store; | 
            
              |  |  | 52 |     my $new_news_item_2 = Koha::AdditionalContent->new( | 
            
              | 53 |         { | 
            
              | 54 |             category   => 'news', | 
            
              | 55 |             code       => 'news_2', | 
            
              | 56 |             location   => 'staff_only', | 
            
              | 57 |             branchcode => $library->{branchcode}, | 
            
              | 58 |             title      => 'another news', | 
            
              | 59 |             content    => 'content for news 2', | 
            
              | 60 |         } | 
            
              | 61 |     )->store; | 
        
          | 52 |  | 62 |  | 
        
          | 53 |     like( $new_news_item_1->idnew, qr|^\d+$|, 'Adding a new news_item should have set the idnew'); | 63 |     like( $new_news_item_1->idnew, qr|^\d+$|, 'Adding a new news_item should have set the idnew'); | 
        
          | 54 |     is( Koha::AdditionalContents->search->count, $nb_of_news + 2, 'The 2 news should have been added' ); | 64 |     is( Koha::AdditionalContents->search->count, $nb_of_news + 2, 'The 2 news should have been added' ); | 
  
    | Lines 130-135
          subtest '->library' => sub {
      
      
        Link Here | 
        
          | 130 | subtest '->author' => sub { | 140 | subtest '->author' => sub { | 
        
          | 131 |     plan tests => 3; | 141 |     plan tests => 3; | 
        
          | 132 |  | 142 |  | 
            
              |  |  | 143 |     $schema->storage->txn_begin; | 
            
              | 144 |  | 
        
          | 133 |     my $news_item = $builder->build_object({ class => 'Koha::AdditionalContents' }); | 145 |     my $news_item = $builder->build_object({ class => 'Koha::AdditionalContents' }); | 
        
          | 134 |     my $author = $news_item->author; | 146 |     my $author = $news_item->author; | 
        
          | 135 |     is( ref($author), 'Koha::Patron', 'Koha::AdditionalContent->author returns a Koha::Patron object' ); | 147 |     is( ref($author), 'Koha::Patron', 'Koha::AdditionalContent->author returns a Koha::Patron object' ); | 
  
    | Lines 139-149
          subtest '->author' => sub {
      
      
        Link Here | 
        
          | 139 |     $news_item = Koha::AdditionalContents->find($news_item->idnew); | 151 |     $news_item = Koha::AdditionalContents->find($news_item->idnew); | 
        
          | 140 |     is( ref($news_item), 'Koha::AdditionalContent', 'News are not deleted alongwith the author' ); | 152 |     is( ref($news_item), 'Koha::AdditionalContent', 'News are not deleted alongwith the author' ); | 
        
          | 141 |     is( $news_item->author, undef, '->author returns undef is the author has been deleted' ); | 153 |     is( $news_item->author, undef, '->author returns undef is the author has been deleted' ); | 
            
              |  |  | 154 |  | 
            
              | 155 |     $schema->storage->txn_rollback; | 
        
          | 142 | }; | 156 | }; | 
        
          | 143 |  | 157 |  | 
        
          | 144 | subtest '->search_for_display' => sub { | 158 | subtest '->search_for_display' => sub { | 
        
          | 145 |  | 159 |  | 
          
            
              | 146 |     plan tests => 13; | 160 |     plan tests => 3; | 
        
          | 147 |  | 161 |  | 
        
          | 148 |     $schema->storage->txn_begin; | 162 |     $schema->storage->txn_begin; | 
        
          | 149 |  | 163 |  | 
  
    | Lines 227-235
          subtest '->search_for_display' => sub {
      
      
        Link Here | 
        
          | 227 |             number => 5, | 241 |             number => 5, | 
        
          | 228 |         } | 242 |         } | 
        
          | 229 |     }); | 243 |     }); | 
            
              | 230 |     my $news = Koha::AdditionalContents->search_for_display; |  |  | 
        
          | 231 |  | 244 |  | 
          
            
              | 232 |     # FIXME Rewrite tests here | 245 |     my $news = Koha::AdditionalContents->search_for_display({ location => 'staff_only' }); | 
            
              |  |  | 246 |     is($news->count, 3, "There are 3 news for staff"); | 
            
              | 247 |  | 
            
              | 248 |     $news = Koha::AdditionalContents->search_for_display({ location => 'opac_only' }); | 
            
              | 249 |     is($news->count, 0, "There are 0 news for OPAC"); | 
            
              | 250 |  | 
            
              | 251 |     $news = Koha::AdditionalContents->search_for_display({ location => 'staff_and_opac' }); | 
            
              | 252 |     is($news->count, 1, "There is 1 news for staff and OPAC"); | 
            
              | 253 |  | 
            
              | 254 |     # TODO We should add more tests here | 
        
          | 233 |  | 255 |  | 
        
          | 234 |     $schema->storage->txn_rollback; | 256 |     $schema->storage->txn_rollback; | 
        
          | 235 | }; | 257 | }; | 
            
              | 236 | -  |  |  |