Debian Codegraph @

ebay/t/ebay.t

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