1#!/usr/bin/perl -w
2use Test::More tests => 16;
3BEGIN {use_ok('Pod::WSDL::Writer')}
4use strict;
5use warnings;
6
7# ****************************************************************
8# test constructor()
9
10my $wr = new Pod::WSDL::Writer(pretty => 1, withDocumentation => 1);
11
12ok($wr->{_pretty} == 1, 'Constructor: Read argument pretty correctly.');
13ok($wr->{_withDocumentation} == 1, 'Constructor: Read argument withDocumentation correctly.');
14ok($wr->{_indent} == 1, 'Constructor: Initialized indentation correctly.');
15ok($wr->{_lastTag} eq '', 'Constructor: Initialized last tag correctly.');
16ok((ref $wr->{_faultMessageWritten} eq 'HASH'), 'Constructor: Initialized "faultMessageWritten" correctly.');
17ok($wr->output eq '<?xml version="1.0" encoding="UTF-8"?>' . "\n", 'Constructor: Initialized XML::Writer correctly.');
18
19# ****************************************************************
20# test wrNewLine()
21$wr->startTag('bla');
22$wr->wrNewLine();
23$wr->endTag('bla');
24my $expectedOutput =<<EOU;
25<?xml version="1.0" encoding="UTF-8"?>
26<bla>
27</bla>
28EOU
29ok($wr->output . "\n" eq $expectedOutput, 'wrNewLine works.');
30
31# ****************************************************************
32# test wrElem()
33$wr = new Pod::WSDL::Writer();
34$wr->wrElem('empty', 'foo', bar => 1, bloerch => 'ggg');
35$expectedOutput =<<EOU;
36<?xml version="1.0" encoding="UTF-8"?>
37<foo bar="1" bloerch="ggg" />
38EOU
39ok($wr->output . "\n" eq $expectedOutput, 'Writing empty elements works.');
40
41$wr = new Pod::WSDL::Writer();
42$wr->wrElem('start', 'foo', bar => 1, bloerch => 'ggg');
43$wr->wrElem('end', 'foo', bar => 1, bloerch => 'ggg');
44$expectedOutput =<<EOU;
45<?xml version="1.0" encoding="UTF-8"?>
46<foo bar="1" bloerch="ggg"></foo>
47EOU
48ok($wr->output . "\n" eq $expectedOutput, 'Writing non empty elements works.');
49
50# ****************************************************************
51# test wrDoc()
52$wr = new Pod::WSDL::Writer(withDocumentation => 1);
53$wr->wrElem('start', 'foo', bar => 1, bloerch => 'ggg');
54$wr->wrDoc('This is my documentation.');
55$wr->wrElem('end', 'foo', bar => 1, bloerch => 'ggg');
56$expectedOutput =<<EOU;
57<?xml version="1.0" encoding="UTF-8"?>
58<foo bar="1" bloerch="ggg"><wsdl:documentation>This is my documentation.</wsdl:documentation></foo>
59EOU
60ok($wr->output . "\n" eq $expectedOutput, 'wrDoc works.');
61
62$wr = new Pod::WSDL::Writer(withDocumentation => 0);
63$wr->wrElem('start', 'foo', bar => 1, bloerch => 'ggg');
64$wr->wrDoc('This is my documentation.');
65$wr->wrElem('end', 'foo', bar => 1, bloerch => 'ggg');
66$expectedOutput =<<EOU;
67<?xml version="1.0" encoding="UTF-8"?>
68<foo bar="1" bloerch="ggg"></foo>
69EOU
70ok($wr->output . "\n" eq $expectedOutput, 'wrDoc writes no documentation when object not initialized with withDocumentation.');
71
72# ****************************************************************
73# test withDocumentation()
74$wr = new Pod::WSDL::Writer(withDocumentation => 1);
75$wr->withDocumentation(0);
76$wr->wrElem('start', 'foo', bar => 1, bloerch => 'ggg');
77$wr->wrDoc('This is my documentation.');
78$wr->wrElem('end', 'foo', bar => 1, bloerch => 'ggg');
79$expectedOutput =<<EOU;
80<?xml version="1.0" encoding="UTF-8"?>
81<foo bar="1" bloerch="ggg"></foo>
82EOU
83ok($wr->output . "\n" eq $expectedOutput, 'wrDoc works.');
84
85$wr = new Pod::WSDL::Writer(withDocumentation => 0);
86$wr->withDocumentation(1);
87$wr->wrElem('start', 'foo', bar => 1, bloerch => 'ggg');
88$wr->wrDoc('This is my documentation.');
89$wr->wrElem('end', 'foo', bar => 1, bloerch => 'ggg');
90$expectedOutput =<<EOU;
91<?xml version="1.0" encoding="UTF-8"?>
92<foo bar="1" bloerch="ggg"><wsdl:documentation>This is my documentation.</wsdl:documentation></foo>
93EOU
94ok($wr->output . "\n" eq $expectedOutput, 'wrDoc writes no documentation when object not initialized with withDocumentation.');
95
96# ****************************************************************
97# test registerWrittenFaultMessage() and faultMessageWritten()
98$wr->registerWrittenFaultMessage('bar');
99ok($wr->faultMessageWritten('bar'), 'Registering written fault messages seems to work.');
100
101# ****************************************************************
102# test AUTOLOADING
103eval {$wr->bla;};
104ok($@ =~ /Can't locate object method "bla" via package "XML::Writer"/, 'AUTOLOADER using XML::Writer correctly.')
105