| 1 |
# $Id$ |
|---|
| 2 |
|
|---|
| 3 |
use strict; |
|---|
| 4 |
|
|---|
| 5 |
use Test::More tests => 32; |
|---|
| 6 |
use XML::Atom::Content; |
|---|
| 7 |
|
|---|
| 8 |
my $content; |
|---|
| 9 |
|
|---|
| 10 |
$content = XML::Atom::Content->new; |
|---|
| 11 |
isa_ok $content, 'XML::Atom::Content'; |
|---|
| 12 |
ok $content->elem; |
|---|
| 13 |
$content->type('image/jpeg'); |
|---|
| 14 |
is $content->type, 'image/jpeg'; |
|---|
| 15 |
$content->type('application/gzip'); |
|---|
| 16 |
is $content->type, 'application/gzip'; |
|---|
| 17 |
|
|---|
| 18 |
$content = XML::Atom::Content->new('This is a test.'); |
|---|
| 19 |
is $content->body, 'This is a test.'; |
|---|
| 20 |
is $content->mode, 'xml'; |
|---|
| 21 |
|
|---|
| 22 |
$content = XML::Atom::Content->new(Body => 'This is a test.'); |
|---|
| 23 |
is $content->body, 'This is a test.'; |
|---|
| 24 |
is $content->mode, 'xml'; |
|---|
| 25 |
|
|---|
| 26 |
$content = XML::Atom::Content->new(Body => 'This is a test.', Type => 'foo/bar'); |
|---|
| 27 |
is $content->body, 'This is a test.'; |
|---|
| 28 |
is $content->mode, 'xml'; |
|---|
| 29 |
is $content->type, 'foo/bar'; |
|---|
| 30 |
|
|---|
| 31 |
$content = XML::Atom::Content->new; |
|---|
| 32 |
$content->body('This is a test.'); |
|---|
| 33 |
is $content->body, 'This is a test.'; |
|---|
| 34 |
is $content->mode, 'xml'; |
|---|
| 35 |
$content->type('foo/bar'); |
|---|
| 36 |
is $content->type, 'foo/bar'; |
|---|
| 37 |
|
|---|
| 38 |
$content = XML::Atom::Content->new; |
|---|
| 39 |
$content->body('<p>This is a test with XHTML.</p>'); |
|---|
| 40 |
is $content->body, '<p>This is a test with XHTML.</p>'; |
|---|
| 41 |
is $content->mode, 'xml'; |
|---|
| 42 |
|
|---|
| 43 |
$content = XML::Atom::Content->new; |
|---|
| 44 |
$content->body('<p>This is a test with invalid XHTML.'); |
|---|
| 45 |
is $content->body, '<p>This is a test with invalid XHTML.'; |
|---|
| 46 |
is $content->mode, 'escaped'; |
|---|
| 47 |
|
|---|
| 48 |
$content = XML::Atom::Content->new; |
|---|
| 49 |
$content->body("This is a test that should use base64\x7f."); |
|---|
| 50 |
$content->type('text/plain'); |
|---|
| 51 |
is $content->mode, 'base64'; |
|---|
| 52 |
is $content->body, "This is a test that should use base64\x7f."; |
|---|
| 53 |
|
|---|
| 54 |
$content = XML::Atom::Content->new; |
|---|
| 55 |
$content->body("My name is \xe5\xae\xae\xe5\xb7\x9d."); |
|---|
| 56 |
is $content->mode, 'xml'; |
|---|
| 57 |
is $content->body, "My name is \xe5\xae\xae\xe5\xb7\x9d."; |
|---|
| 58 |
|
|---|
| 59 |
$content = XML::Atom::Content->new; |
|---|
| 60 |
$content->type('text/plain'); |
|---|
| 61 |
eval { $content->body("Non-printable: " . chr(578)) }; |
|---|
| 62 |
is $content->mode, 'base64'; |
|---|
| 63 |
is $content->body, un_utf8("Non-printable: " . chr(578)); |
|---|
| 64 |
|
|---|
| 65 |
# 1.0 with xhtml |
|---|
| 66 |
$content = XML::Atom::Content->new(Version => 1.0); |
|---|
| 67 |
$content->body("<div>foo bar</div>"); |
|---|
| 68 |
|
|---|
| 69 |
is $content->type, 'xhtml'; |
|---|
| 70 |
is $content->body, "<div>foo bar</div>"; |
|---|
| 71 |
|
|---|
| 72 |
# 1.0 with html |
|---|
| 73 |
$content = XML::Atom::Content->new(Version => 1.0); |
|---|
| 74 |
$content->body("<p>foo bar"); |
|---|
| 75 |
|
|---|
| 76 |
is $content->type, 'html'; |
|---|
| 77 |
is $content->body, "<p>foo bar"; |
|---|
| 78 |
|
|---|
| 79 |
# 1.0 as text |
|---|
| 80 |
$content = XML::Atom::Content->new(Version => 1.0); |
|---|
| 81 |
$content->body("foo bar"); |
|---|
| 82 |
$content->type('text'); |
|---|
| 83 |
|
|---|
| 84 |
is $content->type, 'text'; |
|---|
| 85 |
is $content->body, "foo bar"; |
|---|
| 86 |
|
|---|
| 87 |
# 1.0 as binary |
|---|
| 88 |
$content = XML::Atom::Content->new(Version => 1.0); |
|---|
| 89 |
$content->type('image/jpeg'); |
|---|
| 90 |
$content->body("\xff\xde\xde\xde"); |
|---|
| 91 |
|
|---|
| 92 |
is $content->type, 'image/jpeg'; |
|---|
| 93 |
is $content->body, "\xff\xde\xde\xde"; |
|---|
| 94 |
|
|---|
| 95 |
sub un_utf8 { |
|---|
| 96 |
my $foo = shift; |
|---|
| 97 |
Encode::_utf8_off($foo); |
|---|
| 98 |
$foo; |
|---|
| 99 |
} |
|---|