Debian Codegraph @

ebay/t/category.t

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1
2 use warnings;
3 use strict;
4
5 my $VERSION = 1.05;
6
7 use blib;
8 use Bit::Vector;
9 use Data::Dumper;
10 use Test::More 'no_plan';
11
12 use WWW::Search::Test;
13 BEGIN
14 {
15 use_ok('WWW::Search::Ebay::Category');
16 } # end of BEGIN block
17
18 my $iDebug;
19 my $iDump = 0;
20
21 tm_new_engine('Ebay::Category');
22 $WWW::Search::Test::sSaveOnError = q{category-failed.html};
23 # goto MULTI_RESULT;
24 # goto DEBUG_NOW;
25 # goto CONTENTS;
26
27 diag("Sending 0-page category query...");
28 $iDebug = 0;
29 # This test returns no results (but we should not get any errors):
30 WWW::Search::Test::_tm_run_test('normal', $WWW::Search::Test::bogus_query, 0, 0, $iDebug, 0);
31
32 # goto SKIP_CONTENTS;
33
34 # DEBUG_NOW:
35 pass;
36 goto SKIP_MULTI_RESULT;
37 MULTI_RESULT:
38 {
39 $TODO = 'WWW::Search::Ebay can not fetch multiple pages';
40 diag("Sending multi-page category query...");
41 $iDebug = 0;
42 $iDump = 0;
43 # This query returns dozens of pages of results:
44 tm_run_test('normal', '1380', 222, undef, $iDebug);
45 cmp_ok(1, '<', $WWW::Search::Test::oSearch->{requests_made}, 'got multiple pages');
46 $TODO = '';
47 } # end of MULTI_RESULT block
48 SKIP_MULTI_RESULT:
49 pass;
50 DEBUG_NOW:
51 pass;
52 CONTENTS:
53 diag("Sending 1-page category query to check contents...");
54 $iDebug = 0;
55 $iDump = 0;
56 # 175817 is "Credit Services"
57 tm_run_test('normal', 175817, 1, 199, $iDebug, $iDump);
58 # Now get the results and inspect them:
59 my @ao = $WWW::Search::Test::oSearch->results();
60 cmp_ok(0, '<', scalar(@ao), 'got some results');
61 # We perform this many tests on each result object:
62 my $iTests = 5;
63 my $iAnyFailed = 0;
64 my ($iVall, %hash);
65 my $oV = new Bit::Vector($iTests);
66 $oV->Fill;
67 $iVall = $oV->to_Dec;
68 foreach my $oResult (@ao)
69 {
70 $oV->Bit_Off(0) unless like($oResult->url, qr{\Ahttps?://[^.]+\.ebay\.com},
71 'result URL is really from ebay.com');
72 $oV->Bit_Off(1) unless cmp_ok($oResult->title, 'ne', '',
73 'result Title is not empty');
74 $oV->Bit_Off(3) unless like($oResult->description, qr{(\d+|no)\sbids?;},
75 'result bid count is ok');
76 $oV->Bit_Off(4) unless like($oResult->description, qr{(starting|current)\sbid\s},
77 'result bid amount is ok');
78 my $iV = $oV->to_Dec;
79 if ($iV < $iVall)
80 {
81 $hash{$iV} = $oResult;
82 $iAnyFailed++;
83 } # if
84 } # foreach
85 if ($iAnyFailed)
86 {
87 diag(" Here are results that exemplify the failures:");
88 while (my ($sKey, $sVal) = each %hash)
89 {
90 diag(Dumper($sVal));
91 } # while
92 } # if
93 SKIP_CONTENTS:
94 pass;
95
96 __END__
97