Created
April 3, 2012 18:43
-
-
Save amiri/2294573 to your computer and use it in GitHub Desktop.
How I use setup/teardown for these
This file contains 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 CE::Selenium::FacebookRegistration; | |
use CE::Config; | |
use Test::Class::Most parent => 'CE::Test::Class::WWWSelDriver'; | |
sub class {'CE'} | |
sub new_obj { | |
return shift; | |
} | |
=head2 design | |
logged_out_of_both_pre_approved_promotion_path | |
logged_out_of_both_pre_approved_minimal_path | |
logged_out_of_both_not_approved | |
logged_out_of_fb_logged_in_to_ce_pre_approved_promotion_path | |
logged_out_of_fb_logged_in_to_ce_pre_approved_minimal_path | |
logged_out_of_fb_logged_in_to_ce_not_approved | |
logged_out_of_ce_logged_in_to_fb_pre_approved_promotion_path | |
logged_out_of_ce_logged_in_to_fb_pre_approved_minimal_path | |
logged_out_of_ce_logged_in_to_fb_not_approved | |
logged_in_to_both_pre_approved_promotion_path | |
logged_in_to_both_pre_approved_minimal_path | |
logged_in_to_both_not_approved | |
=cut | |
=head2 startup | |
=cut | |
sub startup : Test(startup => 21) { | |
my $self = shift; | |
$self->next::method(@_); | |
$self->delete_user_data; | |
$self->deauthorize_setup; | |
} | |
=head2 setup | |
We have to prevent the txn_do here because we are starting an app | |
server for CE with a forked DB handle, and you can't share a forked | |
DB handle inside a transaction. | |
=cut | |
sub setup : Test(setup => 5) { | |
my $self = shift; | |
$self->create_promotion_data; | |
return 1; | |
} | |
=head2 teardown | |
Similar to setup, we have to avoid the rollback. | |
=cut | |
sub teardown : Test(teardown => 11) { | |
my $self = shift; | |
$self->delete_user_data_tests; | |
$self->delete_promotion_data; | |
return 1; | |
} | |
################### TESTS ################### | |
# TBD: logged_out_of_fb_logged_in_to_ce_not_approved | |
# TBD: logged_out_of_ce_logged_in_to_fb_pre_approved_promotion_path | |
# TBD: logged_out_of_ce_logged_in_to_fb_pre_approved_minimal_path | |
# TBD: logged_out_of_ce_logged_in_to_fb_not_approved | |
# TBD: logged_in_to_both_pre_approved_promotion_path | |
# TBD: logged_in_to_both_pre_approved_minimal_path | |
# TBD: logged_in_to_both_not_approved | |
# logged_out_of_both_pre_approved_minimal_path | |
sub logged_out_of_both_pre_approved_minimal_path : Test(334) { | |
my $self = shift; | |
my $sel = $self->pre_approved_minimal_path_logged_out_both_sel; | |
for my $promotion_type ( @{ $self->promotion_types } ) { | |
$sel = $self->pre_approved_logged_out_both_apply_for_promotion_type( | |
$sel, $promotion_type ); | |
$sel = $self->logout_of_ce($sel); | |
} | |
$sel = $self->deauthorize($sel); | |
$sel = $self->logout_of_fb($sel); | |
$self->delete_user_data_tests; | |
} | |
# logged_out_of_both_pre_approved_promotion_path | |
sub logged_out_of_both_pre_approved_promotion_path : Test(317) { | |
my $self = shift; | |
my $sel = $self->pre_approved_promotion_path_logged_out_both_sel; | |
for my $promotion_type ( @{ $self->promotion_types } ) { | |
$sel = $self->pre_approved_logged_out_both_apply_for_promotion_type( | |
$sel, $promotion_type ); | |
$sel = $self->logout_of_ce($sel); | |
} | |
$sel = $self->deauthorize($sel); | |
$sel = $self->logout_of_fb($sel); | |
$self->delete_user_data_tests; | |
} | |
# logged_out_of_both_not_approved_promotion_path | |
sub logged_out_of_both_not_approved_promotion_path : Test(391) { | |
my $self = shift; | |
my $sel = $self->not_approved_logged_out_both_sel; | |
for my $promotion_type ( @{ $self->promotion_types } ) { | |
$sel = $self->not_approved_logged_out_both_apply_for_promotion_type( | |
$sel, $promotion_type ); | |
$sel = $self->logout_of_ce($sel); | |
$sel = $self->deauthorize($sel); | |
$sel = $self->logout_of_fb($sel); | |
$self->delete_user_data_tests; | |
} | |
} | |
# logged_out_of_both_not_approved_minimal_path | |
sub logged_out_of_both_not_approved_minimal_path : Test(256) { | |
my $self = shift; | |
my $sel = $self->not_approved_logged_out_both_sel; | |
for my $page_type ( keys %{ $self->url_for_page_type } ) { | |
$sel = $self->login_to_page_type( $sel, $page_type, 'not_approved' ); | |
my $final_url = $sel->get_current_url; | |
my $expected = $self->url_for_page_type->{$page_type}; | |
like( $final_url, qr/$expected/, | |
"After logging in I was redirected to the original URL" ); | |
$sel = $self->logout_of_ce($sel); | |
$sel = $self->deauthorize($sel); | |
$sel = $self->logout_of_fb($sel); | |
$self->delete_user_data_tests; | |
} | |
} | |
# logged_out_of_fb_logged_in_to_ce_pre_approved_promotion_path | |
sub logged_out_of_fb_logged_in_to_ce_pre_approved_promotion_path : Test(155) { | |
my $self = shift; | |
my $sel = $self->pre_approved_promotion_path_logged_out_fb_sel; | |
$sel = $self->logout_of_fb($sel); | |
my $logout = $self->wait_for_load( $sel, "logout", "id" ); | |
ok( $logout, "I am still logged into CE after logging out of FB" ); | |
for my $promotion_type ( @{ $self->promotion_types } ) { | |
$sel = $self->pre_approved_logged_in_to_ce_apply_for_promotion_type( | |
$sel, $promotion_type ); | |
$self->delete_promotion_entries; | |
} | |
$sel = $self->deauthorize($sel); | |
$sel = $self->logout_of_fb($sel); | |
$self->delete_user_data_tests; | |
} | |
# logged_out_of_fb_logged_in_to_ce_pre_approved_minimal_path | |
sub logged_out_of_fb_logged_in_to_ce_pre_approved_minimal_path : Test(157) { | |
my $self = shift; | |
my $sel = $self->pre_approved_minimal_path_logged_out_of_fb_into_ce_sel; | |
for my $promotion_type ( @{ $self->promotion_types } ) { | |
$sel = $self->pre_approved_logged_in_to_ce_apply_for_promotion_type( | |
$sel, $promotion_type ); | |
} | |
$sel = $self->deauthorize($sel); | |
$sel = $self->logout_of_fb($sel); | |
$self->delete_user_data_tests; | |
} | |
################### STATES ################### | |
sub not_approved_logged_out_both_sel { | |
my $self = shift; | |
my $sel = $self->selenium; | |
lives_ok { $sel->get( $self->base ) } "I can get my base url"; | |
return $sel; | |
} | |
sub pre_approved_promotion_path_sel { | |
my $self = shift; | |
my $sel = $self->selenium; | |
$sel = $self->register( $sel, 'promotion' ); | |
return $sel; | |
} | |
sub pre_approved_minimal_path_sel { | |
my $self = shift; | |
my $sel = $self->selenium; | |
$sel->get( $self->base ); | |
$sel = $self->register( $sel, 'register' ); | |
return $sel; | |
} | |
sub pre_approved_minimal_path_logged_out_of_fb_into_ce_sel { | |
my $self = shift; | |
my $sel = $self->selenium; | |
$sel = $self->pre_approved_minimal_path_sel($sel); | |
$sel = $self->logout_of_fb($sel); | |
return $sel; | |
} | |
sub pre_approved_minimal_path_logged_out_both_sel { | |
my $self = shift; | |
my $sel = $self->selenium; | |
$sel = $self->pre_approved_minimal_path_sel($sel); | |
$sel = $self->logout_of_fb($sel); | |
$sel = $self->logout_of_ce($sel); | |
return $sel; | |
} | |
sub pre_approved_promotion_path_logged_out_both_sel { | |
my $self = shift; | |
my $sel = $self->selenium; | |
$sel = $self->pre_approved_promotion_path_sel($sel); | |
$sel = $self->logout_of_ce($sel); | |
return $sel; | |
} | |
sub pre_approved_promotion_path_logged_out_fb_sel { | |
my $self = shift; | |
my $sel = $self->selenium; | |
lives_ok { $sel->get( $self->base ) } "I can get my base url"; | |
$sel = $self->not_approved_logged_out_both_apply_for_promotion_type( $sel, | |
'create_account' ); | |
return $sel; | |
} | |
sub pre_approved_logged_in_to_fb_sel { | |
my $self = shift; | |
my $sel = $self->selenium; | |
$sel = $self->register($sel); | |
$sel = $self->logout_of_ce($sel); | |
return $sel; | |
} | |
sub pre_approved_logged_in_to_ce_sel { | |
my $self = shift; | |
my $sel = $self->selenium; | |
$sel = $self->register($sel); | |
$sel = $self->logout_of_ce($sel); | |
return $sel; | |
} | |
################### SHARED LOGIC ################### | |
sub login_to_page_type { | |
my ( $self, $sel, $page_type, $status ) = @_; | |
my $reg_type; | |
if ( $status eq 'not_approved' ) { | |
$reg_type = 'register'; | |
} else { | |
$reg_type = 'register'; | |
} | |
my $url = $self->url_for_page_type->{$page_type}; | |
$sel->get( $self->url_for_page_type->{$page_type} ); | |
$sel = $self->register( $sel, $reg_type ); | |
return $sel; | |
} | |
sub not_approved_sign_in_to_fb { | |
my ( $self, $sel, $page_type ) = @_; | |
$sel = $self->facebook_button_and_window_signin( $sel, $page_type ); | |
return $sel; | |
} | |
sub pre_approved_sign_in_to_fb { | |
my ( $self, $sel, $page_type ) = @_; | |
$sel = $self->facebook_button_and_window_signin( $sel, $page_type ); | |
return $sel; | |
} | |
sub logout_of_ce { | |
my ( $self, $sel ) = @_; | |
my $logout = $self->wait_for_load( $sel, "logout", "id" ); | |
lives_ok { $logout->click } "I can click Sign Out"; | |
my $login_link = $self->wait_for_load( $sel, "Sign In", "link_text" ); | |
ok( defined($login_link), "I am now logged out of CE" ); | |
$sel->get( $self->base ); | |
my $login_link2 = $self->wait_for_load( $sel, "Sign In", "link_text" ); | |
ok( defined($login_link2), | |
"After a new request I am still logged out of CE" ); | |
lives_ok { $sel->get('https://www.facebook.com') } "I can go to Facebook"; | |
my $fb_login; | |
lives_ok { $fb_login = $self->wait_for_load( $sel, "login_form", "id" ) } | |
"I am logged out of FB after logging out of CE"; | |
return $sel; | |
} | |
sub logout_of_fb { | |
my ( $self, $sel ) = @_; | |
lives_ok { $sel->get('https://www.facebook.com') } "I can go to Facebook"; | |
my $logout; | |
lives_ok { $logout = $self->wait_for_load( $sel, "logout_form", "id" ) } | |
"I can find my Facebook logout form"; | |
lives_ok { $logout->submit } "I can submit that logout form"; | |
lives_ok { $sel->get( $self->base ) } "I can go to my site"; | |
return $sel; | |
} | |
sub login_to_fb { | |
my ( $self, $sel ) = @_; | |
$sel->get("https://www.facebook.com"); | |
my $email_field = $self->wait_for_load( $sel, "email", "id" ); | |
my $password_field = $self->wait_for_load( $sel, "pass", "id" ); | |
my $submit = $self->wait_for_load( $sel, "loginbutton", "id" ); | |
lives_ok { $email_field->clear } "I can clear the email field"; | |
lives_ok { $email_field->send_keys("c.e._vuojrqh_testuser\@tfbnw.net") } | |
"I can type into the email field"; | |
lives_ok { $password_field->clear } "I can clear the password field"; | |
lives_ok { $password_field->send_keys("601241726") } | |
"I can type into my password field"; | |
lives_ok { $submit->click } "I can submit it"; | |
return $sel; | |
} | |
sub login_to_ce { | |
my ( $self, $sel ) = @_; | |
$sel->get( $self->base ); | |
$sel = $self->click_sign_in($sel); | |
my $email_field = $self->wait_for_load( $sel, "emailaddr", "name" ); | |
my $password_field = $self->wait_for_load( $sel, "password", "name" ); | |
my $submit = $self->wait_for_load( $sel, | |
"//form[\@id='signin_signup']/p[5]/button", "xpath" ); | |
lives_ok { $email_field->clear } "I can clear the email field"; | |
lives_ok { $email_field->send_keys("c.e._vuojrqh_testuser\@tfbnw.net") } | |
"I can type into the email field"; | |
lives_ok { $password_field->clear } "I can clear the password field"; | |
lives_ok { $password_field->send_keys("601241726") } | |
"I can type into my password field"; | |
lives_ok { $submit->click } "I can submit the form"; | |
my $logout = $self->wait_for_load( $sel, "logout", "id" ); | |
ok( $logout, "I am logged in now" ); | |
return $sel; | |
} | |
sub not_approved_logged_out_both_apply_for_promotion_type { | |
my ( $self, $sel, $promotion_type ) = @_; | |
my $promotion = $self->schema->resultset('Promotion') | |
->find( { promotion_cd => $promotion_type } ); | |
my $promotion_url | |
= $self->base | |
. "panel/apply/?backref=%2Fpanel%2Fqualify%2F&promotion_id=" | |
. $promotion->promotion_id; | |
lives_ok { $sel->get($promotion_url) } | |
"I can get my promotion URL, $promotion_url"; | |
$sel | |
= $self->not_approved_sign_in_to_fb( $sel, 'promotion_not_approved' ); | |
$sel = $self->check_success_elements( $sel, $promotion_type ); | |
return $sel; | |
} | |
sub check_success_elements { | |
my ( $self, $sel, $promotion_type ) = @_; | |
if ( $promotion_type eq 'review' ) { | |
my $logout = $self->wait_for_load( $sel, "logout", "id" ); | |
my $not_you = $self->wait_for_load( $sel, "(Not you?)", "link_text" ); | |
my $official_rules | |
= $self->wait_for_load( $sel, "official-rules", "id" ); | |
my $instructions | |
= $self->wait_for_load( $sel, "instructions", "class" ); | |
my $college_keyword | |
= $self->wait_for_load( $sel, "college_keyword", "name" ); | |
ok( defined($_), | |
"My success element " | |
. ( $_->get_attribute('id') || 'unidentified' ) | |
. " is defined" ) | |
for ( $logout, $not_you, $official_rules, $instructions, | |
$college_keyword ); | |
} else { | |
my $increase = $self->wait_for_load( $sel, "increase", "id" ); | |
my $next = $self->wait_for_load( $sel, "next", "id" ); | |
my $share_option = $self->wait_for_load( $sel, "share-option", "id" ); | |
my $referral_url = $self->wait_for_load( $sel, "referral-url", "id" ); | |
my $social_share | |
= $self->wait_for_load( $sel, "social-media-share-message", | |
"id" ); | |
ok( defined($_), | |
"My success element " . $_->get_attribute('id') . " is defined" ) | |
for ( $increase, $next, $share_option, $referral_url, | |
$social_share ); | |
} | |
return $sel; | |
} | |
sub pre_approved_logged_in_to_ce_apply_for_promotion_type { | |
my ( $self, $sel, $promotion_type ) = @_; | |
my $promotion = $self->schema->resultset('Promotion') | |
->find( { promotion_cd => $promotion_type } ); | |
my $promotion_url | |
= $self->base | |
. "panel/apply/?backref=%2Fpanel%2Fqualify%2F&promotion_id=" | |
. $promotion->promotion_id; | |
lives_ok { $sel->get($promotion_url) } | |
"I can get my promotion URL, $promotion_url"; | |
$sel = $self->pre_approved_sign_in_to_fb( $sel, 'logged_in_to_ce' ); | |
$sel = $self->check_success_elements( $sel, $promotion_type ); | |
return $sel; | |
} | |
sub pre_approved_logged_out_both_apply_for_promotion_type { | |
my ( $self, $sel, $promotion_type ) = @_; | |
my $promotion = $self->schema->resultset('Promotion') | |
->find( { promotion_cd => $promotion_type } ); | |
my $promotion_url | |
= $self->base | |
. "panel/apply/?backref=%2Fpanel%2Fqualify%2F&promotion_id=" | |
. $promotion->promotion_id; | |
lives_ok { $sel->get($promotion_url) } | |
"I can get my promotion URL, $promotion_url"; | |
$sel = $self->pre_approved_sign_in_to_fb( $sel, 'logged_out_of_fb' ); | |
$sel = $self->check_success_elements( $sel, $promotion_type ); | |
return $sel; | |
} | |
sub deauthorize { | |
my ( $self, $sel ) = @_; | |
$sel = $self->login_to_fb($sel); | |
$sel->get('http://www.facebook.com/settings/?tab=applications'); | |
my $edit | |
= $self->wait_for_load( $sel, 'fbsettingslistitemedit', "class" ); | |
$edit->click; | |
my $handles = $sel->get_window_handles; | |
my $remove = $self->wait_for_load( $sel, "Remove app", "link_text" ); | |
$remove->click; | |
my $confirm = $self->wait_for_load( $sel, "remove", "name" ); | |
$confirm->click; | |
return $sel; | |
} | |
sub deauthorize_setup { | |
my $self = shift; | |
my $sel = $self->selenium; | |
$sel->get("https://www.facebook.com"); | |
my $email_field = $self->wait_for_load( $sel, "email", "id" ); | |
my $password_field = $self->wait_for_load( $sel, "pass", "id" ); | |
my $submit = $self->wait_for_load( $sel, "loginbutton", "id" ); | |
lives_ok { $email_field->clear } "I can clear the email field"; | |
lives_ok { $email_field->send_keys("c.e._vuojrqh_testuser\@tfbnw.net") } | |
"I can type into the email field"; | |
lives_ok { $password_field->clear } "I can clear the password field"; | |
lives_ok { $password_field->send_keys("601241726") } | |
"I can type into my password field"; | |
lives_ok { $submit->click } "I can submit it"; | |
$sel->get('http://www.facebook.com/settings/?tab=applications'); | |
my $edit; | |
sleep(3); | |
eval { $edit = $sel->find_element( 'fbsettingslistitemedit', "class" ); }; | |
SKIP: { | |
skip "User already deauthorized app", 4 if $@; | |
$edit->click; | |
my $handles = $sel->get_window_handles; | |
my $remove = $self->wait_for_load( $sel, "Remove app", "link_text" ); | |
$remove->click; | |
my $confirm = $self->wait_for_load( $sel, "remove", "name" ); | |
$confirm->click; | |
} | |
lives_ok { $sel->get('https://www.facebook.com') } "I can go to Facebook"; | |
my $logout; | |
lives_ok { $logout = $self->wait_for_load( $sel, "logout_form", "id" ) } | |
"I can find my Facebook logout form"; | |
lives_ok { $logout->submit } "I can submit that logout form"; | |
} | |
sub register { | |
my ( $self, $sel, $reg_type ) = @_; | |
my ( $user, $new_user, $el, $el_type ); | |
if ( $reg_type eq 'register' || 'promotion_not_approved' ) { | |
$el = "Sign In"; | |
$el_type = "link_text"; | |
} elsif ( $reg_type eq 'promotion' ) { | |
( $el, $el_type ) = qw/fb_button_medium class/; | |
} else { | |
( $el, $el_type ) = qw/fb_button_medium class/; | |
} | |
lives_ok { | |
$user = $self->schema->resultset('User') | |
->find( { email_address => '[email protected]' } ); | |
} | |
"I can search for my newly created FB user"; | |
ok( !( defined($user) ), "But that user is not defined yet" ); | |
if ( $reg_type eq 'promotion' ) { | |
$sel->get( $self->start_url_for_page_type->{$reg_type} ); | |
my @apply_now = $sel->find_elements("//p[\@class=\"apply\"]/*"); | |
lives_ok { $apply_now[0]->click } | |
"I can click on the apply button for a promotion"; | |
} else { | |
my $signin = $self->wait_for_load( $sel, $el, $el_type ); | |
lives_ok { $signin->click } "I can click my signin button"; | |
} | |
$sel = $self->facebook_button_and_window_signin( $sel, $reg_type ); | |
lives_ok { | |
$new_user = $self->schema->resultset('User') | |
->find( { email_address => '[email protected]' } ); | |
} | |
"I can find my newly created FB user"; | |
ok( defined($new_user), "My user is defined" ); | |
ok( defined( $new_user->facebook_uid ), | |
"My new user has a facebook_uid" ); | |
is( $new_user->facebook_uid, "100003488602234", | |
"And it is the FB UID I expect" ); | |
ok( defined( $new_user->userdata->first_name ), | |
"My new user has a first_name" ); | |
is( $new_user->first_name, "C.E.", "And it is the first name I expect" ); | |
ok( defined( $new_user->userdata->last_name ), | |
"My new user has a last_name" ); | |
is( $new_user->last_name, "Testuser", | |
"And it is the last name I expect" ); | |
ok( defined( $new_user->userdata->city_nm ), | |
"My new user has a city_nm" ); | |
is( $new_user->city_nm, "Hoboken", "And it is the city_nm I expect" ); | |
ok( defined( $new_user->userdata->state_cd ), | |
"My new user has a state_cd" ); | |
is( $new_user->state_cd, "NJ", "And it is the state_cd I expect" ); | |
ok( defined( $new_user->userdata->birthdate_time ), | |
"My new user has a birthday" ); | |
is( $new_user->birthdate_time, | |
"1974-10-30 00:00:00", | |
"And it is the birthdate_time I expect" | |
); | |
ok( defined( $new_user->userdata->gender ), "My new user has a gender" ); | |
is( $new_user->gender, "M", "And it is the gender I expect" ); | |
my $handles; | |
lives_ok { $handles = $sel->get_window_handles } | |
"I can get my window handles"; | |
$sel->switch_to_window( $handles->[0] ); | |
return $sel; | |
} | |
sub wait_for_load { | |
my ( $self, $sel, $el, $type ) = @_; | |
my $element; | |
WAIT: { | |
for ( 1 .. 10 ) { | |
if ( eval { $element = $sel->find_element( $el, $type ); } ) { | |
pass; | |
last WAIT; | |
} | |
sleep(1); | |
} | |
fail("timeout"); | |
} | |
ok( defined($element), "The element '$el' of type '$type' loaded" ); | |
return $element; | |
} | |
sub click_sign_in { | |
my ( $self, $sel ) = @_; | |
my $login_link = $self->wait_for_load( $sel, "Sign In", "link_text" ); | |
lives_ok { $login_link->click } "I can click my Sign In link"; | |
return $sel; | |
} | |
sub facebook_button_and_window_signin { | |
my ( $self, $sel, $page_type ) = @_; | |
my ( $el, $el_type ); | |
if ( $page_type eq 'register' ) { | |
( $el, $el_type ) = qw/fb_button_medium class/; | |
} elsif ( $page_type eq 'promotion' ) { | |
( $el, $el_type ) = qw/fb_button_medium class/; | |
} elsif ( $page_type eq 'promotion_not_approved' ) { | |
( $el, $el_type ) = qw/fb_button_medium class/; | |
} elsif ( $page_type eq 'logged_out_of_fb' ) { | |
( $el, $el_type ) = qw/fb_button_medium class/; | |
} elsif ( $page_type eq 'logged_in_to_ce' ) { | |
( $el, $el_type ) = qw/fb_button_medium class/; | |
} elsif ( $page_type eq 'logged_in_to_fb' ) { | |
$el = "//img[\@alt='F']"; | |
$el_type = "xpath"; | |
} else { | |
( $el, $el_type ) = qw/fb_button_medium class/; | |
} | |
if ( $page_type eq 'register' | |
|| $page_type eq 'promotion' | |
|| $page_type eq 'promotion_not_approved' | |
|| $page_type eq 'logged_out_of_fb' ) | |
{ | |
my $fb_button = $self->wait_for_load( $sel, $el, $el_type ); | |
lives_ok { $fb_button->click } "I can click that button"; | |
my $handles; | |
lives_ok { $handles = $sel->get_window_handles } | |
"I can get my window handles"; | |
lives_ok { $sel->switch_to_window( $handles->[1] ) } | |
"I can switch to the second window"; | |
my $email_field = $self->wait_for_load( $sel, "email", "id" ); | |
my $password_field = $self->wait_for_load( $sel, "pass", "id" ); | |
my $submit = $self->wait_for_load( $sel, "login", "name" ); | |
lives_ok { $email_field->clear } "I can clear the email field"; | |
lives_ok { | |
$email_field->send_keys("c.e._vuojrqh_testuser\@tfbnw.net"); | |
} | |
"I can type into the email field"; | |
lives_ok { $password_field->clear } "I can clear the password field"; | |
lives_ok { $password_field->send_keys("601241726") } | |
"I can type into my password field"; | |
lives_ok { $submit->submit } "I can submit it"; | |
lives_ok { $handles = $sel->get_window_handles } | |
"I can get my window handles"; | |
if ( $handles->[1] ) { | |
$sel->switch_to_window( $handles->[1] ); | |
my $captcha = $sel->find_element( "//h2[\@id='standard_error']", | |
"xpath" ); | |
if ( defined($captcha) ) { | |
CE::Test::Class::Selenium::RemoteWebDriver->_shutdown_selenium; | |
$self->SKIP_ALL( | |
"Facebook threw our test user a captcha! They are not supposed to..." | |
); | |
} else { | |
$sel->close; | |
} | |
} | |
lives_ok { $sel->switch_to_window( $handles->[0] ) } | |
"I can now switch back to my first window"; | |
} | |
if ( $page_type eq "register" ) { | |
return $self->register_step2($sel); | |
} elsif ( $page_type eq 'promotion' ) { | |
return $self->register_step2($sel); | |
} elsif ( $page_type eq 'promotion_not_approved' ) { | |
return $self->register_step2($sel); | |
} else { | |
return $sel; | |
} | |
} | |
sub register_step2 { | |
my ( $self, $sel ) = @_; | |
my $ok = $self->wait_for_load( $sel, "grant_clicked", "id" ); | |
lives_ok { $ok->click } "I can grant permissions in registration step2"; | |
my $handles; | |
lives_ok { $handles = $sel->get_window_handles } | |
"I can get my window handles"; | |
lives_ok { $sel->switch_to_window( $handles->[0] ) } | |
"I can now switch back to my first window"; | |
return $sel; | |
} | |
sub create_promotion_data { | |
my $self = shift; | |
for my $promotion_type ( @{ $self->promotion_types } ) { | |
lives_ok { | |
my $promotion | |
= $self->schema->resultset('Promotion') | |
->find_or_create( | |
$self->promotion_data_for->{$promotion_type} ); | |
} | |
"I can find or create a promotion for the promotion type $promotion_type"; | |
} | |
} | |
sub delete_promotion_data { | |
my $self = shift; | |
for my $promotion_cd ( @{ $self->promotion_types } ) { | |
lives_ok { | |
$self->schema->storage->dbh_do( | |
sub { | |
my ( $storage, $dbh, $email ) = @_; | |
$dbh->do( | |
"delete from tblpromotion where promotion_cd = '$promotion_cd';" | |
); | |
}, | |
$promotion_cd | |
); | |
} | |
"I can delete my promotion"; | |
} | |
} | |
sub delete_promotion_entries { | |
my $self = shift; | |
my $user = $self->schema->resultset('User') | |
->find( { email_address => '[email protected]' } ); | |
if ($user) { | |
$user->promotion_entries->delete_all; | |
} | |
} | |
sub delete_user_data { | |
my $self = shift; | |
my ( $user, $emails ); | |
$user = $self->schema->resultset('User') | |
->find( { email_address => '[email protected]' } ); | |
if ($user) { | |
$emails = $self->schema->resultset('Email') | |
->search( { user_id => $user->user_id } ); | |
if ($emails) { | |
$self->schema->storage->dbh_do( | |
sub { | |
my ( $storage, $dbh, $id ) = @_; | |
$dbh->do("delete from tblemail where user_id = $id"); | |
}, | |
$user->user_id | |
); | |
} | |
$self->schema->storage->dbh_do( | |
sub { | |
my ( $storage, $dbh, $email ) = @_; | |
$dbh->do( | |
"delete from tbluser where email_address = '$email';"); | |
}, | |
$user->email_address | |
); | |
} | |
} | |
sub delete_user_data_tests { | |
my $self = shift; | |
my ( $user, $emails ); | |
SKIP: { | |
$user = $self->schema->resultset('User') | |
->find( { email_address => '[email protected]' } ); | |
skip "User already deleted", 5 if !defined($user); | |
lives_ok { | |
$user | |
= $self->schema->resultset('User') | |
->find( | |
{ email_address => '[email protected]' } ); | |
} | |
"I can find my user OK"; | |
lives_ok { | |
$emails = $self->schema->resultset('Email') | |
->search( { user_id => $user->user_id } ); | |
} | |
"I can find the emails OK"; | |
my $number_of_emails = $user->promotion_entries->count + 1; | |
my $result = $self->schema->storage->dbh_do( | |
sub { | |
my ( $storage, $dbh, $id ) = @_; | |
$dbh->do("delete from tblemail where user_id = $id"); | |
}, | |
$user->user_id | |
); | |
$result = $self->schema->storage->dbh_do( | |
sub { | |
my ( $storage, $dbh, $email ) = @_; | |
$dbh->do( | |
"delete from tbluser where email_address = '$email';"); | |
}, | |
$user->email_address | |
); | |
my $user_now = $self->schema->resultset('User') | |
->find( { email_address => '[email protected]' } ); | |
ok( !( defined($user_now) ), "My user is no longer in the database" ); | |
} | |
} | |
################### "ATTRIBUTES" ################### | |
sub base { | |
return 'http://localhost:3000/'; | |
} | |
sub username { | |
return '[email protected]'; | |
} | |
sub password { | |
return '601241726'; | |
} | |
sub user_id { | |
return '100003488602234'; | |
} | |
sub link_for_page_type { | |
return { | |
scholarship => qw/fb_login id/, | |
register => qw/fb_button_medium class/, | |
preapproved_logged_in_to_fb => "//img[\@alt='F']", | |
}; | |
} | |
sub url_for_page_type { | |
my $self = shift; | |
my $cdp_url = $self->schema->resultset('College')->first->cdp_url; | |
$cdp_url =~ s/^\///g; | |
return { | |
cdp => $self->base . $cdp_url, | |
masters => $self->base . 'masters-degree/', | |
home => $self->base, | |
}; | |
} | |
sub start_url_for_page_type { | |
return { | |
promotion => 'http://localhost:3000/campus-explorer-scholarships/', }; | |
} | |
sub promotion_types { | |
return [ | |
qw/ | |
review | |
facebook_like | |
twitter_follow | |
create_account | |
write_review | |
/ | |
]; | |
} | |
sub tomorrow { | |
my $self = shift; | |
my $now = CE::DateTime->now; | |
my $tomorrow = $now->clone->add( days => 1 ); | |
my $tomorrow_parsed | |
= $self->schema->storage->datetime_parser->format_datetime($tomorrow); | |
return $tomorrow_parsed; | |
} | |
sub yesterday { | |
my $self = shift; | |
my $now = CE::DateTime->now; | |
my $yesterday = $now->clone->subtract( days => 1 ); | |
my $yesterday_parsed | |
= $self->schema->storage->datetime_parser->format_datetime( | |
$yesterday); | |
return $yesterday_parsed; | |
} | |
sub admin { | |
my $self = shift; | |
return $self->schema->resultset('User') | |
->search( { roles => 'admin,reports,qa,cs,callqueue-admin' } )->first; | |
} | |
sub promotion_data_for { | |
my $self = shift; | |
my $yesterday = $self->yesterday; | |
my $tomorrow = $self->tomorrow; | |
my $admin_id = $self->admin->user_id; | |
return { | |
facebook_like => { | |
activation_date => $yesterday, | |
expiration_date => $tomorrow, | |
created_by => $admin_id, | |
updated_by => $admin_id, | |
published_time => $yesterday, | |
promotion_title => "Facebook Like", | |
promotion_cd => 'facebook_like', | |
status => 'current', | |
prize_type => 'scholarship', | |
prize_text => 'Win a brand new Facebook', | |
prize => 'a Facebook', | |
description => 'Win a brand new Facebook', | |
qualification_action => 'create_account', | |
}, | |
twitter_follow => { | |
activation_date => $yesterday, | |
expiration_date => $tomorrow, | |
created_by => $admin_id, | |
updated_by => $admin_id, | |
published_time => $yesterday, | |
promotion_title => "Twitter Follow", | |
promotion_cd => 'twitter_follow', | |
status => 'current', | |
prize_type => 'scholarship', | |
prize_text => 'Win a brand new Twitter', | |
prize => 'a Twitter', | |
description => 'Win a brand new Twitter', | |
qualification_action => 'create_account', | |
}, | |
create_account => { | |
activation_date => $yesterday, | |
expiration_date => $tomorrow, | |
created_by => $admin_id, | |
updated_by => $admin_id, | |
published_time => $yesterday, | |
promotion_title => "Account Follow", | |
promotion_cd => 'create_account', | |
status => 'current', | |
prize_type => 'scholarship', | |
prize_text => 'Win a brand new Account', | |
prize => 'a Account', | |
description => 'Win a brand new Account', | |
qualification_action => 'create_account', | |
}, | |
write_review => { | |
activation_date => $yesterday, | |
expiration_date => $tomorrow, | |
created_by => $admin_id, | |
updated_by => $admin_id, | |
published_time => $yesterday, | |
promotion_title => "Write Review Follow", | |
promotion_cd => 'write_review', | |
status => 'current', | |
prize_type => 'scholarship', | |
prize_text => 'Win a brand new Write Review', | |
prize => 'a Write Review', | |
description => 'Win a brand new Write Review', | |
qualification_action => 'create_account', | |
}, | |
review => { | |
activation_date => $yesterday, | |
expiration_date => $tomorrow, | |
created_by => $admin_id, | |
updated_by => $admin_id, | |
published_time => $yesterday, | |
promotion_title => "Review Follow", | |
promotion_cd => 'review', | |
status => 'current', | |
prize_type => 'premium', | |
prize_text => 'Write a brand new Review', | |
prize => 'a Review', | |
description => 'Write a brand new Review', | |
qualification_action => 'write_review', | |
}, | |
}; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment