redirect.t: Add test for ted external URL
[libquvi-scripts.git] / tests / t / redirect.t
blob11ec717ef5f74eaadcd000334466b2a34dd5481b
1 # libquvi-scripts
2 # Copyright (C) 2011  Toni Gundogdu <legatvs@gmail.com>
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 # 02110-1301, USA.
19 use warnings;
20 use strict;
22 use Test::More;
24 eval "use JSON::XS";
25 plan skip_all => "JSON::XS required for testing" if $@;
27 eval "use Test::Deep";
28 plan skip_all => "Test::Deep required for testing" if $@;
30 use Test::Quvi;
32 my $q = Test::Quvi->new;
34 plan skip_all => "TEST_SKIP rule"
35   if $q->test_skip("redirect");
37 plan tests => 8;
39 my $j = $q->get_json_obj;
41 test_redirect_url(    # Test self.redirect_url in academicearth.lua
42        "http://www.academicearth.org/lectures/intro-roman-architecture",
43        "data/resolve/redirect_url_academicearth.json"
44                  );
46 test_redirect_url(    # Test self.redirect_url in collegehumor.lua
47   "http://www.dorkly.com/embed/17349/ridiculous-way-to-get-ammo-to-teammates-in-battlefield-bad-company-2",
48   "data/resolve/redirect_url_dorkly.json"
49                  );
51 test_redirect_url(    # Test self.redirect_url in ted.lua
52       "http://www.ted.com/talks/paul_lewis_crowdsourcing_the_news.html",
53       "data/resolve/redirect_url_ted.json"
54                  );
56 test_url_shortener(    # Test URL shortener support
57         "http://is.gd/EbVFoa",             # -> http://vimeo.com/1485507
58         "data/format/default/vimeo.json"
59                   );
61 sub test_redirect_url
63   my ($url, $json) = @_;
64   my ($r, $o) = $q->run($url, "-q");
65   is($r, 0, "quvi exit status == 0") or diag $url;
66 SKIP:
67   {
68     skip 'quvi exit status != 0', 1 if $r != 0;
69     my $e = $q->read_json($json, 1)
70       ;    # 1=prepend --data-root (if specified in cmdline)
71     cmp_deeply($j->decode($o), $e, "compare with $json")
72       or diag $url;
73   }
76 sub test_url_shortener
78   my ($url, $json) = @_;
79   my ($r, $o) = $q->run($url, "-q");
80   is($r, 0, "quvi exit status == 0") or diag $url;
81 SKIP:
82   {
83     skip 'quvi exit status != 0', 1 if $r != 0;
84     my $e = $q->read_json($json, 1)
85       ;    # 1=prepend --data-root (if specified in cmdline)
86     cmp_deeply($j->decode($o), $e, "compare with $json")
87       or diag $url;
88   }
91 # vim: set ts=2 sw=2 tw=72 expandtab: