++ed by:
BEROV AKRON KARJALA MHOWARD

4 PAUSE users
2 non-PAUSE users.

Author image Nils Diewald
and 1 contributors

NAME

Test::XML::Loy - Test XML and XML::Loy objects

SYNOPSIS

  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&#39;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!");

DESCRIPTION

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.

ATTRIBUTES

Test::XML::Loy inherits all attributes from Mojo::Base and implements the following new ones.

loy

  print $t->loy->to_pretty_XML;

The XML::Loy object to test against.

success

  my $bool = $t->success;
  $t       = $t->success($bool);

True if the last test was successful.

METHODS

Test::XML::Loy inherits all methods from Mojo::Base and implements the following new ones.

new

  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.

attr_is

  $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.

attr_isnt

  $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".

attr_like

  $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.

attr_unlike

  $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".

content_is

  $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.

content_isnt

  $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".

content_like

  $t = $t->content_like(qr/Check!/);
  $t = $t->content_like(qr/Check!/, 'right content');

Check textual serialization for similar match.

content_unlike

  $t = $t->content_unlike(qr/Check!/);
  $t = $t->content_unlike(qr/Check!/, 'right content');

Opposite of "content_like".

element_count_is

  $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.

element_exists

  $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.

element_exists_not

  $t = $t->element_exists_not('div.foo[x=y]');
  $t = $t->element_exists_not('html head title', 'has no title');

Opposite of "element_exists".

text_is

  $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.

text_isnt

  $t = $t->text_isnt('div.foo[x=y]' => 'Hello!');
  $t = $t->text_isnt('html head title' => 'Hello!', 'different title');

Opposite of "text_is".

text_like

  $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.

text_unlike

  $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".

AVAILABILITY

  https://github.com/Akron/XML-Loy

COPYRIGHT AND LICENSE

Copyright (c) 2008-2020 Sebastian Riedel and others.

Copyright (C) 2020, Nils Diewald.

This program is free software, you can redistribute it and/or modify it under the same terms as Perl.