Ready for 7.10.29 development.

This commit is contained in:
Colin Kuskie 2013-03-20 21:38:23 -07:00
commit c806f99b7b
4236 changed files with 1217679 additions and 0 deletions

69
t/Operation/AdSpace.t Normal file
View file

@ -0,0 +1,69 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# This tests the operation of saving the AdSpaces
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::AdSpace;
use WebGUI::Operation::AdSpace;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $adSpace;
#----------------------------------------------------------------------------
# Tests
plan tests => 3; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Test that AdSpace name can't have ']' characters in them
# Create an AdSpace to verify the saving
$adSpace = WebGUI::AdSpace->create( $session, { name => 'oldname', } );
my $output
= WebGUI::Test->getPage(
'WebGUI::Operation::AdSpace::www_editAdSpaceSave',
undef,
{
args => [ $session ],
formParams => {
adSpaceId => $adSpace->getId,
name => 'This should ] fail',
},
userId => 3,
},
);
like(
$output,
qr/error/,
"Notifies user that an error occurred",
);
like(
$output,
qr/invalid/,
"Notifies user what the error is",
);
ok( $adSpace->get('name') eq 'oldname', 'AdSpace does not get saved.' );
$adSpace->delete;

141
t/Operation/Auth.t Normal file
View file

@ -0,0 +1,141 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# This tests the operation of Authentication
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Operation::Auth;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Test package for method dispatch
BEGIN { $INC{'WebGUI/Auth/TestAuth.pm'} = __FILE__; }
package WebGUI::Auth::TestAuth;
use base 'WebGUI::Auth';
sub new {
my $self = shift->SUPER::new(@_);
$self->setCallable( ['callable'] );
return bless $self, 'WebGUI::Auth::TestAuth'; # Auth requires rebless
}
sub callable {
return "callable";
}
sub not_callable {
return "not callable";
}
sub www_verify {
return "verify";
}
package main;
#----------------------------------------------------------------------------
# Tests
plan tests => 10; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Test the getInstance method
# By default, it returns a WebGUI::Auth::WebGUI object
my $auth = WebGUI::Operation::Auth::getInstance( $session );
ok($auth, 'getInstance returned something');
isa_ok($auth, 'WebGUI::Auth::' . $session->setting->get('authMethod') );
# Test setting authType by form var
$session->request->setup_body({
authType => 'TestAuth',
});
isa_ok(
WebGUI::Operation::Auth::getInstance( $session ),
'WebGUI::Auth::' . $session->setting->get('authMethod'),
'AuthType not in config file, so return default authType',
);
WebGUI::Test->originalConfig( 'authMethods' );
$session->config->addToArray( 'authMethods', 'TestAuth' );
isa_ok(
WebGUI::Operation::Auth::getInstance( $session ),
'WebGUI::Auth::TestAuth',
'AuthType in config file, so return instance of authType',
);
$session->user({ userId => 3 });
isa_ok(
WebGUI::Operation::Auth::getInstance( $session ),
'WebGUI::Auth::WebGUI',
'AuthType is defined by the logged-in user',
);
#----------------------------------------------------------------------------
# Test the web method for auth operation
# First a clean session, without an authenticated user
$session->user({ userId => 1 });
my $output = WebGUI::Operation::Auth::www_auth($session);
like(
$output,
qr/<input type="hidden" name="method" value="login" /,
"Hidden form elements for login displayed",
);
# Become admin and test web method
$session->user({userId => 3});
$output = WebGUI::Operation::Auth::www_auth($session);
unlike(
$output,
qr/<input type="hidden" name="method" value="login" /,
"Hidden form elements for login NOT displayed to valid user",
);
# Go back to visitor and test callable dispatch
$session->user({ userId => 1 });
$session->request->setup_body({
authType => 'TestAuth',
method => 'callable',
});
eval { $output = WebGUI::Operation::Auth::www_auth( $session ); };
like( $output, qr{\bcallable\b}, 'Callable method is callable' );
# Test a method not in callable
$session->user({ userId => 1 });
$session->request->setup_body({
authType => 'TestAuth',
method => 'not_callable',
});
my $i18n = WebGUI::International->new($session);
my $error = $i18n->get(1077);
eval { $output = WebGUI::Operation::Auth::www_auth( $session ); };
like( $output, qr{$error}, 'not_callable method gives error message' );
# Test www_ dispatch
$session->user({ userId => 1 });
$session->request->setup_body({
authType => 'TestAuth',
method => 'verify',
});
eval { $output = WebGUI::Operation::Auth::www_auth( $session ); };
like( $output, qr{verify}, 'www_ callable without being setCallable' );

