#!/usr/bin/perl
BEGIN { use_ok(
'XML::DOMBacked'
) };
Foo->has_properties(
'name'
,
'foo:size'
);
Foo->has_attributes(
'uri'
,
'foo:id'
);
Foo->has_a(
'Bar'
,
'Baz'
);
Bar->has_properties(
'BAR:age'
);
sub
nodename {
'BAR:bar'
}
Baz->has_many(
'bars'
=> {
class
=>
'Bar'
},
names
=>
'test:name'
);
ok(
my
$f
= Foo->new );
ok(
my
$b
= Bar->new );
ok(
my
$ns
= Foo->lookup_namespace(
'foo'
) );
isa_ok(
$b
,
'Bar'
);
isa_ok(
$b
,
'Foo'
);
ok(
$f
->name(
'test'
) );
is(
$f
->name,
'test'
,
"name is test"
);
ok(
$f
->size(
'large'
) );
is(
$f
->size,
'large'
,
'namespaced properties work'
);
ok(
$b
->size(
'small'
) );
ok(
$b
->age( 26 ) );
ok(
$b
->id(
'x102'
) );
is(
$b
->id,
'x102'
,
"namespaced attributes work"
);
ok(
$f
->bar(
$b
) );
is(
$f
->bar->as_string,
$b
->as_string );
ok(
my
$baz
= Baz->new );
ok(
$baz
->add_name(
"James"
) );
ok(
$baz
->add_name(
"Katrien"
) );
ok(
my
@names
=
$baz
->names );
is(
scalar
(
@names
), 2,
"got two names"
);
ok(
$baz
->remove_name(
'James'
) );
is(
scalar
(
$baz
->names ), 1 );
ok(
my
$metro
= Bar->new->name(
'Metro'
) );
ok(
my
$vibe
= Bar->new->name(
'Vibe'
) );
ok(
$baz
->add_bar(
$metro
) );
ok(
$baz
->add_bar(
$vibe
) );
ok(
my
@bars
=
$baz
->bars() );
is(
scalar
(
@bars
), 2 );
is(
$bars
[0],
$metro
);
is(
$bars
[1],
$vibe
);
ok(
$baz
->remove_bar(
$metro
) );
ok(
$baz
->remove_bar(
$bars
[1] ) );
is(
scalar
(
$baz
->bars), 0,
"no more bars"
);
ok(
$f
->Baz(
$baz
) );
is(
$baz
,
$f
->Baz );
1;