Source

Fiction-XML / perl / modules / XML-Grammar-Fiction / t / screenplay / to-xhtml.t

#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use lib './t/lib';

use Test::More tests => 6;

use File::Spec;

use XML::LibXML;

use XML::Grammar::Screenplay::ToHTML;

my @tests = (qw(
        with-internal-description
        with-img-element-inside-paragraphs
    ));

sub load_xml
{
    my $path = shift;

    open my $in, "<", $path;
    my $contents;
    {
        local $/;
        $contents = <$in>
    }
    close($in);
    return $contents;
}

# TEST:$num_texts=2

my $converter = XML::Grammar::Screenplay::ToHTML->new({
        data_dir => File::Spec->catdir(File::Spec->curdir(), "extradata"),
    });

foreach my $fn (@tests)
{
    my $xhtml_text = $converter->translate_to_html({
            source => { file => "t/screenplay/data/xml/$fn.xml", },
            output => "string",
        }
        );

    my $parser = XML::LibXML->new();

    $parser->load_ext_dtd(0);

    my $doc = $parser->parse_string($xhtml_text);

    my $xpc = XML::LibXML::XPathContext->new();
    $xpc->registerNs('x', q{http://www.w3.org/1999/xhtml});
    # TEST*$num_texts
    is (
        scalar(() = $xpc->find(q{//x:html}, $doc)),
        1,
        "Found one article with id index",
    );

    # TEST*$num_texts
    ok (
        (scalar(() = $xpc->find(q{//x:div[@class='saying']}, $doc))
            >=
            1
        ),
        "Found role=description sections",
    );

    # TEST*$num_texts
    ok (
        (scalar(() = $xpc->find(q{//x:div[@class='saying']/x:p/x:strong[@class='sayer']}, $doc))
            >=
            1
        ),
        "Found role=description sections",
    );

}

1;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.