Test::XML::Loy - Test XML and XML::Loy objects
use Test::XML::Loy; my $t = Test::XML::Loy->new(<<'XML'); <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <env> <header> <!-- My Greeting --> <greetings> <title style="color: red">Hello!</title> </greetings> </header> <body date="today"> <p>That's all!</p> </body> </env> XML $t->attr_is('env title', 'style', 'color: red') ->attr_is('env body', 'date', 'today') ->text_is('body > p', "That's all!");
Test::XML::Loy allows to test XML documents in the same way as Test::Mojo tests X(HT)ML responses using Mojo::DOM. The code is heavily based on Test::Mojo and implements the same API. The documentation is heavily based on Test::Mojo.
Test::XML::Loy inherits all attributes from Mojo::Base and implements the following new ones.
print $t->loy->to_pretty_XML;
The XML::Loy object to test against.
my $bool = $t->success; $t = $t->success($bool);
True if the last test was successful.
Test::XML::Loy inherits all methods from Mojo::Base and implements the following new ones.
my $xml = Test::XML::Loy->new(<<'EOF'); <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <entry> <fun>Yeah!</fun> <entry> EOF
Constructs a new Test::XML::Loy document. Accepts all parameters supported by XML::Loy.
$t = $t->attr_is('img.cat', 'alt', 'Grumpy cat'); $t = $t->attr_is('img.cat', 'alt', 'Grumpy cat', 'right alt text');
Checks text content of attribute with "attr" in Mojo::DOM at the CSS selectors first matching HTML/XML element for exact match with "at" in Mojo::DOM.
$t = $t->attr_isnt('img.cat', 'alt', 'Calm cat'); $t = $t->attr_isnt('img.cat', 'alt', 'Calm cat', 'different alt text');
Opposite of "attr_is".
$t = $t->attr_like('img.cat', 'alt', qr/Grumpy/); $t = $t->attr_like('img.cat', 'alt', qr/Grumpy/, 'right alt text');
Checks text content of attribute with "attr" in Mojo::DOM at the CSS selectors first matching HTML/XML element for similar match with "at" in Mojo::DOM.
$t = $t->attr_unlike('img.cat', 'alt', qr/Calm/); $t = $t->attr_unlike('img.cat', 'alt', qr/Calm/, 'different alt text');
Opposite of "attr_like".
$t = $t->content_is(<<'XML'); <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Test foo="bar"> <baum>Check!</baum> </Test> XML
Check textual serialization for exact match.
$t = $t->content_isnt(<<'XML'); <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Test foo="bar"> <baum>Check!</baum> </Test> XML
Opposite of "content_is".
$t = $t->content_like(qr/Check!/); $t = $t->content_like(qr/Check!/, 'right content');
Check textual serialization for similar match.
$t = $t->content_unlike(qr/Check!/); $t = $t->content_unlike(qr/Check!/, 'right content');
Opposite of "content_like".
$t = $t->element_count_is('div.foo[x=y]', 5); $t = $t->element_count_is('html body div', 30, 'thirty elements');
Checks the number of HTML/XML elements matched by the CSS selector with "find" in Mojo::DOM.
$t = $t->element_exists('div.foo[x=y]'); $t = $t->element_exists('html head title', 'has a title');
Checks for existence of the CSS selectors first matching HTML/XML element with "at" in Mojo::DOM.
$t = $t->element_exists_not('div.foo[x=y]'); $t = $t->element_exists_not('html head title', 'has no title');
Opposite of "element_exists".
$t = $t->text_is('div.foo[x=y]' => 'Hello!'); $t = $t->text_is('html head title' => 'Hello!', 'right title');
Checks text content of the CSS selectors first matching HTML/XML element for exact match with "at" in Mojo::DOM.
$t = $t->text_isnt('div.foo[x=y]' => 'Hello!'); $t = $t->text_isnt('html head title' => 'Hello!', 'different title');
Opposite of "text_is".
$t = $t->text_like('div.foo[x=y]' => qr/Hello/); $t = $t->text_like('html head title' => qr/Hello/, 'right title');
Checks text content of the CSS selectors first matching HTML/XML element for similar match with "at" in Mojo::DOM.
$t = $t->text_unlike('div.foo[x=y]' => qr/Hello/); $t = $t->text_unlike('html head title' => qr/Hello/, 'different title');
Opposite of "text_like".
https://github.com/Akron/XML-Loy
Copyright (c) 2008-2020 Sebastian Riedel and others.
Copyright (c) 2020-2021, Nils Diewald.
This program is free software, you can redistribute it and/or modify it under the same terms as Perl.
To install XML::Loy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::Loy
CPAN shell
perl -MCPAN -e shell install XML::Loy
For more information on module installation, please visit the detailed CPAN module installation guide.