| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
use Test::More; |
| 5 |
use Finance::Quote; |
| 6 |
|
| 7 |
if (not $ENV{'ONLINE_TEST'}) { |
| 8 |
plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; |
| 9 |
} |
| 10 |
|
| 11 |
my $q = Finance::Quote->new('OnVista'); |
| 12 |
my @valid = qw/MRK AAPL SAP FR0010510800 A3GQ2N/; |
| 13 |
my @invalid = qw/BOGUS/; |
| 14 |
my @symbols = (@valid, @invalid); |
| 15 |
my @labels = qw/symbol isin wkn name open close high low last date currency exchange method p_change/; |
| 16 |
my $year = (localtime())[5] + 1900; |
| 17 |
my $lastyear = $year - 1; |
| 18 |
|
| 19 |
plan tests => 1 + (3 + @labels) * @valid + @invalid; |
| 20 |
|
| 21 |
my %quotes = $q->onvista(@symbols); |
| 22 |
ok(%quotes); |
| 23 |
|
| 24 |
foreach my $symbol (@valid) { |
| 25 |
ok($quotes{$symbol, 'success'}, "$symbol success"); |
| 26 |
for my $label (@labels) { |
| 27 |
ok(defined $quotes{$symbol, $label}, "$symbol returned $label as $quotes{$symbol, $label}"); |
| 28 |
} |
| 29 |
ok((substr($quotes{$symbol, 'isodate'}, 0, 4) == $year or |
| 30 |
substr($quotes{$symbol, 'isodate'}, 0, 4) == $lastyear), "$symbol returned isodate as $quotes{$symbol, 'isodate'}"); |
| 31 |
ok($quotes{$symbol, 'time'} =~ /^[0-2]?[0-9]:[0-5][0-9]/, "$symbol returned time as $quotes{$symbol, 'time'}"); |
| 32 |
} |
| 33 |
|
| 34 |
foreach my $symbol (@invalid) { |
| 35 |
ok((not $quotes{'BOGUS', 'success'}), 'failed as expected'); |
| 36 |
} |