Debian Codegraph @

ebay/t/ebay.t

raw ◀ ▶
1 Debian patch touch this file
1
2 my $VERSION = 1.22;
3
4 use strict;
5 use warnings;
6
7 use constant DEBUG_CONTENTS => 0;
8
9 use Bit::Vector;
10 use Data::Dumper;
11 use Date::Manip;
12 use ExtUtils::testlib;
13 use Test::More;
14 use WWW::Search;
15 use WWW::Search::Test;
16
•17 use blib;
18 use WWW::Search::Ebay;
19
20 BEGIN {
21 unless ($ENV{NO_NETWORK}) {
22 no_plan();
23 }
24 else {
25 plan skip_all => "no network";
26 }
27 }
28
29 my $iDebug;
30 my $iDump = 0;
31
32 tm_new_engine('Ebay');
33 # goto ISBN;
34 # goto DEBUG_NOW;
35 goto CONTENTS if DEBUG_CONTENTS;
36 # goto SPELL_TEST;
37
38 diag("Sending 0-page ebay queries...");
39 $iDebug = 0;
40 # This test returns no results (but we should not get an HTTP error):
41 tm_run_test('normal', $WWW::Search::Test::bogus_query, 0, 0, $iDebug);
42 SPELL_TEST:
43 pass('no-op');
44 # There are no hits for "laavar", make sure Ebay.pm does not return
45 # the "lavar" hits:
46 $iDebug = 0;
47 # tm_run_test('normal', 'laavar', 0, 0, $iDebug, 'dump');
48 $iDebug = 0;
49 # tm_run_test('normal', 'no products match this entire phrase', 0, 0, $iDebug, 'dump');
50 # goto ALL_DONE;
51
52 DEBUG_NOW:
53 pass('no-op');
54 MULTI_RESULT:
55 {
56 $TODO = 'WWW::Search::Ebay can not fetch multiple pages';
57 diag("Sending multi-page ebay query...");
58 $iDebug = 0;
59 $iDump = 0;
60 # This query returns hundreds of pages of results:
61 tm_run_test('normal', 'LEGO', 101, undef, $iDebug);
62 cmp_ok(1, '<', $WWW::Search::Test::oSearch->{requests_made}, 'got multiple pages');
63 $TODO = '';
64 } # end of MULTI_PAGE block
65 # goto SKIP_CONTENTS; # for debugging
66
67 if (0)
68 {
69 # The intention of this test block is to retrieve a page that
70 # returns hits on the exact query term, AND hits on alternate
71 # spellings. It's just too hard to find such a word that
72 # consistently performs as needed.
73 $TODO = "Sometimes there are NO hits for lavarr";
74 diag("Sending 1-page ebay queries...");
75 # There are a few hits for "lavarr", and eBay also gives us all the
76 # "lavar" hits:
77 $iDebug = 0;
78 tm_run_test('normal', 'lavarr', 1, 99, $iDebug);
79 $TODO = '';
80 } # if
81
82 UPC:
83 {
84 $TODO = 'too hard to find a consistent EAN';
85 diag("Sending 1-page ebay query for 12-digit UPC...");
86 $iDebug = 0;
87 $iDump = 0;
88 tm_run_test('normal', '0-77778-60672-7' , 1, 99, $iDebug, $iDump);
89 $TODO = '';
90 } # end of UPC block
91 EAN:
92 {
93 $TODO = 'too hard to find a consistent EAN';
94 diag("Sending 1-page ebay query for 13-digit EAN...");
95 $iDebug = 0;
96 $iDump = 0;
97 tm_run_test('normal', '00-77778-60672-7' , 1, 99, $iDebug, $iDump);
98 $TODO = '';
99 } # end of EAN block
100 ISBN:
101 {
102 $TODO = q{I don't know why, but this test has more false negatives than almost any other};
103 diag("Sending 1-page ebay query for 10-digit ISBN...");
104 $iDebug = 0;
105 $iDump = 0;
106 tm_run_test('normal', '0-553-09606-0' , 1, 99, $iDebug, $iDump);
107 $TODO = q{};
108 } # end of ISBN block
109 # goto SKIP_CONTENTS;
110
111 CONTENTS:
112 diag("Sending 1-page ebay query to check contents...");
113 $iDebug = DEBUG_CONTENTS ? 2 : 0;
114 $iDump = 0;
115 $WWW::Search::Test::sSaveOnError = q{ebay-1-failed.html}; # }; # Emacs bug
116 my $sQuery = 'trinidad tobago flag';
117 # $sQuery = 'church spread wings'; # Special debugging
118 tm_run_test('normal', $sQuery, 1, 99, $iDebug, $iDump);
119 # Now get the results and inspect them:
120 my @ao = $WWW::Search::Test::oSearch->results();
121 cmp_ok(0, '<', scalar(@ao), 'got some results');
122 my $sBidPattern = 'bid\s+'. $WWW::Search::Test::oSearch->_currency_pattern .'\s?[,.0-9]+';
123 my $qrBid = qr{\b$sBidPattern};
124 my @ara = (
125 ['description', 'like', $qrBid, 'description contains bid amount'],
126 ['description', 'like', qr{Item #\d+;}, 'description contains item #'],
127 ['url', 'like', qr(\Ahttps?://(cgi|www)\d*\.ebay\.com)i, # ), # Emacs bug
128 q'URL is from ebay.com'], # '], # Emacs bug
129 ['title', 'ne', 'q{}', 'result Title is not empty'],
130 ['change_date', 'date', 'change_date is really a date'],
131 ['description', 'like', qr{\b(\d+|no)\s+bids?}, # }, # Emacs bug
132 'result bidcount is ok'],
133 ['bid_count', 'like', qr{\A\d+\Z}, 'bid_count is a number'],
134 # ['shipping', 'like', qr{\A(free|[0-9\$\.]+)\Z}i, 'shipping looks like a money value'],
135 ['category', 'like', qr{\A-?\d+\Z}, 'category is a number'],
136 );
137 WWW::Search::Test::test_most_results(\@ara, 1.00);
138 # Sanity check for new category list parsing:
139 # print STDERR Dumper($WWW::Search::Test::oSearch->{categories});
140
141 SKIP_CONTENTS:
142 pass('no-op');
143 ALL_DONE:
144 pass('all done');
145
146 done_testing();
147
148 __END__
149