]>
Dogcows Code - chaz/p5-File-KDBX/blob - t/entry.t
13 BEGIN { use_ok
'File::KDBX::Entry' }
15 subtest
'Construction' => sub {
16 my $entry = File
::KDBX
::Entry-
>new(my $data = {username
=> 'foo'});
17 is $entry, $data, 'Provided data structure becomes the object';
18 isa_ok
$data, 'File::KDBX::Entry', 'Data structure is blessed';
19 is $entry->{username
}, 'foo', 'username is in the object still';
20 is $entry->username, '', 'username is not the UserName string';
22 like exception
{ $entry->kdbx }, qr/disassociated from a KDBX database/, 'Dies if disassociated';
23 $entry->kdbx(my $kdbx = File
::KDBX-
>new);
24 is $entry->kdbx, $kdbx, 'Set a database after instantiation';
26 is_deeply
$entry, {username
=> 'foo', strings
=> {UserName
=> {value
=> ''}}},
27 'Entry data contains what was provided to the constructor plus vivified username';
29 $entry = File
::KDBX
::Entry-
>new(username
=> 'bar');
30 is $entry->{username
}, undef, 'username is not set on the data';
31 is $entry->username, 'bar', 'username is set correctly as the UserName string';
33 cmp_deeply
$entry, noclass
({
35 background_color
=> "",
38 custom_icon_uuid
=> undef,
39 foreground_color
=> "",
40 icon_id
=> "Password",
42 previous_parent_group
=> undef,
43 quality_check
=> bool
(1),
64 last_modification_time
=> isa
('Time::Piece'),
65 creation_time
=> isa
('Time::Piece'),
66 last_access_time
=> isa
('Time::Piece'),
67 expiry_time
=> isa
('Time::Piece'),
70 location_changed
=> isa
('Time::Piece'),
72 uuid
=> re
('^(?s:.){16}$'),
73 }), 'Entry data contains UserName string and the rest default attributes';
76 subtest
'Custom icons' => sub {
78 my $gif = pack('H*', '4749463839610100010000ff002c00000000010001000002003b');
80 my $entry = File
::KDBX
::Entry-
>new(my $kdbx = File
::KDBX-
>new, icon_id
=> 42);
81 is $entry->custom_icon_uuid, undef, 'UUID is undef if no custom icon is set';
82 is $entry->custom_icon, undef, 'Icon is undef if no custom icon is set';
83 is $entry->icon_id, 42, 'Default icon is set to something';
85 is $entry->custom_icon($gif), $gif, 'Setting a custom icon returns icon';
86 is $entry->custom_icon, $gif, 'Henceforth the icon is set';
87 is $entry->icon_id, 0, 'Default icon got changed to first icon';
88 my $uuid = $entry->custom_icon_uuid;
89 isnt
$uuid, undef, 'UUID is now set';
91 my $found = $entry->kdbx->custom_icon_data($uuid);
92 is $entry->custom_icon, $found, 'Custom icon on entry matches the database';
94 is $entry->custom_icon(undef), undef, 'Unsetting a custom icon returns undefined';
95 $found = $entry->kdbx->custom_icon_data($uuid);
96 is $found, $gif, 'Custom icon still exists in the database';
This page took 0.049554 seconds and 4 git commands to generate.