#!/usr/bin/perl use warnings; use strict; use Test::More; use XML::LibXML; use Carp::Assert qw( assert ); use Path::Class qw( file ); use Daizu; use Daizu::Test qw( init_tests ); use Daizu::Util qw( db_select ); init_tests(50); my $cms = Daizu->new($Daizu::Test::TEST_CONFIG); # XHTMLArticle { my $plugin_info = $cms->{article_loaders}{'text/html'}{''}[0]; assert(defined $plugin_info); my ($plugin_object, $plugin_method) = @$plugin_info; is(ref $plugin_object, 'Daizu::Plugin::XHTMLArticle', 'XHTMLArticle: plugin object of right class'); my $file = MockFile->new; my $article = $plugin_object->$plugin_method($cms, $file); ok(defined $article, 'XHTMLArticle: article info'); is(scalar(keys %$article), 1, 'XHTMLArticle: no metadata'); my $doc = $article->{content}; ok(defined $doc, 'XHTMLArticle: content'); isa_ok($doc, 'XML::LibXML::Document', 'XHTMLArticle: content'); my $root = $doc->documentElement; is($root->nodeName, 'body', 'XHTMLArticle: right root elem'); my (@child_elems) = map { $_->nodeType == XML_ELEMENT_NODE ? ($_) : () } $root->getChildNodes(); is(scalar(@child_elems), 5, 'XHTMLArticle: right number of child elems'); is($child_elems[0]->localname, 'p', 'XHTMLArticle: elem 0 is p'); is($child_elems[0]->namespaceURI, 'http://www.w3.org/1999/xhtml', 'XHTMLArticle: elem 0 is XHTML'); is($child_elems[1]->localname, 'fold', 'XHTMLArticle: elem 1 is fold'); is($child_elems[1]->namespaceURI, 'http://www.daizucms.org/ns/html-extension/', 'XHTMLArticle: elem 0 is Daizu extension'); ok($child_elems[2]->findnodes("*[local-name() = 'include']"), 'XHTMLArticle: XInclude not expanded yet'); my $text = $child_elems[3]->textContent; is($text, "More\x{2026}", 'XHTMLArticle: char entity refs expanded'); $text = $child_elems[4]->textContent; my $expected = "UTF-8 characters: (\xA0) (\x{2026})"; assert(utf8::is_utf8($expected)); is($text, $expected, 'XHTMLArticle: UTF-8 chars preserved'); } # PictureArticle { my $plugin_info = $cms->{article_loaders}{'image/*'}{''}[0]; assert(defined $plugin_info); my ($plugin_object, $plugin_method) = @$plugin_info; is(ref $plugin_object, 'Daizu::Plugin::PictureArticle', 'PictureArticle: plugin object of right class'); my $file = $cms->live_wc->file_at_path('foo.com/blog/2005/photos/wasp-on-holly-leaf.jpg'); assert(defined $file); my $article = $plugin_object->$plugin_method($cms, $file); ok(defined $article, 'PictureArticle: article info'); is(scalar(keys %$article), 3, 'PictureArticle: no metadata'); my $doc = $article->{content}; ok(defined $doc, 'PictureArticle: content'); isa_ok($doc, 'XML::LibXML::Document', 'PictureArticle: content'); my $root = $doc->documentElement; is($root->nodeName, 'body', 'PictureArticle: right root elem'); is($root->namespaceURI, 'http://www.w3.org/1999/xhtml', 'PictureArticle: body is XHTML'); # Content of the
element. my (@elems) = map { $_->nodeType == XML_ELEMENT_NODE ? ($_) : () } $root->getChildNodes(); is(scalar(@elems), 1, 'PictureArticle: body has right number of child elems'); is($elems[0]->localname, 'div', 'PictureArticle: elem is div'); is($elems[0]->getAttribute('class'), 'display-picture', 'PictureArticle: div has right class'); # Content of theParagraph.
More…
UTF-8 characters: (\xA0) (\x{2026})
]; $text = encode('UTF-8', $text, Encode::FB_CROAK); assert(!utf8::is_utf8($text)); return \$text; } # vi:ts=4 sw=4 expandtab filetype=perl