Subject: | Sending of comments and messages was broken; patch included |
Date: | Sat, 12 Apr 2008 17:51:14 +0100 |
To: | bug-www-myspace [...] rt.cpan.org |
From: | Steven Chamberlain <steven [...] pyro.eu.org> |
Hi,
The test suite was showing multiple failed tests relating to comments
and messages. With my attached patch, things seem to be working again
(for now).
The post_comment and send_message functions weren't working at all due
to changes in the forms. Also, read_message wasn't retrieving the
subject line, and the returned message body had some clutter at the end
causing a test to fail. This all seems to be fixed by my patch.
Also when posting a comment to someone not in your 'friends' list,
post_comment should return 'FF' but I think it was returning something
else like 'F'. I think the regex name was wrong, and it looks like it's
fixed now. A new test, which tries to post to someone definitely *not*
added to friends, would be useful there.
If you decide to use my patch and make another release sometime then I
hope SVN doesn't give you any trouble this time around!
I also noticed a slight problem in t/05-message which I haven't figured
out how to fix yet. A message is sent from one test account to the
other; but if a CAPTCHA is shown then the send_message test still
'passes' whereas I think it should be skipped with a warning instead. I
think it should also skip the following test too because that fails
otherwise (it logs into the recipient account to try and find the message).
As long as a CAPTCHA isn't experienced when sending the test message
between accounts, 'make test' now shows 100% passes. Many tests are
still being skipped though for functions that are currently 'disabled'.
I might be able to fix some of those sometime but I can't guarantee if
or when.
Thanks,
--
Steven Chamberlain
steven@pyro.eu.org
Index: t/05-message.t
===================================================================
--- t/05-message.t (revision 570)
+++ t/05-message.t (working copy)
@@ -84,7 +84,7 @@
is( $mr->{from}, $CONFIG->{acct1}->{friend_id}, "read_message From" );
is( $mr->{subject}, 'Hi '.$ident, "read_message Subject" );
#is( $mr->{date}, 'Feb 28, 2006 1:20 AM', "read_message Date" );
- is( $mr->{body}, "Just saying hi.\n\nHope all is well.\n", "read_message Body" );
+ is( $mr->{body}, "Just saying hi.\n\nHope all is well.", "read_message Body" );
SKIP: {
skip "delete_message tests disabled because Myspace's Delete button doesn't work", 2;
@@ -182,4 +182,4 @@
# Clean up
unlink 'msave.yml';
-}
\ No newline at end of file
+}
Index: lib/WWW/Myspace.pm
===================================================================
--- lib/WWW/Myspace.pm (revision 570)
+++ lib/WWW/Myspace.pm (working copy)
@@ -118,8 +118,8 @@
# What should we look for to see if we are being asked for a CAPTCHA code?
# We'll extract the URL to return from the area in parenthesis.
-our $CAPTCHA='<img.*?src="(http:\/\/security.myspace.com\/CAPTCHA\/'.
- 'CAPTCHA\.aspx\?SecurityToken=[^"]+)"';
+our $CAPTCHA='<img.*?src="(http:\/\/security\.myspace\.com\/captcha\/'.
+ 'captcha\.aspx\?SecurityToken=[^"]+)"';
our $CAPTCHAi = qr/$CAPTCHA/io; # ok, we will store both ways
our $CAPTCHAs = qr/$CAPTCHA/o;
#$CAPTCHA = $CAPTCHAi; # use case insensitive for now
@@ -203,8 +203,8 @@
comment_posted => qr/Your Comment has been posted/io,
not_logged_in => qr/You Must Be Logged-In to do That\!/io,
verify_message_sent => qr/Your Message Has Been Sent\!/o,
- comment_p1 => qr/ctl00\$(cp)?Main\$postComment\$commentTextBox.*<\/form|$NOT_FRIEND_ERROR|($CAPTCHA)|($INVALID_ID)/smio,
- comment_p2 => qr/ctl00\$(cp)?Main\$postComment\$Button1.*<\/form/smo,
+ comment_p1 => qr/ctl00\$(cp)?Main\$UserWriteCommentsControl\$commentTextBox.*<\/form|($NOT_FRIEND_ERROR)|($CAPTCHA)|($INVALID_ID)/smio,
+ comment_p2 => qr/ctl00\$(cp)?Main\$UserWriteCommentsControl\$ConfirmPostButton.*<\/form/smo,
comment_approval_msg => qr/This user requires all comments to be approved before being posted/o,
not_friend => qr/$NOT_FRIEND_ERROR/smo,
bulletin_url => qr/fuseaction=bulletin\.edit/io,
@@ -3445,7 +3445,7 @@
# Submit the comment to $friend_id's page
$link = $self->mech->find_link(
- text_regex => qr/^add\s+comment$/io );
+ text_regex => qr/^Add\s+Comment$/io );
unless ( $link ) { $status="FL"; last TESTBLOCK; }
( $DEBUG ) && print "Getting comment form..\n";
@@ -3455,8 +3455,9 @@
follow => 1,
form_name => 'aspnetForm',
fields_ref => {
- 'ctl00$cpMain$postComment$commentTextBox' => "$message",
- '__EVENTTARGET' => 'ctl00$cpMain$postComment$postcommentImageButton',
+ 'ctl00$cpMain$UserWriteCommentsControl$commentTextBox' => "$message",
+ 'ctl00$cpMain$UserWriteCommentsControl$postcommentImageButton' => "Post A Comment",
+ # '__EVENTTARGET' => 'ctl00$cpMain$UserWriteCommentsControl$postcommentImageButton',
# '__EVENTARGUMENT' => '',
},
re1 => 'comment_p1',
@@ -3484,7 +3485,7 @@
$submitted = $self->submit_form( {
follow => 1,
form_name => 'aspnetForm',
- button => 'ctl00$cpMain$postComment$ConfirmPostButton',
+ button => 'ctl00$cpMain$UserWriteCommentsControl$ConfirmPostButton',
@captcha
} );
} else {
@@ -3503,7 +3504,7 @@
$page =~ s/[ \t\n\r]+/ /g;
# Set the status code to return.
- if ( $self->_apply_regex( source => $page, regex => 'not_friend_error' ) ) {
+ if ( $self->_apply_regex( source => $page, regex => 'not_friend' ) ) {
$status="FF";
} elsif ( $self->_apply_regex( source => $page, regex => 'is_invalid' ) ) {
$status="FI";
@@ -3977,7 +3978,7 @@
$message{'date'} = $1;
# Subject:
- if ( $page =~ /<th.*?>\s*Subject:\s*<.*?<td>\s*(.*?)\s*<\/td>/smo ) {
+ if ( $page =~ /<p.*?>\s*Subject:\s*<.*?<p.*?>\s*(.*?)\s*<\/p>/smo ) {
$message{'subject'} = $1;
}
@@ -3995,18 +3996,18 @@
# Clean up newlines
$message{'body'} =~ s/[\n\r]/\n/go;
- # Gotta clean white space before and after the body
- $message{'body'} =~ s/^\s*//so; # Before
- $message{'body'} =~ s/\s*$//so; # After
-
# And they have these BR tags at the beginning of each line...
# Not any more - 8/16/07
# $message{'body'} =~ s/^[ \t]*<br \/>[ \t]*//mog;
# And sometimes they put them elsewhere, so we'll convert those to newlines.
# (Note: Maybe this shouldn't be done, since the messages *are* HTML after all)
- $message{'body'} =~ s/<br \/>/\n/mog;
-
+ $message{'body'} =~ s/<br (style=\"display:none\")?\/>/\n/mog;
+
+ # Gotta clean white space before and after the body
+ $message{'body'} =~ s/^\s*//so; # Before
+ $message{'body'} =~ s/\s*$//so; # After
+
return \%message;
}
@@ -4317,13 +4318,14 @@
# New mail form...
$submitted = $self->submit_form( {
form_name => 'aspnetForm',
+ button => 'ctl00$ctl00$Main$messagingMain$SendMessage$btnSend',
fields_ref => {
- 'ctl00$ctl00$Main$Main$sendMessageControl$subjectTextBox' =>
+ 'ctl00$ctl00$Main$messagingMain$SendMessage$subjectTextBox' =>
"$options{'subject'}",
- 'ctl00$ctl00$Main$Main$sendMessageControl$bodyTextBox' =>
+ 'ctl00$ctl00$Main$messagingMain$SendMessage$bodyTextBox' =>
"$options{'message'}",
- '__EVENTTARGET' => 'ctl00$ctl00$Main$Main$sendMessageControl$btnSend',
- '__EVENTARGUMENT' => ''
+ '__EVENTTARGET' => 'ctl00$ctl00$Main$messagingMain$SendMessage$btnSend',
+ '__EVENTARGUMENT' => ''
},
no_click => 1,