]>
Dogcows Code - chaz/p5-File-KDBX/blob - t/database.t
15 subtest
'Create a new database' => sub {
16 my $kdbx = File
::KDBX-
>new;
18 $kdbx->add_group(name
=> 'Meh');
19 ok
$kdbx->_has_implicit_root, 'Database starts off with implicit root';
21 my $entry = $kdbx->add_entry({
23 password
=> {value
=> 'This is a secret!!!!!', protect
=> 1},
26 ok
!$kdbx->_has_implicit_root, 'Adding an entry to the root group makes it explicit';
29 ok
$kdbx->_has_implicit_root, 'Removing group makes the root group implicit again';
32 subtest
'Clone' => sub {
33 my $kdbx = File
::KDBX-
>new;
34 $kdbx->add_group(name
=> 'Passwords')->add_entry(title
=> 'My Entry');
36 my $copy = $kdbx->clone;
37 cmp_deeply
$copy, $kdbx, 'Clone keeps the same structure and data' or dumper
$copy;
39 isnt
$kdbx, $copy, 'Clone is a different object';
40 isnt
$kdbx->root, $copy->root,
41 'Clone root group is a different object';
42 isnt
$kdbx->root->groups->[0], $copy->root->groups->[0],
43 'Clone group is a different object';
44 isnt
$kdbx->root->groups->[0]->entries->[0], $copy->root->groups->[0]->entries->[0],
45 'Clone entry is a different object';
47 my @objects = $copy->objects->each;
48 subtest
'Cloned objects refer to the cloned database' => sub {
49 plan tests
=> scalar @_;
50 for my $object (@objects) {
51 my $object_kdbx = eval { $object->kdbx };
52 is $object_kdbx, $copy, 'Object: ' . $object->label;
57 subtest
'Recycle bin' => sub {
58 my $kdbx = File
::KDBX-
>new;
59 my $entry = $kdbx->add_entry(label
=> 'Meh');
61 my $bin = $kdbx->groups->grep(name
=> 'Recycle Bin')->next;
62 ok
!$bin, 'New database has no recycle bin';
64 is $kdbx->recycle_bin_enabled, 1, 'Recycle bin is enabled';
65 $kdbx->recycle_bin_enabled(0);
67 $entry->recycle_or_remove;
68 cmp_ok
$entry->is_recycled, '==', 0, 'Entry is not recycle if recycle bin is disabled';
70 $bin = $kdbx->groups->grep(name
=> 'Recycle Bin')->next;
71 ok
!$bin, 'Recycle bin not autovivified if recycle bin is disabled';
72 is $kdbx->entries->size, 0, 'Database is empty after removing entry';
74 $kdbx->recycle_bin_enabled(1);
76 $entry = $kdbx->add_entry(label
=> 'Another one');
77 $entry->recycle_or_remove;
78 cmp_ok
$entry->is_recycled, '==', 1, 'Entry is recycled';
80 $bin = $kdbx->groups->grep(name
=> 'Recycle Bin')->next;
81 ok
$bin, 'Recycle bin group autovivifies';
82 cmp_ok
$bin->icon_id, '==', 43, 'Recycle bin has the trash icon';
83 cmp_ok
$bin->enable_auto_type, '==', 0, 'Recycle bin has auto type disabled';
84 cmp_ok
$bin->enable_searching, '==', 0, 'Recycle bin has searching disabled';
86 is $kdbx->entries->size, 1, 'Database is not empty';
87 is $kdbx->entries(searching
=> 1)->size, 0, 'Database has no entries if searching';
88 cmp_ok
$bin->entries_deeply->size, '==', 1, 'Recycle bin has an entry';
90 $entry->recycle_or_remove;
91 is $kdbx->entries->size, 0, 'Remove entry if it is already in the recycle bin';
This page took 0.044013 seconds and 4 git commands to generate.