1#!/usr/bin/env perl 2 3# https://rt.cpan.org/Ticket/Display.html?id=58065 4# 5# Test that the parser-factory instance classes allow the parsing of the 6# <nil /> tag whether $RPC::XML::ALLOW_NIL is set or not. This is to allow 7# liberal acceptance of the tag in what we take in. Production of the tag is 8# still limited to only when the flag is set. 9 10## no critic(RequireInterpolationOfMetachars) 11 12use strict; 13use warnings; 14 15use Module::Load; 16use Test::More; 17 18use RPC::XML; 19use RPC::XML::Parser::XMLParser; 20 21plan tests => 8; 22 23my ($parser, $req_message, $res_message, $parsed); 24my $can_libxml = eval { load RPC::XML::Parser::XMLLibXML; 1; }; 25 26# Create mock request and response messages that contain nils in them by first 27# setting the flag. We'll then unset the flag for the tests. 28 29$RPC::XML::ALLOW_NIL = 1; 30 31$req_message = RPC::XML::request->new( 32 'foo', 33 RPC::XML::nil->new() 34); 35$res_message = RPC::XML::response->new( 36 RPC::XML::nil->new() 37); 38 39$RPC::XML::ALLOW_NIL = 0; 40 41# To test this, instantiate each parser then call the ->parse() method with 42# both the request and response message that contain nil tags. 43 44# First test the class we always have, RPC::XML::Parser::XMLParser 45$parser = RPC::XML::Parser::XMLParser->new(); 46 47# Test-parse the request message 48$parsed = $parser->parse($req_message->as_string); 49 50isa_ok($parsed, 'RPC::XML::request', '$parsed content'); 51SKIP: { 52 if (ref($parsed) ne 'RPC::XML::request') 53 { 54 skip 'Parsed value corrupted, cannot test nil value', 1; 55 } 56 57 isa_ok($parsed->args->[0], 'RPC::XML::nil', '$parsed->args->[0]'); 58} 59 60# Test-parse the response message 61$parsed = $parser->parse($res_message->as_string); 62 63isa_ok($parsed, 'RPC::XML::response', '$parsed content'); 64SKIP: { 65 if (ref($parsed) ne 'RPC::XML::response') 66 { 67 skip 'Parsed value corrupted, cannot test nil value', 1; 68 } 69 70 isa_ok($parsed->value, 'RPC::XML::nil', '$parsed->value'); 71} 72 73# Next, test RPC::XML::Parser::XMLLibXML (which we might not have) 74SKIP: { 75 if (! $can_libxml) 76 { 77 skip 'XML::LibXML not installed', 4; 78 } 79 80 $parser = RPC::XML::Parser::XMLLibXML->new(); 81 82 # Test-parse the request message 83 $parsed = $parser->parse($req_message->as_string); 84 85 isa_ok($parsed, 'RPC::XML::request', '$parsed content'); 86 SKIP: { 87 if (ref($parsed) ne 'RPC::XML::request') 88 { 89 skip 'Parsed value corrupted, cannot test nil value', 1; 90 } 91 92 isa_ok($parsed->args->[0], 'RPC::XML::nil', '$parsed->args->[0]'); 93 } 94 95 # Test-parse the response message 96 $parsed = $parser->parse($res_message->as_string); 97 98 isa_ok($parsed, 'RPC::XML::response', '$parsed content'); 99 SKIP: { 100 if (ref($parsed) ne 'RPC::XML::response') 101 { 102 skip 'Parsed value corrupted, cannot test nil value', 1; 103 } 104 105 isa_ok($parsed->value, 'RPC::XML::nil', '$parsed->value'); 106 } 107} 108 109exit; 110