#!/usr/bin/perl -w
my
$j
= WWW::UsePerl::Journal->new(
'testuser'
);
SKIP: {
skip
"Can't see a network connection"
, 20
unless
(
$j
->connected);
diag(
"connected="
.
$j
->connected);
my
$username
=
"russell"
;
my
$entryid
= 2376;
my
$userid
= 1413;
{
$j
= WWW::UsePerl::Journal->new(
$username
);
isa_ok(
$j
,
'WWW::UsePerl::Journal'
);
my
$uid
=
$j
->uid();
is(
$uid
,
$userid
,
'uid'
);
my
%entries
=
$j
->entryhash;
isnt(
scalar
(
keys
%entries
), 0,
'entryhash'
);
if
(
scalar
(
keys
%entries
) == 0) {
diag(
"WUJERR: "
.
$j
->error);
}
my
%cache
=
$j
->entryhash;
is(
scalar
(
keys
%cache
),
scalar
(
keys
%entries
),
'matching cached/entryhash count'
);
my
@ids
=
$j
->entryids;
isnt(
scalar
(
@ids
), 0,
'entryids'
);
if
(
scalar
(
@ids
) == 0) {
diag(
"WUJERR: "
.
$j
->error);
}
@ids
=
sort
{
$a
<=>
$b
}
@ids
;
my
@asc
=
$j
->entryids(
ascending
=> 1);
my
@des
=
$j
->entryids(
descending
=> 1);
my
@rev
=
reverse
@des
;
is_deeply(\
@asc
,\
@ids
,
'ascending entryids'
);
is_deeply(\
@rev
,\
@ids
,
'descending entryids'
);
my
@c_ids
=
$j
->entryids;
my
@c_asc
=
$j
->entryids(
ascending
=> 1);
my
@c_des
=
$j
->entryids(
descending
=> 1);
is_deeply(\
@c_ids
,\
@c_ids
,
'cached threaded entryids'
);
is_deeply(\
@c_asc
,\
@asc
,
'cached ascending entryids'
);
is_deeply(\
@c_des
,\
@des
,
'cached descending entryids'
);
my
@titles
=
$j
->entrytitles;
isnt(
scalar
@titles
, 0,
'entrytitles'
);
if
(
scalar
(
@titles
) == 0) {
diag(
"WUJERR: "
.
$j
->error);
}
@asc
=
$j
->entrytitles(
ascending
=> 1);
@des
=
$j
->entrytitles(
descending
=> 1);
@rev
=
reverse
@des
;
is_deeply(\
@rev
,\
@asc
,
'ordered entrytitles'
);
my
@c_titles
=
$j
->entrytitles;
@c_asc
=
$j
->entrytitles(
ascending
=> 1);
@c_des
=
$j
->entrytitles(
descending
=> 1);
is_deeply(\
@c_titles
,\
@titles
,
'cached threaded entrytitles'
);
is_deeply(\
@c_asc
,\
@asc
,
'cached ascending entrytitles'
);
is_deeply(\
@c_des
,\
@des
,
'cached descending entrytitles'
);
$j
->debug(1);
my
$text
=
'I read in <a href="_hfb/journal/index.html" rel="nofollow">hfb\'s journal</a> that there was no module for testing whether something was a pangram. There is now.'
;
my
$content
=
$j
->entry(
'2340'
)->content;
unless
(
$content
) {
diag(
$j
->
log
());
}
cmp_ok(
$content
,
'eq'
,
$text
,
'entry compare'
);
$content
=
$j
->entrytitled(
'Lingua::Pangram'
)->content;
cmp_ok(
$content
,
'eq'
,
$text
,
'entrytitled compare'
);
}
{
my
$j
= WWW::UsePerl::Journal->new(1662);
my
$user
=
$j
->user;
is(
$user
,
'richardc'
,
'username from uid'
);
if
(
$user
ne
'richardc'
) {
diag(
"WUJERR: "
.
$j
->error);
}
}
{
my
$j
= WWW::UsePerl::Journal->new(
'2shortplanks'
);
my
%entries
=
eval
{
$j
->entryhash; };
is($@,
''
,
'entryhash doesnt die on titles with trailing newlines'
);
isnt(
scalar
(
keys
%entries
), 0,
'...and has found some entries'
);
if
(
scalar
(
keys
%entries
) == 0) {
diag(
"WUJERR: "
.
$j
->error);
}
}
}
{
my
$j
;
dies_ok {
$j
= WWW::UsePerl::Journal->new(); }
'dies if no username given'
;
my
$entry
= WWW::UsePerl::Journal::Entry->new();
is(
$entry
,
undef
,
'missing parameters'
);
dies_ok {
my
$entry
= WWW::UsePerl::Journal::Entry->new(
j
=>
'journal'
,
eid
=> 1,
author
=>
'me'
) }
'dies with invalid required parameters are missing'
;
}