|
Lines 26-32
use List::MoreUtils qw(none);
Link Here
|
| 26 |
use Module::Load::Conditional qw(can_load); |
26 |
use Module::Load::Conditional qw(can_load); |
| 27 |
use Test::MockModule; |
27 |
use Test::MockModule; |
| 28 |
use Test::NoWarnings; |
28 |
use Test::NoWarnings; |
| 29 |
use Test::More tests => 20; |
29 |
use Test::More tests => 22; |
| 30 |
use Test::Warn; |
30 |
use Test::Warn; |
| 31 |
use Test::Exception; |
31 |
use Test::Exception; |
| 32 |
|
32 |
|
|
Lines 563-582
subtest 'Test _version_compare' => sub {
Link Here
|
| 563 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
563 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 564 |
|
564 |
|
| 565 |
is( Koha::Plugins::Base::_version_compare( '1.1.1', '2.2.2' ), -1, "1.1.1 is less then 2.2.2" ); |
565 |
is( Koha::Plugins::Base::_version_compare( '1.1.1', '2.2.2' ), -1, "1.1.1 is less then 2.2.2" ); |
| 566 |
is( Koha::Plugins::Base::_version_compare( '2.2.2', '1.1.1' ), 1, "1.1.1 is greater then 2.2.2" ); |
566 |
is( Koha::Plugins::Base::_version_compare( '2.2.2', '1.1.1' ), 1, "1.1.1 is greater then 2.2.2" ); |
| 567 |
is( Koha::Plugins::Base::_version_compare( '1.1.1', '1.1.1' ), 0, "1.1.1 is equal to 1.1.1" ); |
567 |
is( Koha::Plugins::Base::_version_compare( '1.1.1', '1.1.1' ), 0, "1.1.1 is equal to 1.1.1" ); |
| 568 |
is( Koha::Plugins::Base::_version_compare( '1.01.001', '1.1.1' ), 0, "1.01.001 is equal to 1.1.1" ); |
568 |
is( Koha::Plugins::Base::_version_compare( '1.01.001', '1.1.1' ), 0, "1.01.001 is equal to 1.1.1" ); |
| 569 |
is( Koha::Plugins::Base::_version_compare( '1', '1.0.0' ), 0, "1 is equal to 1.0.0" ); |
569 |
is( Koha::Plugins::Base::_version_compare( '1', '1.0.0' ), 0, "1 is equal to 1.0.0" ); |
| 570 |
is( Koha::Plugins::Base::_version_compare( '1.0', '1.0.0' ), 0, "1.0 is equal to 1.0.0" ); |
570 |
is( Koha::Plugins::Base::_version_compare( '1.0', '1.0.0' ), 0, "1.0 is equal to 1.0.0" ); |
| 571 |
|
571 |
|
| 572 |
# OO tests |
572 |
# OO tests |
| 573 |
my $plugin = Koha::Plugin::Test->new; |
573 |
my $plugin = Koha::Plugin::Test->new; |
| 574 |
is( $plugin->_version_compare( '1.1.1', '2.2.2' ), -1, "1.1.1 is less then 2.2.2" ); |
574 |
is( $plugin->_version_compare( '1.1.1', '2.2.2' ), -1, "1.1.1 is less then 2.2.2" ); |
| 575 |
is( $plugin->_version_compare( '2.2.2', '1.1.1' ), 1, "1.1.1 is greater then 2.2.2" ); |
575 |
is( $plugin->_version_compare( '2.2.2', '1.1.1' ), 1, "1.1.1 is greater then 2.2.2" ); |
| 576 |
is( $plugin->_version_compare( '1.1.1', '1.1.1' ), 0, "1.1.1 is equal to 1.1.1" ); |
576 |
is( $plugin->_version_compare( '1.1.1', '1.1.1' ), 0, "1.1.1 is equal to 1.1.1" ); |
| 577 |
is( $plugin->_version_compare( '1.01.001', '1.1.1' ), 0, "1.01.001 is equal to 1.1.1" ); |
577 |
is( $plugin->_version_compare( '1.01.001', '1.1.1' ), 0, "1.01.001 is equal to 1.1.1" ); |
| 578 |
is( $plugin->_version_compare( '1', '1.0.0' ), 0, "1 is equal to 1.0.0" ); |
578 |
is( $plugin->_version_compare( '1', '1.0.0' ), 0, "1 is equal to 1.0.0" ); |
| 579 |
is( $plugin->_version_compare( '1.0', '1.0.0' ), 0, "1.0 is equal to 1.0.0" ); |
579 |
is( $plugin->_version_compare( '1.0', '1.0.0' ), 0, "1.0 is equal to 1.0.0" ); |
| 580 |
}; |
580 |
}; |
| 581 |
|
581 |
|
| 582 |
subtest 'bundle_path() tests' => sub { |
582 |
subtest 'bundle_path() tests' => sub { |
|
Lines 619-624
subtest 'new() tests' => sub {
Link Here
|
| 619 |
is( ref($result), 'Koha::Plugins', 'calling new with enable_plugins makes it override the config' ); |
619 |
is( ref($result), 'Koha::Plugins', 'calling new with enable_plugins makes it override the config' ); |
| 620 |
}; |
620 |
}; |
| 621 |
|
621 |
|
|
|
622 |
subtest '_check_dependencies() tests' => sub { |
| 623 |
|
| 624 |
plan tests => 7; |
| 625 |
|
| 626 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 627 |
|
| 628 |
my $plugins = Koha::Plugins->new( { enable_plugins => 1 } ); |
| 629 |
|
| 630 |
# Test with no dependency files - should pass silently |
| 631 |
my $empty_dir = tempdir( CLEANUP => 1 ); |
| 632 |
lives_ok { $plugins->_check_dependencies($empty_dir) } |
| 633 |
'No dependency files - passes without error'; |
| 634 |
|
| 635 |
# Test with cpanfile that has satisfied dependencies |
| 636 |
my $cpanfile_ok_dir = tempdir( CLEANUP => 1 ); |
| 637 |
open my $fh, '>', "$cpanfile_ok_dir/cpanfile" or die "Cannot create cpanfile: $!"; |
| 638 |
print $fh "requires 'Modern::Perl';\n"; # This should be installed |
| 639 |
close $fh; |
| 640 |
lives_ok { $plugins->_check_dependencies($cpanfile_ok_dir) } |
| 641 |
'cpanfile with satisfied dependencies - passes'; |
| 642 |
|
| 643 |
# Test with cpanfile that has unsatisfied dependencies |
| 644 |
my $cpanfile_bad_dir = tempdir( CLEANUP => 1 ); |
| 645 |
open $fh, '>', "$cpanfile_bad_dir/cpanfile" or die "Cannot create cpanfile: $!"; |
| 646 |
print $fh "requires 'Some::Nonexistent::Module::XYZ123';\n"; |
| 647 |
close $fh; |
| 648 |
throws_ok { $plugins->_check_dependencies($cpanfile_bad_dir) } |
| 649 |
qr/Unmet dependencies:/, |
| 650 |
'cpanfile with unmet dependencies - dies with message'; |
| 651 |
|
| 652 |
# Test with META.json that has satisfied dependencies (CPAN::Meta 2.0 format) |
| 653 |
my $meta_json_dir = tempdir( CLEANUP => 1 ); |
| 654 |
open $fh, '>', "$meta_json_dir/META.json" or die "Cannot create META.json: $!"; |
| 655 |
print $fh <<'JSON'; |
| 656 |
{ |
| 657 |
"abstract": "Test plugin", |
| 658 |
"author": ["Test <test@test.com>"], |
| 659 |
"dynamic_config": 0, |
| 660 |
"generated_by": "Test", |
| 661 |
"license": ["gpl_3"], |
| 662 |
"meta-spec": { "version": 2 }, |
| 663 |
"name": "Test-Plugin", |
| 664 |
"release_status": "stable", |
| 665 |
"version": "1.0", |
| 666 |
"prereqs": { |
| 667 |
"runtime": { |
| 668 |
"requires": { |
| 669 |
"Modern::Perl": "0" |
| 670 |
} |
| 671 |
} |
| 672 |
} |
| 673 |
} |
| 674 |
JSON |
| 675 |
close $fh; |
| 676 |
lives_ok { $plugins->_check_dependencies($meta_json_dir) } |
| 677 |
'META.json with satisfied dependencies - passes'; |
| 678 |
|
| 679 |
# Test with META.yml that has satisfied dependencies (CPAN::Meta 1.4 format) |
| 680 |
my $meta_yml_dir = tempdir( CLEANUP => 1 ); |
| 681 |
open $fh, '>', "$meta_yml_dir/META.yml" or die "Cannot create META.yml: $!"; |
| 682 |
print $fh <<'YAML'; |
| 683 |
meta-spec: |
| 684 |
version: 1.4 |
| 685 |
name: Test-Plugin |
| 686 |
version: 1.0 |
| 687 |
abstract: Test plugin |
| 688 |
author: |
| 689 |
- Test <test@test.com> |
| 690 |
license: perl |
| 691 |
requires: |
| 692 |
Modern::Perl: 0 |
| 693 |
YAML |
| 694 |
close $fh; |
| 695 |
lives_ok { $plugins->_check_dependencies($meta_yml_dir) } |
| 696 |
'META.yml with satisfied dependencies - passes'; |
| 697 |
|
| 698 |
# Test with META.json that has unsatisfied dependencies |
| 699 |
my $meta_json_bad_dir = tempdir( CLEANUP => 1 ); |
| 700 |
open $fh, '>', "$meta_json_bad_dir/META.json" or die "Cannot create META.json: $!"; |
| 701 |
print $fh <<'JSON'; |
| 702 |
{ |
| 703 |
"abstract": "Test plugin", |
| 704 |
"author": ["Test <test@test.com>"], |
| 705 |
"dynamic_config": 0, |
| 706 |
"generated_by": "Test", |
| 707 |
"license": ["gpl_3"], |
| 708 |
"meta-spec": { "version": 2 }, |
| 709 |
"name": "Test-Plugin", |
| 710 |
"release_status": "stable", |
| 711 |
"version": "1.0", |
| 712 |
"prereqs": { |
| 713 |
"runtime": { |
| 714 |
"requires": { |
| 715 |
"Nonexistent::Module::ABC": "1.0" |
| 716 |
} |
| 717 |
} |
| 718 |
} |
| 719 |
} |
| 720 |
JSON |
| 721 |
close $fh; |
| 722 |
throws_ok { $plugins->_check_dependencies($meta_json_bad_dir) } |
| 723 |
qr/Unmet dependencies:/, |
| 724 |
'META.json with unmet dependencies - dies'; |
| 725 |
|
| 726 |
# Test that multiple unmet dependencies are all reported |
| 727 |
my $multi_bad_dir = tempdir( CLEANUP => 1 ); |
| 728 |
open $fh, '>', "$multi_bad_dir/cpanfile" or die "Cannot create cpanfile: $!"; |
| 729 |
print $fh "requires 'Nonexistent::ModuleA';\n"; |
| 730 |
print $fh "requires 'Nonexistent::ModuleB';\n"; |
| 731 |
close $fh; |
| 732 |
throws_ok { $plugins->_check_dependencies($multi_bad_dir) } |
| 733 |
qr/Nonexistent::ModuleA.*Nonexistent::ModuleB/s, |
| 734 |
'Multiple unmet dependencies are all reported'; |
| 735 |
}; |
| 736 |
|
| 737 |
subtest 'InstallPlugins() with from parameter tests' => sub { |
| 738 |
|
| 739 |
plan tests => 6; |
| 740 |
|
| 741 |
$schema->storage->txn_begin; |
| 742 |
|
| 743 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 744 |
|
| 745 |
# Create a temporary plugins directory for this test |
| 746 |
my $test_plugins_dir = tempdir( CLEANUP => 1 ); |
| 747 |
t::lib::Mocks::mock_config( 'pluginsdir', $test_plugins_dir ); |
| 748 |
|
| 749 |
my $plugins = Koha::Plugins->new( { enable_plugins => 1 } ); |
| 750 |
|
| 751 |
# Test 1: Files are copied from staging to plugins dir |
| 752 |
my $staging_dir = tempdir( CLEANUP => 1 ); |
| 753 |
mkdir "$staging_dir/Koha"; |
| 754 |
mkdir "$staging_dir/Koha/Plugin"; |
| 755 |
open my $fh, '>', "$staging_dir/Koha/Plugin/TestStaging.pm" or die $!; |
| 756 |
print $fh "package Koha::Plugin::TestStaging;\n1;\n"; |
| 757 |
close $fh; |
| 758 |
|
| 759 |
$plugins->InstallPlugins( { from => $staging_dir, verbose => 0 } ); |
| 760 |
ok( -f "$test_plugins_dir/Koha/Plugin/TestStaging.pm", 'Plugin file copied to plugins directory' ); |
| 761 |
|
| 762 |
# Test 2: cpanfile is NOT copied |
| 763 |
my $staging_dir2 = tempdir( CLEANUP => 1 ); |
| 764 |
mkdir "$staging_dir2/Koha"; |
| 765 |
mkdir "$staging_dir2/Koha/Plugin"; |
| 766 |
open $fh, '>', "$staging_dir2/Koha/Plugin/TestStaging2.pm" or die $!; |
| 767 |
print $fh "package Koha::Plugin::TestStaging2;\n1;\n"; |
| 768 |
close $fh; |
| 769 |
open $fh, '>', "$staging_dir2/cpanfile" or die $!; |
| 770 |
print $fh "requires 'Modern::Perl';\n"; |
| 771 |
close $fh; |
| 772 |
|
| 773 |
$plugins->InstallPlugins( { from => $staging_dir2, verbose => 0 } ); |
| 774 |
ok( -f "$test_plugins_dir/Koha/Plugin/TestStaging2.pm", 'Plugin file copied' ); |
| 775 |
ok( !-f "$test_plugins_dir/cpanfile", 'cpanfile is NOT copied to plugins directory' ); |
| 776 |
|
| 777 |
# Test 3: META.json and META.yml are NOT copied |
| 778 |
my $staging_dir3 = tempdir( CLEANUP => 1 ); |
| 779 |
mkdir "$staging_dir3/Koha"; |
| 780 |
mkdir "$staging_dir3/Koha/Plugin"; |
| 781 |
open $fh, '>', "$staging_dir3/Koha/Plugin/TestStaging3.pm" or die $!; |
| 782 |
print $fh "package Koha::Plugin::TestStaging3;\n1;\n"; |
| 783 |
close $fh; |
| 784 |
|
| 785 |
# Create valid META.json (CPAN::Meta 2.0 format) |
| 786 |
open $fh, '>', "$staging_dir3/META.json" or die $!; |
| 787 |
print $fh <<'JSON'; |
| 788 |
{ |
| 789 |
"abstract": "Test", |
| 790 |
"author": ["Test <test@test.com>"], |
| 791 |
"dynamic_config": 0, |
| 792 |
"generated_by": "Test", |
| 793 |
"license": ["gpl_3"], |
| 794 |
"meta-spec": { "version": 2 }, |
| 795 |
"name": "Test", |
| 796 |
"release_status": "stable", |
| 797 |
"version": "1.0" |
| 798 |
} |
| 799 |
JSON |
| 800 |
close $fh; |
| 801 |
|
| 802 |
# Create valid META.yml (CPAN::Meta 1.4 format) |
| 803 |
open $fh, '>', "$staging_dir3/META.yml" or die $!; |
| 804 |
print $fh <<'YAML'; |
| 805 |
meta-spec: |
| 806 |
version: 1.4 |
| 807 |
name: Test |
| 808 |
version: 1.0 |
| 809 |
abstract: Test |
| 810 |
author: |
| 811 |
- Test <test@test.com> |
| 812 |
license: perl |
| 813 |
YAML |
| 814 |
close $fh; |
| 815 |
|
| 816 |
$plugins->InstallPlugins( { from => $staging_dir3, verbose => 0 } ); |
| 817 |
ok( !-f "$test_plugins_dir/META.json", 'META.json is NOT copied to plugins directory' ); |
| 818 |
ok( !-f "$test_plugins_dir/META.yml", 'META.yml is NOT copied to plugins directory' ); |
| 819 |
|
| 820 |
# Test 4: Trailing slash in path is handled correctly |
| 821 |
my $staging_dir4 = tempdir( CLEANUP => 1 ); |
| 822 |
mkdir "$staging_dir4/Koha"; |
| 823 |
mkdir "$staging_dir4/Koha/Plugin"; |
| 824 |
open $fh, '>', "$staging_dir4/Koha/Plugin/TestStaging4.pm" or die $!; |
| 825 |
print $fh "package Koha::Plugin::TestStaging4;\n1;\n"; |
| 826 |
close $fh; |
| 827 |
|
| 828 |
# Pass path with trailing slash |
| 829 |
$plugins->InstallPlugins( { from => "$staging_dir4/", verbose => 0 } ); |
| 830 |
ok( |
| 831 |
-f "$test_plugins_dir/Koha/Plugin/TestStaging4.pm", |
| 832 |
'Plugin file copied correctly with trailing slash in from path' |
| 833 |
); |
| 834 |
|
| 835 |
$schema->storage->txn_rollback; |
| 836 |
}; |
| 837 |
|
| 622 |
$schema->storage->txn_rollback; |
838 |
$schema->storage->txn_rollback; |
| 623 |
|
839 |
|
| 624 |
#!/usr/bin/perl |
840 |
#!/usr/bin/perl |
| 625 |
- |
|
|