194
t/Operation/User.t Normal file
View file

@ -0,0 +1,194 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# This tests the operation of Authentication
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use Test::Deep;
use Exception::Class;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::User;
use WebGUI::Operation::User;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
$session->user({ userId => 3 });
my $andy = WebGUI::User->new($session, "new");
WebGUI::Test->addToCleanup($andy);
$andy->username("andydufresne");
#----------------------------------------------------------------------------
# Tests
plan tests => 10; # Increment this number for each test you create
#----------------------------------------------------------------------------
#######################################################################
#
# www_editUserSave
#
#######################################################################
tie my %profile_info, "Tie::IxHash", (
firstName => "Andy",
lastName => "Dufresne",
homeAddress => "123 Shank Ave.",
homeCity => "Shawshank",
homeState => "PA",
homeZip => "11223",
homeCountry => "US",
homePhone => "111-111-1111",
email => 'andy@shawshank.com'
);
$session->request->setup_body({
uid => $andy->getId,
username => $andy->username,
webguiCsrfToken => $session->scratch->get('webguiCsrfToken'),
%profile_info
});
$session->request->method('POST');
WebGUI::Operation::User::www_editUserSave($session);
$andy = WebGUI::User->new($session,$andy->getId);
#Test that the address was saved to the profile
cmp_bag(
[ map { $andy->profileField($_) } keys %profile_info ],
[ values %profile_info ],
'Profile fields were saved'
);
#Test that the addressBook was created
my $bookId = $session->db->quickScalar(
q{ select addressBookId from addressBook where userId=? },
[$andy->getId]
);
ok( ($bookId ne ""), "Address Book was created");
my $book = WebGUI::Shop::AddressBook->new($session,$bookId);
my @addresses = @{ $book->getAddresses() };
is(scalar(@addresses), 1 , "One address was created in the address book");
my $address = $addresses[0];
tie my %address_info, "Tie::IxHash", (
firstName => $address->get("firstName"),
lastName => $address->get("lastName"),
homeAddress => $address->get("address1"),
homeCity => $address->get("city"),
homeState => $address->get("state"),
homeZip => $address->get("code"),
homeCountry => $address->get("country"),
homePhone => $address->get("phoneNumber"),
email => $address->get("email")
);
#Test that the address was saved properly to shop
cmp_bag(
[ values %profile_info ],
[ values %address_info ],
'Shop address was has the right information'
);
#Test that the address is returned as the profile address
my $profileAddress = $book->getProfileAddress;
is($profileAddress->getId, $address->getId, "Profile linked properly to address");
#Test that the address is the default address
my $defaultAddress = $book->getDefaultAddress;
is(
$defaultAddress->getId,
$address->getId,
"Profile address properly set to default address when created"
);
#Test updates to existing addresses
%profile_info = (
firstName => "Andy",
lastName => "Dufresne",
homeAddress => "123 Seaside Ave.",
homeCity => "Zihuatanejo",
homeState => "Guerrero",
homeZip => "40880",
homeCountry => "MX",
homePhone => "222-222-2222",
email => 'andy@freeman.com'
);
$session->request->setup_body({
uid => $andy->getId,
username => $andy->username,
webguiCsrfToken => $session->scratch->get('webguiCsrfToken'),
%profile_info
});
$session->request->method('POST');
WebGUI::Operation::User::www_editUserSave($session);
$andy = WebGUI::User->new($session,$andy->getId);
#Test that the address was saved to the profile
cmp_bag (
[ map { $andy->profileField($_) } keys %profile_info ],
[ values %profile_info ],
'Profile fields were updated'
);
#Test that there is still only one address book and one address
my @bookIds = $session->db->quickArray(
q{ select addressBookId from addressBook where userId=? },
[$andy->getId]
);
is( scalar(@bookIds), 1, "Only one address book exists after update" );
$bookId = $bookIds[0];
$book = WebGUI::Shop::AddressBook->new($session,$bookId);
@addresses = @{ $book->getAddresses() };
is( scalar(@addresses), 1 , "Only one address exists after update");
my $address = $addresses[0];
%address_info = (
firstName => $address->get("firstName"),
lastName => $address->get("lastName"),
homeAddress => $address->get("address1"),
homeCity => $address->get("city"),
homeState => $address->get("state"),
homeZip => $address->get("code"),
homeCountry => $address->get("country"),
homePhone => $address->get("phoneNumber"),
email => $address->get("email")
);
#Test that the address was saved properly to shop
cmp_bag(
[ values %profile_info ],
[ values %address_info ],
'Shop address was has the right information'
);

