Created
December 29, 2011 18:08
-
-
Save marcusramberg/1535331 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package TestPayFlow; | |
use lib 't/lib'; | |
use TestCase -db; | |
sub pay_page : Tests(setup => no_plan) { | |
my $self = shift; | |
my $event_id = $self->dummy_event; | |
$self->visit('event', id => $event_id); | |
$self->click_link('buy'); | |
} | |
sub pay_with_email : Tests { | |
my $self = shift; | |
$self->fill_in(email => '[email protected]'); | |
$self->click_button('auth-with-email'); | |
$self->select(total_tickets => 3); | |
$self->click_button('pay'); | |
$self->payex_ok; | |
is $self->find('.ticket')->size, 3; | |
} | |
sub fail_with_email : Tests { | |
my $self = shift; | |
$self->fill_in(email => '[email protected]'); | |
$self->click_button('auth-with-email'); | |
$self->select(total_tickets => 3); | |
$self->click_button('pay'); | |
$self->payex_fail; | |
is $self->find('.ticket')->size, 0; | |
} | |
# This is a bit brittle, but it makes it possible to test the whole flow. | |
sub payex { | |
my $self = shift; | |
my $prefix = '#ctl00_BodyContentPlaceHolder_PaymentControl_'; | |
like $self->current_page->host, qr/payex\.com/; | |
$self->at($prefix.'ddCardType')->select('VISA'); | |
$self->at($prefix.'txtCardNumber')->fill('4925000000000004'); | |
$self->at($prefix.'txtCardHolderName')->fill('Ola Nordman'); | |
$self->at($prefix.'ddExpireMonth')->select(12); | |
$self->at($prefix.'ddExpireYear')->select(12); | |
$self->at($prefix.'txtCVCCode')->fill(123); | |
$self->at($prefix.'btnPay')->click; | |
} | |
sub payex_ok { | |
my $self = shift; | |
$self->payex; | |
$self->carry_on; | |
$self->at('#OkContinue')->click; | |
$self->carry_on; | |
is $self->current_page->host, 'localhost'; | |
} | |
sub payex_fail { | |
my $self = shift; | |
$self->payex; | |
$self->carry_on; | |
$self->select(ddStatus => 'FAILED'); | |
$self->at('#form1')->submit; | |
$self->at('#OkContinue')->click; | |
$self->carry_on; | |
is $self->current_page->host, 'localhost'; | |
} | |
# Submit JavaScript auto-POST form | |
sub carry_on { | |
if (my $form = shift->at('form[name=sendRequest]')) { | |
$form->submit; | |
} | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment