API-CPanel

 view release on metacpan or  search on metacpan

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

#!/usr/bin/perl -w

use strict;
use warnings;
use lib qw( ./lib );

use Data::Dumper;

our $ONLINE;

BEGIN {
    #$ENV{auth_user}   = 'restest';
    #$ENV{auth_passwd} = '123';
    #$ENV{host}        = '192.168.123.1';
    $ONLINE = $ENV{auth_user} && $ENV{auth_passwd} && $ENV{host};
}

my $manipulate_user = 'zsezse';

use Test::More tests => $ONLINE ? 61 : 61;

my $test_host = $ENV{host} || '127.0.0.1';

ok(1, 'Test OK');
use_ok('API::CPanel');

$a = 'refs';

is( refs( undef ),   '',       $a);
is( refs( {} ),      'HASH',   $a );
is( refs( [] ),      'ARRAY',  $a );
is( refs( sub {} ),  'CODE',   $a );
is( refs( \$a ),     'SCALAR', $a );

$a = 'is_success';

ok(! is_success(), $a);
ok(! is_success( { error => {}, data => {} } ), $a);
ok(! is_success( { data  => {} } ), $a);
ok(! is_success( { } ), $a);
ok(  is_success( { status => 1 } ), $a);

$a = 'filter_hash';
is_deeply( API::CPanel::filter_hash( {  }, [ ]), {}, $a );
is_deeply( API::CPanel::filter_hash( { aaa => 555, bbb => 111 }, [ 'aaa' ]), { aaa => 555 }, $a );
is_deeply( API::CPanel::filter_hash( { aaa => 555, bbb => 111 }, [ ]), { }, $a );
is_deeply( API::CPanel::filter_hash( { }, [ 'aaa' ]), { }, $a );

$a = 'mk_query_string';
is( API::CPanel::mk_query_string( {  }  ), '', $a );
is( API::CPanel::mk_query_string( ''    ), '', $a );
is( API::CPanel::mk_query_string( undef ), '', $a );
is( API::CPanel::mk_query_string( { aaa => 111, bbb => 222 } ), 'aaa=111&bbb=222', $a );
is( API::CPanel::mk_query_string( { bbb => 222, aaa => 111 } ), 'aaa=111&bbb=222', $a );
is( API::CPanel::mk_query_string( [ ] ), '', $a );
is( API::CPanel::mk_query_string( { dddd => 'dfdf' } ), 'dddd=dfdf', $a );

my $kill_start_end_slashes_test = {
    '////aaa////' => 'aaa',
    'bbb////'     => 'bbb',
    '////ccc'     => 'ccc', 
    ''            => '',
};

for (keys %$kill_start_end_slashes_test) {
    is(
        API::CPanel::kill_start_end_slashes ($_),
        $kill_start_end_slashes_test->{$_},
        'kill_start_end_slashes'
    );
}

$a = 'mk_full_query_string';
is( API::CPanel::mk_full_query_string( {
        host => $test_host, 
    } ), 
    '',
    $a
);

is( API::CPanel::mk_full_query_string( {
        host       => $test_host,
        allow_http => 1,
        path       => 'xml-api',
    } ), 
    '',
    $a
);

is(  API::CPanel::mk_full_query_string( {
        host       => $test_host,
        allow_http => 1,

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


$result = API::CPanel::User::list_simple(
    {
	%correct_params,
    }
);
ok( ref $result eq 'ARRAY' && scalar @$result, 'API::CPanel::User::list_simple');

$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<restartservice>
  <restart>
      <rawout>Apache successfully restarted.</rawout>
      <result>1</result>
      <service>httpd</service>
      <servicename>Apache Web Server</servicename>
  </restart>
</restartservice>
THEEND

$result = API::CPanel::Misc::reload(
    {
	%correct_params,
	service     => 'httpd',
    }
);
is( $result, 1, 'API::CPanel::Misc::reload');

$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<addpkg>
  <result>
    <pkg>Host-3</pkg>
    <status>1</status>
    <statusmsg>Created the package Host-343</statusmsg>
  </result>
</addpkg>
THEEND

$result = API::CPanel::Package::add(
    {
	%correct_params,
	name      => 'Host-343',
	quota     => 110,
	frontpage => 1,
	maxlsts   => 15,
	maxsql    => 99,
    }
);

is( $result, 1, 'API::CPanel::Package::add');

$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<changepackage>
  <result>
    <rawout>&lt;pre&gt;
Changing bwlimit to unlimited Meg
Changing Feature List to default
Changing max pop accounts from unlimited to unlimited
Changing max sql accounts from 14 to 99
Changing max ftp accounts from unlimited to unlimited
Changing max lists from unlimited to unlimited
Changing max sub domains from unlimited to unlimited
Changing language from ru to en
Changing max parked domains from 0 to 0
Changing max addon domains from 0 to 0
Shell Access Set Correctly (noshell)
Changing cPanel theme from x to
Changing plan from default to Host-343
Resetting QUOTA....
Using Quota v3 Support
Bandwidth limit (0) is lower than (unlimited) (all limits removed)&lt;br /&gt;&lt;blockquote&gt;&lt;div style='float:left;'&gt;Enabling...&lt;/div&gt;&lt;div style='float:left;'&gt;...zse1.ru...&lt;/div&gt;&lt;div style='float:left;'&gt;Done&lt;/div&...
</rawout>
    <status>1</status>
    <statusmsg>Account Upgrade/Downgrade Complete for zsezse</statusmsg>
  </result>
</changepackage>
THEEND

$result = API::CPanel::User::change_package(
    {
	%correct_params,
	user        => $manipulate_user,
	pkg         => 'Host-343',
    }
);

is( $result, 1, 'API::CPanel::User::change_package');

$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<editpkg>
  <result>
    <pkg>Host-3</pkg>
    <status>1</status>
    <statusmsg>Modified the package Host-343</statusmsg>
  </result>
</editpkg>
THEEND

$result = API::CPanel::Package::edit(
    {
	%correct_params,
	name        => 'Host-343',
	quota       => 100,
	frontpage   => 0,
	maxlsts     => 45,
    }
);

is( $result, 1, 'API::CPanel::Package::edit');

$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<listpkgs>
  <package>
    <name>Host-1</name>
    <BWLIMIT>100</BWLIMIT>
    <CGI>y</CGI>
    <CPMOD>x3</CPMOD>
    <FEATURELIST>default</FEATURELIST>
    <FRONTPAGE>n</FRONTPAGE>
    <HASSHELL>y</HASSHELL>
    <IP>n</IP>
    <LANG>ru</LANG>



( run in 2.181 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )