| 
      
            Line 0
          
      
      
        Link Here
      
     | 
  
          
            
              | 0 | 
              -   | 
              1 | 
              #!/usr/bin/perl  | 
            
            
               | 
               | 
              2 | 
               | 
            
            
              | 3 | 
              # This file is part of Koha.  | 
            
            
              | 4 | 
              #  | 
            
            
              | 5 | 
              # Koha is free software; you can redistribute it and/or modify it under the  | 
            
            
              | 6 | 
              # terms of the GNU General Public License as published by the Free Software  | 
            
            
              | 7 | 
              # Foundation; either version 3 of the License, or (at your option) any later  | 
            
            
              | 8 | 
              # version.  | 
            
            
              | 9 | 
              #  | 
            
            
              | 10 | 
              # Koha is distributed in the hope that it will be useful, but WITHOUT ANY  | 
            
            
              | 11 | 
              # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR  | 
            
            
              | 12 | 
              # A PARTICULAR PURPOSE. See the GNU General Public License for more details.  | 
            
            
              | 13 | 
              #  | 
            
            
              | 14 | 
              # You should have received a copy of the GNU General Public License along  | 
            
            
              | 15 | 
              # with Koha; if not, see <http://www.gnu.org/licenses>.  | 
            
            
              | 16 | 
               | 
            
            
              | 17 | 
              use Modern::Perl;  | 
            
            
              | 18 | 
               | 
            
            
              | 19 | 
              use Test::More tests => 5;  | 
            
            
              | 20 | 
               | 
            
            
              | 21 | 
              use C4::Context;  | 
            
            
              | 22 | 
              use Koha::Database;  | 
            
            
              | 23 | 
              use Koha::Patron::Attribute::Types;  | 
            
            
              | 24 | 
               | 
            
            
              | 25 | 
              use t::lib::TestBuilder;  | 
            
            
              | 26 | 
              use t::lib::Mocks;  | 
            
            
              | 27 | 
               | 
            
            
              | 28 | 
              BEGIN { | 
            
            
              | 29 | 
                  use_ok('Koha::Template::Plugin::ExtendedAttributeTypes'); | 
            
            
              | 30 | 
              }  | 
            
            
              | 31 | 
               | 
            
            
              | 32 | 
              my $schema  = Koha::Database->schema;  | 
            
            
              | 33 | 
              my $builder = t::lib::TestBuilder->new;  | 
            
            
              | 34 | 
               | 
            
            
              | 35 | 
              $schema->storage->txn_begin;  | 
            
            
              | 36 | 
               | 
            
            
              | 37 | 
              my $plugin = Koha::Template::Plugin::ExtendedAttributeTypes->new();  | 
            
            
              | 38 | 
              ok( $plugin, "initialized ExtendedAttributeTypes plugin" );  | 
            
            
              | 39 | 
               | 
            
            
              | 40 | 
              my $typeA = $builder->build_object(  | 
            
            
              | 41 | 
                  { | 
            
            
              | 42 | 
                      class => 'Koha::Patron::Attribute::Types',  | 
            
            
              | 43 | 
                      value => { | 
            
            
              | 44 | 
                          staff_searchable => 0,  | 
            
            
              | 45 | 
                          description => "Desc type A",  | 
            
            
              | 46 | 
                      }  | 
            
            
              | 47 | 
                  }  | 
            
            
              | 48 | 
              );  | 
            
            
              | 49 | 
              my $typeB = $builder->build_object(  | 
            
            
              | 50 | 
                  { | 
            
            
              | 51 | 
                      class  => 'Koha::Patron::Attribute::Types',  | 
            
            
              | 52 | 
                      value => { | 
            
            
              | 53 | 
                          staff_searchable => 1,  | 
            
            
              | 54 | 
                          description => "Desc type B",  | 
            
            
              | 55 | 
                      }  | 
            
            
              | 56 | 
                  }  | 
            
            
              | 57 | 
              );  | 
            
            
              | 58 | 
               | 
            
            
              | 59 | 
              my $all_plugin = $plugin->all();  | 
            
            
              | 60 | 
              my $all_objects = Koha::Patron::Attribute::Types->search();  | 
            
            
              | 61 | 
               | 
            
            
              | 62 | 
              is_deeply( $all_plugin->unblessed, $all_objects->unblessed, "all method returns all the types correctly");  | 
            
            
              | 63 | 
               | 
            
            
              | 64 | 
              my $all_plugin_codes = $plugin->codes();  | 
            
            
              | 65 | 
              my $all_object_codes = Koha::Patron::Attribute::Types->search()->get_column('code'); | 
            
            
              | 66 | 
               | 
            
            
              | 67 | 
              is_deeply( $all_plugin_codes, $all_object_codes, "codes method returns the codes as expected");  | 
            
            
              | 68 | 
               | 
            
            
              | 69 | 
              my $searchable_plugin_codes = $plugin->codes({ staff_searchable => 1 }); | 
            
            
              | 70 | 
              my $searchable_object_codes = Koha::Patron::Attribute::Types->search({ staff_searchable => 1 })->get_column('code'); | 
            
            
              | 71 | 
               | 
            
            
              | 72 | 
              is_deeply( $searchable_plugin_codes, $searchable_object_codes, "searching plugin method works as expected");  | 
            
            
              | 73 | 
               | 
            
            
              | 74 | 
              $schema->storage->txn_rollback;  | 
            
            
              | 75 | 
               | 
            
            
              | 76 | 
              1;  |