/[suikacvs]/messaging/manakai/t/DOM-Element.t
Suika

Diff of /messaging/manakai/t/DOM-Element.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by wakaba, Sun Jun 17 13:37:42 2007 UTC revision 1.3 by wakaba, Sun Jul 8 13:04:39 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
2  use strict;  use strict;
3  use Test;  use Test;
4  BEGIN { plan tests => 38 }  BEGIN { plan tests => 55 }
5    
6  require Message::DOM::DOMImplementation;  require Message::DOM::DOMImplementation;
7  use Message::Util::Error;  use Message::Util::Error;
8    
9  my $dom = Message::DOM::DOMImplementation->____new;  my $dom = Message::DOM::DOMImplementation->____new;
 my $doc = $dom->create_document;  
10    
11    {
12      my $doc = $dom->create_document;
13      my $el = $doc->create_element ('et1');
14    
15      ok 0+@{$el->attributes}, 0, 'create_element->attributes @{} 0+ [0]';
16    
17      my $dt = $doc->create_document_type_definition ('dt');
18      my $et = $doc->create_element_type_definition ('et1');
19      my $at = $doc->create_attribute_definition ('dattr1');
20      $at->default_type ($at->EXPLICIT_DEFAULT);
21      $at->text_content ('dattr1 default ');
22      $et->set_attribute_definition_node ($at);
23      $dt->set_element_type_definition_node ($et);
24      $doc->append_child ($dt);
25      my $el2 = $doc->create_element ('et1');
26    
27      ok 0+@{$el2->attributes}, 1, 'create_element->attributes @{} 0+ [1]';
28    
29      ok $el2->has_attribute ('dattr1') ? 1 : 0, 1, 'create_element->has_attr [1]';
30    
31      my $an = $el2->get_attribute_node ('dattr1');
32      ok UNIVERSAL::isa ($an, 'Message::IF::Attr') ? 1 : 0, 1, 'ce->def if [1]';
33      ok $an->text_content, 'dattr1 default ', 'ce->def tx [1]';
34      ok $an->specified ? 1 : 0, 0, 'ce->def specified [1]';
35    
36      $doc->dom_config->set_parameter
37          (q<http://suika.fam.cx/www/2006/dom-config/dtd-default-attribute> => 0);
38      
39      my $el3 = $doc->create_element ('et1');
40      ok 0+@{$el3->attributes}, 0, 'create_element->attributes @{} 0+ [2]';
41    }
42    
43    {
44      my $doc = $dom->create_document;
45      my $el = $doc->create_element_ns (undef, 'et1');
46    
47      ok 0+@{$el->attributes}, 0, 'create_element->attributes @{} 0+ [0]';
48    
49      my $dt = $doc->create_document_type_definition ('dt');
50      my $et = $doc->create_element_type_definition ('et1');
51      my $at = $doc->create_attribute_definition ('dattr1');
52      $at->default_type ($at->EXPLICIT_DEFAULT);
53      $at->text_content ('dattr1 default ');
54      $et->set_attribute_definition_node ($at);
55      $dt->set_element_type_definition_node ($et);
56      $doc->append_child ($dt);
57      my $el2 = $doc->create_element ('et1');
58    
59      ok 0+@{$el2->attributes}, 1, 'create_element->attributes @{} 0+ [1]';
60    
61      ok $el2->has_attribute ('dattr1') ? 1 : 0, 1, 'create_element->has_attr [1]';
62    
63      my $an = $el2->get_attribute_node ('dattr1');
64      ok UNIVERSAL::isa ($an, 'Message::IF::Attr') ? 1 : 0, 1, 'ce->def if [1]';
65      ok $an->text_content, 'dattr1 default ', 'ce->def tx [1]';
66      ok $an->specified ? 1 : 0, 0, 'ce->def specified [1]';
67    
68      $doc->dom_config->set_parameter
69          (q<http://suika.fam.cx/www/2006/dom-config/dtd-default-attribute> => 0);
70      
71      my $el3 = $doc->create_element ('et1');
72      ok 0+@{$el3->attributes}, 0, 'create_element->attributes @{} 0+ [2]';
73    }
74    
75    my $doc = $dom->create_document;
76  my $el = $doc->create_element ('element');  my $el = $doc->create_element ('element');
77    
78  for my $prop (qw/manakai_base_uri/) {  for my $prop (qw/manakai_base_uri/) {
# Line 62  for my $method (qw/set_attribute_node se Line 126  for my $method (qw/set_attribute_node se
126        "$method get_attribute_ns [3]";        "$method get_attribute_ns [3]";
127  }  }
128    
129    ## |attributes|
130    {
131      my $el = $doc->create_element ('e');
132      ok $el->can ('attributes') ? 1 : 0, 1, 'Element->attributes can';
133    
134      my $as = $el->attributes;
135      ok UNIVERSAL::isa ($as, 'Message::IF::NamedNodeMap') ? 1 : 0, 1, 'E->as if';
136      
137      $el->set_attribute (at1 => 'value');
138      ok $as->get_named_item ('at1'), $el->get_attribute_node ('at1'),
139          'Element->attributes get_named_item get_attr_node';
140    }
141    
142  =head1 LICENSE  =head1 LICENSE
143    
144  Copyright 2007 Wakaba <w@suika.fam.cx>  Copyright 2007 Wakaba <w@suika.fam.cx>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24