4 |
BEGIN { plan tests => 4 } |
BEGIN { plan tests => 4 } |
5 |
|
|
6 |
require Message::DOM::DOMImplementation; |
require Message::DOM::DOMImplementation; |
7 |
|
use Message::Util::Error; |
8 |
|
|
9 |
my $dom = Message::DOM::DOMImplementation->____new; |
my $dom = Message::DOM::DOMImplementation->____new; |
10 |
my $doc = $dom->create_document; |
my $doc = $dom->create_document; |
510 |
ok $node3->previous_sibling, $node2, $parent->node_name."3->previous_sibling [3]"; |
ok $node3->previous_sibling, $node2, $parent->node_name."3->previous_sibling [3]"; |
511 |
} |
} |
512 |
|
|
513 |
|
## |prefix| setter |
514 |
|
for my $node (create_nodes ()) { |
515 |
|
$node->manakai_set_read_only (0); |
516 |
|
|
517 |
|
$node->prefix ('non-null'); |
518 |
|
if ($node->node_type == $node->ELEMENT_NODE or |
519 |
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
520 |
|
ok $node->prefix, 'non-null', $node->node_name . '->prefix (non-null)'; |
521 |
|
} else { |
522 |
|
ok $node->prefix, undef, $node->node_name . '->prefix (non-null)'; |
523 |
|
} |
524 |
|
|
525 |
|
$node->prefix (undef); |
526 |
|
if ($node->node_type == $node->ELEMENT_NODE or |
527 |
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
528 |
|
ok $node->prefix, undef, $node->node_name . '->prefix (null)'; |
529 |
|
} else { |
530 |
|
ok $node->prefix, undef, $node->node_name . '->prefix (null)'; |
531 |
|
} |
532 |
|
|
533 |
|
$node->manakai_set_read_only (1); |
534 |
|
my $err_type; |
535 |
|
try { |
536 |
|
$node->prefix ('non-null'); |
537 |
|
} catch Message::IF::DOMException with { |
538 |
|
my $err = shift; |
539 |
|
$err_type = $err->type; |
540 |
|
}; |
541 |
|
if ($node->node_type == $node->ELEMENT_NODE or |
542 |
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
543 |
|
ok $err_type, 'NO_MODIFICATION_ALLOWED_ERR', |
544 |
|
$node->node_name . '->prefix exception (read-only)'; |
545 |
|
ok $node->prefix, undef, $node->node_name . '->prefix (read-only)'; |
546 |
|
} else { |
547 |
|
ok $err_type, undef, $node->node_name . '->prefix exception (read-only)'; |
548 |
|
ok $node->prefix, undef, $node->node_name . '->prefix (read-only)'; |
549 |
|
} |
550 |
|
} |
551 |
|
|
552 |
|
## |text_content| |
553 |
|
{ |
554 |
|
my $doc2 = $doc->implementation->create_document; |
555 |
|
$doc2->dom_config->set_parameter |
556 |
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 1); |
557 |
|
for my $node ( |
558 |
|
$doc2, |
559 |
|
$doc->create_document_type_definition ('dt1'), |
560 |
|
$doc->implementation->create_document_type ('doctype1'), |
561 |
|
$doc->create_notation ('notation1'), |
562 |
|
$doc->create_element_type_definition ('et1'), |
563 |
|
) { |
564 |
|
ok $node->can ('text_content') ? 1 : 0, 1, |
565 |
|
$node->node_name . '->can text_content'; |
566 |
|
|
567 |
|
ok $node->text_content, undef, $node->node_name . '->text_content'; |
568 |
|
|
569 |
|
$node->manakai_set_read_only (0); |
570 |
|
$node->text_content ('new-text-content'); |
571 |
|
ok $node->text_content, undef, $node->node_name . '->text_content set'; |
572 |
|
|
573 |
|
$node->manakai_set_read_only (1); |
574 |
|
$node->text_content ('new-text-content'); |
575 |
|
ok $node->text_content, undef, |
576 |
|
$node->node_name . '->text_content set (read-only)'; |
577 |
|
} |
578 |
|
|
579 |
|
$doc2->dom_config->set_parameter |
580 |
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 0); |
581 |
|
for my $node ( |
582 |
|
$doc2, |
583 |
|
$doc->create_attribute ('attr1'), |
584 |
|
$doc->create_attribute_definition ('at1'), |
585 |
|
$doc->create_element ('element1'), |
586 |
|
$doc->create_general_entity ('entity1'), |
587 |
|
$doc->create_entity_reference ('entity-reference1'), |
588 |
|
$doc->create_document_fragment, |
589 |
|
) { |
590 |
|
ok $node->can ('text_content') ? 1 : 0, 1, |
591 |
|
$node->node_name . '->can text_content'; |
592 |
|
|
593 |
|
ok $node->text_content, '', $node->node_name . '->text_content'; |
594 |
|
|
595 |
|
$node->manakai_set_read_only (0); |
596 |
|
$node->text_content ('text1'); |
597 |
|
ok $node->text_content, 'text1', $node->node_name . '->text_content set'; |
598 |
|
ok 0+@{$node->child_nodes}, 1, |
599 |
|
$node->node_name . '->text_content set child_nodes length'; |
600 |
|
|
601 |
|
$node->text_content (''); |
602 |
|
ok $node->text_content, '', $node->node_name . '->text_content set empty'; |
603 |
|
ok 0+@{$node->child_nodes}, 0, |
604 |
|
$node->node_name . '->text_content set empty child_nodes length'; |
605 |
|
|
606 |
|
$node->text_content ('text2'); |
607 |
|
$node->text_content (''); |
608 |
|
ok $node->text_content, '', $node->node_name . '->text_content set empty'; |
609 |
|
ok 0+@{$node->child_nodes}, 0, |
610 |
|
$node->node_name . '->text_content set empty child_nodes length'; |
611 |
|
|
612 |
|
$node->text_content ('text3'); |
613 |
|
$node->manakai_set_read_only (1); |
614 |
|
try { |
615 |
|
$node->text_content ('new-text-content'); |
616 |
|
ok undef, 'NO_MODIFICATION_ALLOWED_ERR', |
617 |
|
$node->node_name . '->text_content set (read-only)'; |
618 |
|
} catch Message::IF::DOMException with { |
619 |
|
my $err = shift; |
620 |
|
ok $err->type, 'NO_MODIFICATION_ALLOWED_ERR', |
621 |
|
$node->node_name . '->text_content set (read-only)'; |
622 |
|
}; |
623 |
|
ok $node->text_content, 'text3', |
624 |
|
$node->node_name . '->text_content set (read-only) text_content'; |
625 |
|
} |
626 |
|
|
627 |
|
|
628 |
|
for (0..2) { |
629 |
|
my $el; |
630 |
|
my $ce; |
631 |
|
|
632 |
|
[ |
633 |
|
sub { |
634 |
|
$el = $doc->create_element ('nestingElement'); |
635 |
|
$ce = $doc->create_element ('el2'); |
636 |
|
}, |
637 |
|
sub { |
638 |
|
$el = $doc->create_element ('elementWithEntityReference'); |
639 |
|
$ce = $doc->create_entity_reference ('ent'); |
640 |
|
$ce->manakai_set_read_only (0, 1); |
641 |
|
}, |
642 |
|
sub { |
643 |
|
$el = $doc->create_general_entity ('generalEntityWithChild'); |
644 |
|
$ce = $doc->create_element ('el'); |
645 |
|
$el->manakai_set_read_only (0, 1); |
646 |
|
}, |
647 |
|
]->[$_]->(); |
648 |
|
$el->append_child ($ce); |
649 |
|
|
650 |
|
ok $el->text_content, '', $el->node_name . '->text_content [1]'; |
651 |
|
|
652 |
|
$ce->text_content ('gc'); |
653 |
|
ok $el->text_content, 'gc', $el->node_name . '->text_content [2]'; |
654 |
|
|
655 |
|
$el->manakai_append_text ('cc'); |
656 |
|
ok $el->text_content, 'gccc', $el->node_name . '->text_content [3]'; |
657 |
|
|
658 |
|
$el->text_content ('nc'); |
659 |
|
ok $el->text_content, 'nc', $el->node_name . '->text_content [4]'; |
660 |
|
ok 0+@{$el->child_nodes}, 1, |
661 |
|
$el->node_name . '->text_content child_nodes length [4]'; |
662 |
|
ok $ce->parent_node, undef, |
663 |
|
$el->node_name . '->text_content old_child parent_node [4]'; |
664 |
|
} |
665 |
|
} |
666 |
|
|
667 |
## TODO: parent_node tests, as with append_child tests |
## TODO: parent_node tests, as with append_child tests |
668 |
|
|
669 |
|
## TODO: text_content tests for CharacterData and PI |
670 |
|
|
671 |
|
## TODO: manakai_read_only tests |
672 |
|
|
673 |
sub create_nodes () { |
sub create_nodes () { |
674 |
( |
( |
675 |
$doc->create_attribute ('attr1'), |
$doc->create_attribute ('attr1'), |