File: 04.util.t

package info (click to toggle)
libatompub-perl 0.3.7-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: perl: 2,735; makefile: 2
file content (79 lines) | stat: -rw-r--r-- 2,301 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use strict;
use warnings;
#use Data::Dumper; $Data::Dumper::Indent = 1;
use Test::More tests => 25;

use Atompub::MediaType qw(media_type);
use Atompub::Util qw(is_acceptable_media_type is_allowed_category);
use XML::Atom::Service;

# is_acceptable_media_type

my $coll = XML::Atom::Collection->new;

ok  is_acceptable_media_type($coll, media_type('entry'));
ok !is_acceptable_media_type($coll, 'image/png');

$coll->accept('application/xml');
ok  is_acceptable_media_type($coll, media_type('entry'));
ok !is_acceptable_media_type($coll, 'image/png');

$coll->accept(media_type('entry'));
ok  is_acceptable_media_type($coll, media_type('entry'));
ok !is_acceptable_media_type($coll, 'image/png');

$coll->accept('image/png');
ok !is_acceptable_media_type($coll, media_type('entry'));
ok  is_acceptable_media_type($coll, 'image/png');

$coll->accept('image/*');
ok !is_acceptable_media_type($coll, media_type('entry'));
ok  is_acceptable_media_type($coll, 'image/png');

$coll->accept('image/png', 'image/jpeg', 'image/gif');
ok !is_acceptable_media_type($coll, media_type('entry'));
ok  is_acceptable_media_type($coll, 'image/png');

$coll->accept('image/png,image/jpeg,image/gif');
ok !is_acceptable_media_type($coll, media_type('entry'));
ok  is_acceptable_media_type($coll, 'image/png');


# is_allowed_category

my $cat1 = XML::Atom::Category->new;
$cat1->term('animal');
my $cat1_s = XML::Atom::Category->new;
$cat1_s->term('animal');
$cat1_s->scheme('http://example.com/cats/big3');
my $cat2 = XML::Atom::Category->new;
$cat2->term('vegetable');

my $cats = XML::Atom::Categories->new;
$coll->categories($cats);
ok is_allowed_category($coll, $cat1);

$cats->fixed('yes');
ok !is_allowed_category($coll, $cat1);

$cats->category($cat1);
ok  is_allowed_category($coll, $cat1);
ok  is_allowed_category($coll, $cat1_s);
ok !is_allowed_category($coll, $cat1, $cat2);

$cats->category($cat1_s);
ok !is_allowed_category($coll, $cat1);
ok  is_allowed_category($coll, $cat1_s);

$cats->category($cat1, $cat2);
ok is_allowed_category($coll, $cat1, $cat2);

$cats->category($cat1);
$cats->scheme('http://example.com/cats/big3');
ok !is_allowed_category($coll, $cat1);
ok  is_allowed_category($coll, $cat1_s);


$coll = XML::Atom::Collection->new; # no app:categories

ok is_allowed_category($coll, $cat1);