Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67a
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Perl Modules

    Test::HTML::Content 0.07

    Download button

    No screenshots available
    Downloads: 332  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Max Maischein | More programs
    Perl Artistic License / FREE
    November 6th, 2007, 01:05 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    Test::HTML::Content description

    A Perl extension for testing HTML output.

    Test::HTML::Content is a Perl extension for testing HTML output.

    SYNOPSIS

    use Test::HTML::Content( tests => 13 );
    $HTML = "< html >< title >A test page< /title >< body >< p >Home page< /p >
    < img src='http://www.perl.com/camel.png' alt='camel' >
    < a href='http://www.perl.com' >Perl< /a >
    < img src='http://www.perl.com/camel.png' alt='more camel' >
    < !--Hidden message-- >< /body >< /html >";

    link_ok($HTML,"http://www.perl.com","We link to Perl");
    no_link($HTML,"http://www.pearl.com","We have no embarassing typos");
    link_ok($HTML,qr"http://[a-z]+.perl.com","We have a link to perl.com");

    title_count($HTML,1,"We have one title tag");
    title_ok($HTML,qr/test/);

    tag_ok($HTML,"img", {src => "http://www.perl.com/camel.png"},
    "We have an image of a camel on the page");
    tag_count($HTML,"img", {src => "http://www.perl.com/camel.png"}, 2,
    "In fact, we have exactly two camel images on the page");
    no_tag($HTML,"blink",{}, "No annoying blink tags ..." );

    # We can check the textual contents
    text_ok($HTML,"Perl");

    # We can also check the contents of comments
    comment_ok($HTML,"Hidden message");


    # Advanced stuff

    # Using a regular expression to match against
    # tag attributes - here checking there are no ugly styles
    no_tag($HTML,"p",{ style => qr'ugly$' }, "No ugly styles" );

    # REs also can be used for substrings in comments
    comment_ok($HTML,qr"[hH]iddens+mess");

    # and if you have XML::LibXML or XML::XPath, you can
    # even do XPath queries yourself:
    xpath_ok($HTML,'/html/body/p','HTML is somewhat wellformed');
    no_xpath($HTML,'/html/head/p','HTML is somewhat wellformed');


    This is a module to test the HTML output of your programs in simple test scripts. It can test a scalar (presumably containing HTML) for the presence (or absence, or a specific number) of tags having (or lacking) specific attributes. Unspecified attributes are ignored, and the attribute values can be specified as either scalars (meaning a match succeeds if the strings are identical) or regular expressions (meaning that a match succeeds if the actual attribute value is matched by the given RE) or undef (meaning that the attribute must not be present).

    If you want to specify or test the deeper structure of the HTML (for example, META tags within the BODY) or the (textual) content of tags, you will have to resort to xpath_ok,xpath_count and no_xpath, which take an XPath expression. If you find yourself crafting very complex XPath expression to verify the structure of your output, it is time to rethink your testing process and maybe use a template based solution or simply compare against prefabricated files as a whole.

    The used HTML parser is HTML::TokeParser, the used XPath module is XML::XPath or XML::LibXML. XML::XPath needs valid xHTML, XML::LibXML will try its best to force your code into xHTML, but it is best to supply valid xHTML (snippets) to the test functions.

    If no XPath parsers/interpreters are available, the tests will automatically skip, so your users won't need to install XML::XPath or XML::LibXML. The module then falls back onto a crude implementation of the core functions for tags, links, comments and text, and the diagnostic output of the tests varies a bit.

    The test functionality is derived from Test::Builder, and the export behaviour is the same. When you use Test::HTML::Content, a set of HTML testing functions is exported into the namespace of the caller.


    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    testing HTML output | testing HTML content | Perl extension | HTML | output | content

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM