#!/usr/bin/perl # $Id$ use strict; use Test::More 'no_plan'; use lib "$ENV{LJHOME}/cgi-bin"; require 'ljlib.pl'; require 'ljprotocol.pl'; no warnings 'redefine'; use LJ::Test qw (temp_user memcache_stress); use Class::Autouse qw ( LJ::SMS::Message LJ::SMS::MessageHandler ); use Carp qw (croak); my $lastmsg = ''; # trap message sending $LJ::_T_SMS_SEND = sub { my $msg = shift; $lastmsg = $msg->body_text; }; sub run_tests { my $u = temp_user(); my $sms_num = LJ::Test::alloc_sms_num(); # give user some messages $u->add_sms_quota(20, 'paid'); # pretend user just entered their sms number and carrier $u->set_prop('sms_carrier', 'cingular'); my $POST = { msisdn => $sms_num, }; my (@errors, @warnings, $redir); $u->set_sms_number($sms_num, verified => 'N'); LJ::run_hook('sms_post_register', u => $u, redir => \$redir, errors => \@errors); LJ::run_hook('sms_bml_post', 'u' => $u, 'POST' => $POST, 'errors' => \@errors, 'warnings' => \@warnings, redir => \$redir); my $name = $u->display_username; is($lastmsg, "Welcome to $LJ::SMS_TITLE. To validate this phone for $name reply with YES. You may" . " cancel at anytime by sending STOP. Standard rates apply.", "Confirmation message"); # register $u->t_receive_sms('Yes'); is($lastmsg, "This number is now validated for $name. Cancel at anytime by sending STOP. " . 'Send MENU for commands and HELP for program details. Standard rates apply.', "Registered message"); # menu $u->t_receive_sms('Menu'); is($lastmsg, "Available commands: (p)ost, (f)riends, (r)ead, (a)dd, i like, help. E.g. to read username " . "frank send \"read frank\". Standard rates apply.", "Menu"); # post $lastmsg = ''; $u->t_receive_sms('Post Today was one of the best days ever. I got a great new phone and I can even text ' . 'message in my journal entries to LJ!'); is($lastmsg, '', 'Post'); # no msg returned # add my $u2 = temp_user(); $u->t_receive_sms('Add ' . $u2->user); is($lastmsg, '', 'Add'); # interests $u->t_receive_sms('i like meeting new people'); is($lastmsg, '', 'Interests'); # help $u->t_receive_sms('Help'); is($lastmsg, "This is $LJ::SMS_TITLE from LiveJournal. For help contact support\@$LJ::SMS_DOMAIN or 415-294-5054. Send " . 'STOP to opt-out. Send MENU for commands. Standard rates apply.', 'Help'); # buy 100 $u->t_receive_sms('BUY100'); my $qty = $u->sms_quota_remaining; is($lastmsg, "\$4.99 will be charged to your next phone bill. Thank you!\n\n" . "LiveJournal.com - support\@$LJ::SMS_DOMAIN", 'Buy100'); # stop $u->t_receive_sms('Stop'); is($lastmsg, "Disable $LJ::SMS_TITLE? Send YES to confirm. Standard rates apply.", 'Stop confirm'); $u->t_receive_sms('Yes'); is($lastmsg, "You have discontinued $LJ::SMS_TITLE. You will no longer receive messages or charges " . "for this service. Questions contact support\@$LJ::SMS_DOMAIN", 'Stop'); } run_tests();