2021-06-05 01:18:44 +02:00
|
|
|
use 5.32.1;
|
|
|
|
|
2021-06-05 01:31:43 +02:00
|
|
|
use Test::Most tests => 9;
|
2021-06-05 01:18:44 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Const::Fast;
|
|
|
|
|
|
|
|
use BeastBB::Mock::Controller;
|
|
|
|
|
|
|
|
{
|
|
|
|
use_ok 'BeastBB::DAO::GroupManager';
|
|
|
|
}
|
|
|
|
|
2021-06-05 02:36:39 +02:00
|
|
|
const my $APP => BeastBB::Mock::Controller->new;
|
|
|
|
const my $GROUP_MANAGER => BeastBB::DAO::GroupManager->new( app => $APP );
|
|
|
|
|
2021-06-05 01:18:44 +02:00
|
|
|
{
|
|
|
|
$APP->db->Mock(
|
|
|
|
sql =>
|
|
|
|
'SELECT "id_group", "groupname" FROM "group" WHERE "groupname" = ?',
|
|
|
|
results => [ [ 'id_group', 'groupname' ], [ 1, 'example_group' ] ]
|
|
|
|
);
|
|
|
|
my $maybe_group = $GROUP_MANAGER->Get( groupname => 'example_group' );
|
|
|
|
die $maybe_group->ErrorMessage if $maybe_group->IsError;
|
|
|
|
my $group = $maybe_group->Content;
|
2021-06-05 01:31:43 +02:00
|
|
|
ok $group->isa('BeastBB::Model::Group'),
|
|
|
|
'We can recover groups by groupname.';
|
2021-06-05 01:18:44 +02:00
|
|
|
is_deeply $group->Hash, { groupname => 'example_group', id_group => 1 },
|
|
|
|
'The group hash after groupname recovery is ok.';
|
|
|
|
}
|
|
|
|
|
2021-06-05 01:31:43 +02:00
|
|
|
{
|
|
|
|
$APP->db->Mock(
|
|
|
|
sql =>
|
|
|
|
'SELECT "id_group", "groupname" FROM "group" WHERE "id_group" = ?',
|
|
|
|
results => [ [ 'id_group', 'groupname' ], [ 1, 'example_group' ] ]
|
|
|
|
);
|
|
|
|
my $maybe_group = $GROUP_MANAGER->Get( id_group => 1 );
|
|
|
|
die $maybe_group->ErrorMessage if $maybe_group->IsError;
|
|
|
|
my $group = $maybe_group->Content;
|
|
|
|
ok $group->isa('BeastBB::Model::Group'),
|
|
|
|
'We can recover groups by id_group.';
|
|
|
|
is_deeply $group->Hash, { groupname => 'example_group', id_group => 1 },
|
|
|
|
'The group hash after id_group recovery is ok.';
|
|
|
|
}
|
|
|
|
|
2021-06-05 01:18:44 +02:00
|
|
|
{
|
|
|
|
$APP->db->Mock(
|
|
|
|
sql =>
|
|
|
|
'SELECT "id_group", "groupname" FROM "group" WHERE "groupname" = ?',
|
|
|
|
results => [ [ 'id_group', 'groupname' ], [ 1, 'example_group' ] ]
|
|
|
|
);
|
|
|
|
$APP->db->Mock(
|
|
|
|
sql =>
|
|
|
|
'SELECT privilege.name FROM group_privilege INNER JOIN privilege USING (id_privilege) WHERE id_group=?',
|
|
|
|
results => [
|
|
|
|
['name'],
|
|
|
|
['example_privilege'],
|
|
|
|
['example_privilege_1']
|
|
|
|
]
|
|
|
|
);
|
|
|
|
my $maybe_group = $GROUP_MANAGER->Get(
|
|
|
|
groupname => 'example_group',
|
|
|
|
recover_privileges => 1
|
|
|
|
);
|
|
|
|
die $maybe_group->ErrorMessage if $maybe_group->IsError;
|
|
|
|
my $group = $maybe_group->Content;
|
2021-06-05 01:31:43 +02:00
|
|
|
ok $group->isa('BeastBB::Model::Group'), 'We can recover groups with privileges by id_group.';
|
2021-06-05 01:18:44 +02:00
|
|
|
is_deeply $group->Hash,
|
|
|
|
{
|
|
|
|
groupname => 'example_group',
|
|
|
|
id_group => 1,
|
|
|
|
privileges => { example_privilege => 1, example_privilege_1 => 1 }
|
|
|
|
},
|
|
|
|
'The group hash after groupname recovery is ok.';
|
|
|
|
}
|
2021-06-05 01:31:43 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
$APP->db->Mock(
|
|
|
|
sql =>
|
|
|
|
'SELECT "id_group", "groupname" FROM "group" WHERE "id_group" = ?',
|
|
|
|
results => [ [ 'id_group', 'groupname' ], [ 1, 'example_group' ] ]
|
|
|
|
);
|
|
|
|
$APP->db->Mock(
|
|
|
|
sql =>
|
|
|
|
'SELECT privilege.name FROM group_privilege INNER JOIN privilege USING (id_privilege) WHERE id_group=?',
|
|
|
|
results => [
|
|
|
|
['name'],
|
|
|
|
['example_privilege'],
|
|
|
|
['example_privilege_1']
|
|
|
|
]
|
|
|
|
);
|
|
|
|
my $maybe_group = $GROUP_MANAGER->Get(
|
|
|
|
id_group => 1,
|
|
|
|
recover_privileges => 1
|
|
|
|
);
|
|
|
|
die $maybe_group->ErrorMessage if $maybe_group->IsError;
|
|
|
|
my $group = $maybe_group->Content;
|
|
|
|
ok $group->isa('BeastBB::Model::Group'), 'We can recover groups with privileges by id_group.';
|
|
|
|
is_deeply $group->Hash,
|
|
|
|
{
|
|
|
|
groupname => 'example_group',
|
|
|
|
id_group => 1,
|
|
|
|
privileges => { example_privilege => 1, example_privilege_1 => 1 }
|
|
|
|
},
|
|
|
|
'The group hash after id_group recovery is ok.';
|
|
|
|
}
|