Debian Codegraph @

ebay/t/category.t

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