API-DirectAdmin

 view release on metacpan or  search on metacpan

t/01-test.t  view on Meta::CPAN

is_deeply( $da->filter_hash( {  }, [ ]), {}, $func );
is_deeply( $da->filter_hash( { aaa => 555, bbb => 111 }, [ 'aaa' ]), { aaa => 555 }, $func );
is_deeply( $da->filter_hash( { aaa => 555, bbb => 111 }, [ ]), { }, $func );
is_deeply( $da->filter_hash( { }, [ 'aaa' ]), { }, $func );

$func = 'mk_query_string';
is( $da->mk_query_string( {  }  ), '', $func );
is( $da->mk_query_string( ''    ), '', $func );
is( $da->mk_query_string( undef ), '', $func );
is( $da->mk_query_string( { aaa => 111, bbb => 222 } ), 'aaa=111&bbb=222', $func );
is( $da->mk_query_string( { bbb => 222, aaa => 111 } ), 'aaa=111&bbb=222', $func );
is( $da->mk_query_string( [ ] ), '', $func );
is( $da->mk_query_string( { dddd => 'dfdf' } ), 'dddd=dfdf', $func );

$func = 'mk_full_query_string';
is( $da->mk_full_query_string( { command => 'CMD' } ), 
    'https://'.$connection_params{auth_user}.':'.$connection_params{auth_passwd}.'@'.$connection_params{host}.':2222/CMD?',
    $func
);

is( $da->mk_full_query_string( { command => 'CMD', allow_https => 0 } ), 
    'http://'.$connection_params{auth_user}.':'.$connection_params{auth_passwd}.'@'.$connection_params{host}.':2222/CMD?',
    $func
);

is( $da->mk_full_query_string( {
	command => 'CMD',
        param1  => 'val1',
        param2  => 'val2',
    } ), 
    'https://'.$connection_params{auth_user}.':'.$connection_params{auth_passwd}.'@'.$connection_params{host}.':2222/CMD?param1=val1&param2=val2',
    $func
);

is( $da->mk_full_query_string( {
        param1      => 'val1',
        param2      => 'val2',
        command     => 'CMD',
	    allow_https => 0, 
    } ), 
    'http://'.$connection_params{auth_user}.':'.$connection_params{auth_passwd}.'@'.$connection_params{host}.':2222/CMD?param1=val1&param2=val2',
    $func
);

# IP

use_ok('API::DirectAdmin::Ip');

$da->{fake_answer} = ! $ONLINE ? { list => ['127.0.0.1'], error => 0 } : undef;

my $ip_list = $da->ip->list();

my $main_shared_ip = $ip_list->[0];
ok($ip_list && ref $ip_list eq 'ARRAY' && scalar @$ip_list, 'API::DirectAdmin::Ip::list');

my %answer = (
    text    => "User $manipulate_user created",
    error   => 0,
    details => 'Unix User created successfully
Users System Quotas set
Users data directory created successfully
Domains directory created successfully
Domains directory created successfully in users home
Domain Created Successfully');
$da->{fake_answer} = ! $ONLINE ? \%answer : undef;

# User

use_ok('API::DirectAdmin::User');

my $result = $da->user->create(
    {
	username => $manipulate_user,
	domain   => 'zse1.ru',
	passwd   => 'qwerty',
	passwd2  => 'qwerty',
	email    => 'test@example.com',
	ip       => '127.0.0.1',
	package  => 'newpackage',
    }
);
is_deeply( $result, \%answer, 'API::DirectAdmin::User::create' );

%answer = (
  text    => 'Cannot Create Account',
  error   => 1,
  details => 'That username already exists on the system'
);
	
$da->{fake_answer} = ! $ONLINE ? \%answer : undef;

$result = $da->user->create(
    {
	username => $manipulate_user,
	domain   => 'zse1.ru',
	passwd   => 'qwerty',
	passwd2  => 'qwerty',
	email    => 'test@example.com',
	ip       => '127.0.0.1',
	package  => 'newpackage',
    }
);
is_deeply( $result, \%answer, 'API::DirectAdmin::User::create repeat');

%answer = (
    text 	=> 'Password Changed',
    error 	=> 0,
    details 	=> 'Password successfully changed'
);

$da->{fake_answer} = ! $ONLINE ? \%answer : undef;

$result = $da->user->change_password(
    {
	user => $manipulate_user,
	pass => 'sdfdsfsdfhsdfj',
    }
);
is_deeply( $result, \%answer, 'API::DirectAdmin::User::change_password');

%answer = (



( run in 1.279 second using v1.01-cache-2.11-cpan-677af5a14d3 )