|
Lines 22-27
use Modern::Perl;
Link Here
|
| 22 |
use Test::More tests => 4; |
22 |
use Test::More tests => 4; |
| 23 |
|
23 |
|
| 24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
|
|
25 |
use Test::MockObject; |
| 25 |
use Test::Exception; |
26 |
use Test::Exception; |
| 26 |
|
27 |
|
| 27 |
use JSON qw(encode_json); |
28 |
use JSON qw(encode_json); |
|
Lines 38-44
my $schema = Koha::Database->new->schema;
Link Here
|
| 38 |
my $builder = t::lib::TestBuilder->new; |
39 |
my $builder = t::lib::TestBuilder->new; |
| 39 |
|
40 |
|
| 40 |
subtest 'get_user() tests' => sub { |
41 |
subtest 'get_user() tests' => sub { |
| 41 |
plan tests => 4; |
42 |
plan tests => 5; |
| 42 |
|
43 |
|
| 43 |
$schema->storage->txn_begin; |
44 |
$schema->storage->txn_begin; |
| 44 |
|
45 |
|
|
Lines 77-82
subtest 'get_user() tests' => sub {
Link Here
|
| 77 |
is( $mapped_data->{surname}, undef, 'No surname mapped' ); |
78 |
is( $mapped_data->{surname}, undef, 'No surname mapped' ); |
| 78 |
is( $domain->identity_provider_domain_id, $resolved_domain->identity_provider_domain_id, 'Is the same domain' ); |
79 |
is( $domain->identity_provider_domain_id, $resolved_domain->identity_provider_domain_id, 'Is the same domain' ); |
| 79 |
|
80 |
|
|
|
81 |
# Test the plugin hook "auth_client_get_user". |
| 82 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 83 |
my $get_plugins = sub { |
| 84 |
my $methods = [ |
| 85 |
{ |
| 86 |
auth_client_get_user => sub { |
| 87 |
$_[1]->{mapped_data}->{firstname} = 'test name modified 1'; |
| 88 |
return; |
| 89 |
}, |
| 90 |
retrieve_data => sub { return $_[1] eq 'priority' ? 2 : undef; } |
| 91 |
}, |
| 92 |
{ |
| 93 |
auth_client_get_user => sub { |
| 94 |
$_[1]->{mapped_data}->{firstname} = 'test name modified 2'; |
| 95 |
return; |
| 96 |
}, |
| 97 |
retrieve_data => sub { return $_[1] eq 'priority' ? 1 : undef; } |
| 98 |
} |
| 99 |
]; |
| 100 |
my @plugins; |
| 101 |
foreach my $method ( @{$methods} ) { |
| 102 |
my $plugin = Test::MockObject->new; |
| 103 |
foreach my $name ( keys %{$method} ) { |
| 104 |
$plugin->mock( $name, $method->{$name} ); |
| 105 |
} |
| 106 |
push @plugins, $plugin; |
| 107 |
} |
| 108 |
return @plugins; |
| 109 |
}; |
| 110 |
my $plugins_module = Test::MockModule->new('Koha::Plugins'); |
| 111 |
$plugins_module->mock( 'GetPlugins', $get_plugins ); |
| 112 |
$plugins_module->mock( 'get_enabled_plugins', $get_plugins ); |
| 113 |
( $resolved_patron, $mapped_data, $resolved_domain ) = |
| 114 |
$client->get_user( { provider => $provider->code, data => $data, interface => 'opac' } ); |
| 115 |
is( |
| 116 |
$mapped_data->{firstname}, |
| 117 |
'test name modified 1', |
| 118 |
'Data modified correctly by plugins' |
| 119 |
); |
| 120 |
|
| 80 |
$schema->storage->txn_rollback; |
121 |
$schema->storage->txn_rollback; |
| 81 |
|
122 |
|
| 82 |
}; |
123 |
}; |
| 83 |
- |
|
|