aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/uri_for.t
blob: 2362e6976e279431b795ddb09ead04d334825023 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use strict;
use warnings;

use Test::More;

# FIXME Should this be here? A better way? uri_for varies by map.
use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App';
FixMyStreet::Map::set_map_class();

# structure of these tests borrowed from '/t/aggregate/unit_core_uri_for.t'

use strict;
use warnings;
use URI;

use_ok('FixMyStreet::App');

my $fms_c = FixMyStreet::App->new(
    {
        request => Catalyst::Request->new(
            {
                base => URI->new('http://www.fixmystreet.com/'),
                uri  => URI->new('http://www.fixmystreet.com/test_namespace')
            }
        ),
        namespace => 'test_namespace',
    }
);

my $fgm_c = FixMyStreet::App->new(
    {
        request => Catalyst::Request->new(
            {
                base => URI->new('http://www.fiksgatami.no/'),
                uri  => URI->new('http://www.fiksgatami.no/test_namespace')
            }
        ),
        namespace => 'test_namespace',
    }
);

my $reh_en_c = FixMyStreet::App->new(
    {
        request => Catalyst::Request->new(
            {
                base => URI->new('http://reportemptyhomes.com/'),
                uri  => URI->new('http://reportemptyhomes.com/test_namespace')
            }
        ),
        namespace => 'test_namespace',
    }
);
$reh_en_c->setup_request();


is(
    $fms_c->uri_for('/bar/baz') . "",
    'http://www.fixmystreet.com/bar/baz',
    'URI for absolute path'
);

is(
    $fms_c->uri_for('') . "",
    'http://www.fixmystreet.com/test_namespace',
    'URI for namespace'
);

is(
    $fms_c->uri_for( '/bar/baz', 'boing', { foo => 'bar', } ) . "",
    'http://www.fixmystreet.com/bar/baz/boing?foo=bar',
    'URI with query'
);

# fiksgatami
is(
    $fgm_c->uri_for( '/foo', { lat => 1.23, } ) . "",
    'http://www.fiksgatami.no/foo?lat=1.23&zoom=3',
    'FiksGataMi url with lat not zoom'
);

like(
    $reh_en_c->uri_for_email( '/foo' ),
    qr{^http://en.},
    'adds en to retain language'
);

# instantiate this here otherwise sets locale to cy and breaks test
# above
my $reh_cy_c = FixMyStreet::App->new(
    {
        request => Catalyst::Request->new(
            {
                base => URI->new('http://cy.reportemptyhomes.com/'),
                uri  => URI->new('http://cy.reportemptyhomes.com/test_namespace')
            }
        ),
        namespace => 'test_namespace',
    }
);
$reh_cy_c->setup_request();

like(
    $reh_cy_c->uri_for_email( '/foo' ),
    qr{^http://cy.},
    'retains language'
);

## Should really test the cities but we'd need to fake up too much of the
# request. Following code starts to do this but is not complete. Instead better
# to test that the cities produces the correct urls by looking at the html
# produced.
#
# # cities
# my $cities_c = FixMyStreet::App->new(
#     {
#         request => Catalyst::Request->new(
#             {
#                 base => URI->new('http://cities.fixmystreet.com/'),
#                 uri  => URI->new(
#                     'http://cities.fixmystreet.com/test_namespace?city=cardiff'
#                 ),
#                 params => { city => 'cardiff', },
#             }
#         ),
#         namespace => 'test_namespace',
#     }
# )->setup_request;
# is(
#     $cities_c->uri_for( '/foo', { bar => 'baz' } ) . "",
#     '{microapp-href:http://cities.fixmystreet.com/foo?bar=baz&city=cardiff}',
#     'Cities url'
# );

done_testing();