457
t/Operation/User/service.t Normal file
View file

@ -0,0 +1,457 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Test the user services from WebGUI::Operation::User
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../../lib";
use Test::More;
use Test::Deep;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use XML::Simple;
use JSON;
use WebGUI::Operation::User;
use WebGUI::Operation::Auth;
use Data::Dumper;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
WebGUI::Test->originalConfig( "serviceSubnets" );
$session->config->delete('serviceSubnets');
my ( $response, $responseObj, $auth, $userAndy, $userRed );
#----------------------------------------------------------------------------
# Tests
plan tests => 56; # Increment this number for each test you create
#----------------------------------------------------------------------------
# www_ajaxCreateUser
# Permissions
# - user
$session->user({ userId => 1 });
$response = WebGUI::Operation::User::www_ajaxCreateUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::Unauthorized',
message => ignore(),
},
"Unauthorized user gets correct error object",
);
# - serviceSubnets
$ENV{REMOTE_ADDR} = '2.2.2.2';
$session->config->set('serviceSubnets',['1.1.1.1/32']);
$session->user({ userId => 3 });
$session->request->setup_body({
as => "xml",
});
$response = WebGUI::Operation::User::www_ajaxCreateUser( $session );
is( $session->http->getMimeType, 'application/xml', "Correct mime type (as => xml)" );
cmp_deeply(
XML::Simple::XMLin( $response ),
{
error => 'WebGUI::Error::Unauthorized',
message => ignore(),
},
"Unauthorized user gets correct error object",
);
$session->request->setup_body({});
$session->config->delete('serviceSubnets');
# Invalid parameters
# - username missing
$session->request->setup_body({
as => "json",
'auth:WebGUI:identifier' => 'somethingorother',
firstName => "Andy",
});
$session->user({ userId => 3 });
$response = WebGUI::Operation::User::www_ajaxCreateUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (as => json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::InvalidParam',
param => 'username',
message => ignore(),
},
"Missing username gets correct error object",
);
# - username exists
$session->request->setup_body({
username => "Visitor",
firstName => 'Jake',
});
$response = WebGUI::Operation::User::www_ajaxCreateUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::InvalidParam',
param => 'username',
message => ignore(),
},
"Existing username gets correct error object",
);
# Correct operation
# - with webgui password
$session->request->setup_body({
username => "ADufresne",
'auth:WebGUI:identifier' => 'Zihuatanejo',
'auth:WebGUI:changePassword'=> 1,
firstName => "Andy",
lastName => "Dufresne",
'auth:LDAP:connectDN' => 'u=andy;o=block-e;dc=shawshank;dc=me',
});
$response = WebGUI::Operation::User::www_ajaxCreateUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json" );
$responseObj = JSON->new->decode( $response );
cmp_deeply(
$responseObj,
{
user => superhashof({
userId => re(qr/^.{22}$/),
username => 'ADufresne',
firstName => 'Andy',
lastName => 'Dufresne',
authMethod => 'WebGUI', # default auth method
}),
},
"Success response contains new users information",
);
$userAndy = WebGUI::User->new( $session, $responseObj->{user}->{userId} );
is( $userAndy->get("username"), "ADufresne", "User exists and username is correct" );
$auth = WebGUI::Operation::Auth::getInstance( $session, 'WebGUI', $userAndy->getId );
is( $auth->getParams->{identifier}, $auth->hashPassword('Zihuatanejo'), "Password is correct" );
is( $auth->getParams->{changePassword}, 1, "Auth param set correctly (WebGUI)" );
$auth = WebGUI::Operation::Auth::getInstance( $session, 'LDAP', $userAndy->getId );
is( $auth->getParams->{connectDN}, 'u=andy;o=block-e;dc=shawshank;dc=me', "Auth param set correctly (LDAP)" );
# - without webgui password
$session->request->setup_body({
username => "EBRedding",
'auth:WebGUI:changePassword'=> 1,
firstName => "Ellis",
lastName => "Redding",
'auth:LDAP:connectDN' => 'u=red;o=block-e;dc=shawshank;dc=me',
});
$response = WebGUI::Operation::User::www_ajaxCreateUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json" );
$responseObj = JSON->new->decode( $response );
cmp_deeply(
$responseObj,
{
user => superhashof({
userId => re(qr/^.{22}$/),
username => 'EBRedding',
firstName => 'Ellis',
lastName => 'Redding',
authMethod => 'WebGUI', # default auth method
}),
},
"Success response contains new users information",
) or diag explain $responseObj;
$userRed = WebGUI::User->new( $session, $responseObj->{user}->{userId} );
is( $userRed->get("username"), "EBRedding", "User exists and username is correct" );
$auth = WebGUI::Operation::Auth::getInstance( $session, 'WebGUI', $userRed->getId );
is( $auth->getParams->{changePassword}, 1, "Auth param set correctly (WebGUI)" );
$auth = WebGUI::Operation::Auth::getInstance( $session, 'LDAP', $userRed->getId );
is( $auth->getParams->{connectDN}, 'u=red;o=block-e;dc=shawshank;dc=me', "Auth param set correctly (LDAP)" );
#----------------------------------------------------------------------------
# www_ajaxUpdateUser
# Permissions
# - user
$session->user({ userId => 1 });
$response = WebGUI::Operation::User::www_ajaxUpdateUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::Unauthorized',
message => ignore(),
},
"Unauthorized user gets correct error object",
);
# - serviceSubnets
$ENV{REMOTE_ADDR} = '2.2.2.2';
$session->config->set('serviceSubnets',['1.1.1.1/32']);
$session->user({ userId => 3 });
$session->request->setup_body({
as => "xml",
});
$response = WebGUI::Operation::User::www_ajaxUpdateUser( $session );
is( $session->http->getMimeType, 'application/xml', "Correct mime type (as => xml)" );
cmp_deeply(
XML::Simple::XMLin( $response ),
{
error => 'WebGUI::Error::Unauthorized',
message => ignore(),
},
"Unauthorized user gets correct error object",
);
$session->request->setup_body({});
$session->config->delete('serviceSubnets');
# Invalid parameters
# - no userId parameter
$session->request->setup_body({
as => "json",
'auth:WebGUI:identifier' => 'somethingorother',
firstName => "Andy",
});
$session->user({ userId => 3 });
$response = WebGUI::Operation::User::www_ajaxUpdateUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (as => json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::InvalidParam',
param => 'userId',
message => ignore(),
},
"Missing userId gets correct error object",
);
# - userId doesn't exist
$session->request->setup_body({
userId => "MORGANFREEMANREDHRNG",
'auth:WebGUI:identifier' => 'somethingorother',
firstName => "Andy",
});
$session->user({ userId => 3 });
$response = WebGUI::Operation::User::www_ajaxUpdateUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::InvalidParam',
param => 'userId',
message => ignore(),
},
"Invalid userId gets correct error object",
);
# Correct operation
# - with webgui password
$session->request->setup_body({
userId => $userAndy->getId,
'auth:WebGUI:identifier' => 'RichardsHotelAndFishing',
'auth:WebGUI:changeUsername'=> 1,
firstName => "Richard",
lastName => "Stevens",
'auth:LDAP:connectDN' => 'u=rich;o=escapee;dc=shawshank;dc=me',
});
$response = WebGUI::Operation::User::www_ajaxUpdateUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json" );
$responseObj = JSON->new->decode( $response );
cmp_deeply(
$responseObj,
{
user => superhashof({
userId => $userAndy->getId,
username => 'ADufresne',
firstName => 'Richard',
lastName => 'Stevens',
authMethod => 'WebGUI', # default auth method
}),
},
"Success response contains new users information",
);
$userAndy = WebGUI::User->new( $session, $responseObj->{user}->{userId} );
is( $userAndy->get("username"), "ADufresne", "User exists and username is correct" );
$auth = WebGUI::Operation::Auth::getInstance( $session, 'WebGUI', $userAndy->getId );
is( $auth->getParams->{identifier}, $auth->hashPassword('RichardsHotelAndFishing'), "Password is correct" );
is( $auth->getParams->{changeUsername}, 1, "Auth param set correctly (WebGUI)" );
$auth = WebGUI::Operation::Auth::getInstance( $session, 'LDAP', $userAndy->getId );
is( $auth->getParams->{connectDN}, 'u=rich;o=escapee;dc=shawshank;dc=me', "Auth param set correctly (LDAP)" );
# - without webgui password
$session->request->setup_body({
userId => $userRed->userId,
'auth:WebGUI:changeUsername'=> 1,
firstName => "Red",
'auth:LDAP:connectDN' => 'u=red;o=parollee;dc=shawshank;dc=me',
});
$response = WebGUI::Operation::User::www_ajaxUpdateUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json" );
$responseObj = JSON->new->decode( $response );
cmp_deeply(
$responseObj,
{
user => superhashof({
userId => $userRed->userId,
username => 'EBRedding',
firstName => 'Red',
lastName => 'Redding',
authMethod => 'WebGUI', # default auth method
}),
},
"Success response contains new users information",
) or diag explain $responseObj;
$userRed = WebGUI::User->new( $session, $responseObj->{user}->{userId} );
is( $userRed->get("username"), "EBRedding", "User exists and username is correct" );
$auth = WebGUI::Operation::Auth::getInstance( $session, 'WebGUI', $userRed->getId );
is( $auth->getParams->{changeUsername}, 1, "Auth param set correctly (WebGUI)" );
$auth = WebGUI::Operation::Auth::getInstance( $session, 'LDAP', $userRed->getId );
is( $auth->getParams->{connectDN}, 'u=red;o=parollee;dc=shawshank;dc=me', "Auth param set correctly (LDAP)" );
#----------------------------------------------------------------------------
# www_ajaxDeleteUser
# Permissions
# - user
$session->user({ userId => 1 });
$response = WebGUI::Operation::User::www_ajaxDeleteUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::Unauthorized',
message => ignore(),
},
"Unauthorized user gets correct error object",
);
# - serviceSubnets
$ENV{REMOTE_ADDR} = '2.2.2.2';
$session->config->set('serviceSubnets',['1.1.1.1/32']);
$session->user({ userId => 3 });
$session->request->setup_body({
as => "xml",
});
$response = WebGUI::Operation::User::www_ajaxDeleteUser( $session );
is( $session->http->getMimeType, 'application/xml', "Correct mime type (as => xml)" );
cmp_deeply(
XML::Simple::XMLin( $response ),
{
error => 'WebGUI::Error::Unauthorized',
message => ignore(),
},
"Unauthorized user gets correct error object",
);
$session->request->setup_body({});
$session->config->delete('serviceSubnets');
# Invalid parameters
# - no userId parameter
$session->request->setup_body({
as => "json",
});
$session->user({ userId => 3 });
$response = WebGUI::Operation::User::www_ajaxDeleteUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (as => json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::InvalidParam',
param => 'userId',
message => ignore(),
},
"Missing userId gets correct error object",
);
# - userId doesn't exist
$session->request->setup_body({
userId => "MORGANFREEMANREDHRNG",
});
$session->user({ userId => 3 });
$response = WebGUI::Operation::User::www_ajaxDeleteUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::InvalidParam',
param => 'userId',
message => ignore(),
},
"Invalid userId gets correct error object",
);
# - Cannot delete Visitor
$session->request->setup_body({
userId => "1",
});
$session->user({ userId => 3 });
$response = WebGUI::Operation::User::www_ajaxDeleteUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::InvalidParam',
param => 'userId',
message => ignore(),
},
"Cannot delete Visitor",
);
# - Cannot delete Admin
$session->request->setup_body({
userId => '3',
});
$session->user({ userId => 3 });
$response = WebGUI::Operation::User::www_ajaxDeleteUser( $session );
is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" );
cmp_deeply(
JSON->new->decode( $response ),
{
error => 'WebGUI::Error::InvalidParam',
param => 'userId',
message => ignore(),
},
"Cannot delete Admin",
);
# Correct operation
$session->request->setup_body({
userId => $userAndy->getId,
});
$response = WebGUI::Operation::User::www_ajaxDeleteUser( $session );
is( $session->http->getMimeType, 'application/json', 'Correct mime type (default: json)' );
cmp_deeply(
JSON->new->decode( $response ),
{
message => ignore(),
},
"Success returns only message, no error",
);
ok( !WebGUI::User->validUserId( $session, $userAndy->getId ), "UserId no longer exists" );
$session->request->setup_body({
userId => $userRed->getId,
});
$response = WebGUI::Operation::User::www_ajaxDeleteUser( $session );
is( $session->http->getMimeType, 'application/json', 'Correct mime type (default: json)' );
cmp_deeply(
JSON->new->decode( $response ),
{
message => ignore(),
},
"Success returns only message, no error",
);
ok( !WebGUI::User->validUserId( $session, $userRed->getId ), "UserId no longer exists" );
#vim:ft=perl