Daizu
view release on metacpan or search on metacpan
# parent and directory_path
{
my $parent_id = db_row_id($db, 'wc_file',
wc_id => $wc->id,
path => 'foo.com/blog/2006/fish-fingers',
);
my $parent = $file_1->parent;
isa_ok($parent, 'Daizu::File', 'parent is right class');
is($parent->{id}, $parent_id, '$parent->{id}');
is($parent->directory_path, 'foo.com/blog/2006/fish-fingers',
'$parent->directory_path');
}
# file_at_path
{
my $file = $file_1->file_at_path('/example.com/fractal.png');
is($file->{path}, 'example.com/fractal.png',
'file_at_path: /example.com/fractal.png');
$file = $file_1->file_at_path('/./example.com/./fractal.png');
is($file->{path}, 'example.com/fractal.png',
'file_at_path: /./example.com/./fractal.png');
$file = $file_1->file_at_path('article-2.html');
is($file->{path}, 'foo.com/blog/2006/fish-fingers/article-2.html',
'file_at_path: article-2.html');
$file = $file_1->file_at_path('../parsnips');
is($file->{path}, 'foo.com/blog/2006/parsnips',
'file_at_path: ../parsnips');
$file = $file_1->file_at_path('../../2005/photos/wasp-on-holly-leaf.jpg');
is($file->{path}, 'foo.com/blog/2005/photos/wasp-on-holly-leaf.jpg',
'file_at_path: ../../2005/photos/wasp-on-holly-leaf.jpg');
# Bad paths.
for ('/.', '..', '/example.com/fractal.png/') {
$@ = undef;
eval { $file_1->file_at_path('/.') };
like($@, qr/no file at/, "file_at_path: $_");
}
}
# article_doc
{
my $doc = $file_1->article_doc;
isa_ok($doc, 'XML::LibXML::Document', 'article_doc: article 1');
my $body = $doc->documentElement;
is($body->localname, 'body', 'article_doc: correct root element');
# There should be three paragraphs and a daizu:fold element, and the
# only other nodes at the top level should be text (newlines).
my $node = $body->firstChild;
my $pos = 1;
while (defined $node) {
if ($pos == 1 || $pos == 3 || $pos == 7) {
isa_ok($node, 'XML::LibXML::Element', "article_doc: $pos: element");
is($node->localname, 'p', "article_doc: $pos: <p>");
is($node->namespaceURI, 'http://www.w3.org/1999/xhtml',
"article_doc: $pos: XHTML namespace");
}
elsif ($pos == 5) {
isa_ok($node, 'XML::LibXML::Element', "article_doc: $pos: element");
is($node->localname, 'fold', "article_doc: $pos: <fold>");
is($node->namespaceURI, $Daizu::HTML_EXTENSION_NS,
"article_doc: $pos: Daizu HTML extension namespace");
}
else {
assert($pos <= 8);
isa_ok($node, 'XML::LibXML::Text', "article_doc: $pos: text");
like($node->textContent, qr/\A\n+\z/,
"article_doc: $pos: only newlines");
}
++$pos;
$node = $node->nextSibling;
}
# Check UTF-8 characters are preserved in the DOM.
$doc = $file_2->article_doc;
my (@para) = $doc->documentElement->getChildrenByTagName('p');
is(scalar @para, 6, 'article_doc: article 2, right number of paragraphs');
my $text = $para[2]->textContent;
is($text, "It also has some UTF-8 stuff:\x{A0}\x{201C}\x{2014}\x{201D}",
'article_doc: article 2, UTF-8 characters preserved');
# Make sure the filtering has been done for the <daizu:syntax-highlight/>
# element. It should have been replaced by a <pre> element.
$doc = $file_5->article_doc;
my (@pre) = $doc->documentElement->getChildrenByTagName('pre');
is(scalar @pre, 1, 'article_doc: article 5, syntax highlighting done');
is($pre[0]->namespaceURI, 'http://www.w3.org/1999/xhtml',
'article_doc: article 5, new <pre> element in XHTML namespace');
$text = $pre[0]->textContent;
like($text, qr/syntax coloured external file/,
'article_doc: article 5, highlighting on text from XIncluded file');
}
# article_body
{
my $body = $file_1->article_body;
isa_ok($body, 'XML::LibXML::Element', 'article_body: is element');
is($body->localname, 'body', 'article_body: is <body>');
is($body->namespaceURI, 'http://www.w3.org/1999/xhtml',
'article_body: XHTML namespace');
}
# article_content_html4
{
is($file_2->article_content_html4,
"<p>Blog article 2</p>\n\n" .
"<p>This one has three pages but no fold mark, so the first" .
" page break\012should be treated like a fold.</p>\n\n" .
enc("<!-- Unicode text: \x{8A9E} -->\n" .
"<p title=\"Some \x{2018}UTF-8\x{2019} text\">" .
"It also has some UTF-8 stuff:" .
"\x{A0}\x{201C}\x{2014}\x{201D}</p>\n\n") .
"\n\n" .
"<p>Content on page 2.</p>\n\n" .
"\n\n" .
"<p>Content on page 3.</p>\n\n" .
"<p>This is the end of the article.</p>\n",
'article_content_html4: whole article');
is($file_2->article_content_html4(1),
"<p>Blog article 2</p>\n\n" .
"<p>This one has three pages but no fold mark, so the first" .
" page break\012should be treated like a fold.</p>\n\n" .
enc("<!-- Unicode text: \x{8A9E} -->\n" .
"<p title=\"Some \x{2018}UTF-8\x{2019} text\">" .
"It also has some UTF-8 stuff:" .
"\x{A0}\x{201C}\x{2014}\x{201D}</p>\n\n"),
'article_content_html4: page 1');
is($file_2->article_content_html4(2),
"\n\n<p>Content on page 2.</p>\n\n",
'article_content_html4: page 2');
is($file_2->article_content_html4(3),
"\n\n<p>Content on page 3.</p>\n\n" .
"<p>This is the end of the article.</p>\n",
'article_content_html4: page 3');
}
# article_extract
is($file_1->article_extract,
"Blog article 1\n\nThis one has a fold after the first two" .
" paragraphs.\n\nThis text should only appear in the full article" .
" page, not on index pages, and not in feeds except for full-content ones.",
'article_extract: short article');
# Test a longer article, which should exceed the word limit.
is($file_3->article_extract,
"Blog article\x{A0}3\n\nThis blog article is no more interesting" .
" than the other test articles, except for the fact that it has" .
" more text. In fact, there is more text in this article than" .
" will fit into the default size of an article extract used" .
" sometimes in blog feeds. This will \x{2026}",
'article_extract: longer article');
# article_snippet
{
# article with a <daizu:fold/> element
my $snippet = $file_1->article_snippet;
isa_ok($snippet, 'XML::LibXML::Document', 'article_snippet: article 1');
is($snippet->documentElement->localname, 'body',
( run in 0.858 second using v1.01-cache-2.11-cpan-f4a522933cf )