API-PleskExpand

 view release on metacpan or  search on metacpan

t/expand.t  view on Meta::CPAN

);



my $delete_query = API::PleskExpand::Accounts::delete( id => 15 );

is_deeply( $delete_query . "\n", <<DOC, 'delete account test');
<del><!-- del_client --><filter><id>15</id></filter></del>
DOC


my $modify_query = API::PleskExpand::Accounts::modify(
    id => 15, 
    general_info => { status => 16 } # deactivate!
);


is_string( $modify_query, $_, 'modify account test') for
'<set><filter><id>15</id></filter><!-- modify_client --><values>' .
'<gen_info><status>16</status></gen_info></values></set>';


my $modify_query_alter = API::PleskExpand::Accounts::modify(
    id => 5, 
    general_info => { status => 0 } # deactivate!
);


is_string( $modify_query_alter, $_, 'modify account test') for 
'<set><filter><id>5</id></filter><!-- modify_client --><values>' .
'<gen_info><status>0</status></gen_info></values></set>';

my %new_domain_data = (
    dname               => 'y2a1ddsdfandex.ru',
    client_id           => 16,
    'template-id'       => 1,
    ftp_login           => 'nrddgddsdasd',
    ftp_password        => 'dadsdasd',
);

my $create_domain = API::PleskExpand::Domains::create( %new_domain_data );


is_string( $create_domain, $_, 'modify account test') for 
'<add_use_template><gen_setup><name>y2a1ddsdfandex.ru</name>'  .
'<client_id>16</client_id><status>0</status></gen_setup>'      .
'<hosting><vrt_hst><ftp_login>nrddgddsdasd</ftp_login>'        .
'<ftp_password>dadsdasd</ftp_password></vrt_hst></hosting>'    .
'<!-- create_domain --><tmpl_id>1</tmpl_id></add_use_template>';

$create_domain = API::PleskExpand::Domains::create( %new_domain_data, attach_to_template  => 1 );

is_string( $create_domain, $_, 'modify account test') for
'<add_use_template><gen_setup><name>y2a1ddsdfandex.ru</name>' .
'<client_id>16</client_id><status>0</status></gen_setup>'     .
'<hosting><vrt_hst><ftp_login>nrddgddsdasd</ftp_login>'       .
'<ftp_password>dadsdasd</ftp_password></vrt_hst></hosting>'   .
'<!-- create_domain --><tmpl_id>1</tmpl_id>'                  .
'<attach_to_template></attach_to_template></add_use_template>';

$expand_client->{dump_headers} = 1; # debugg =)

is_deeply(
    $expand_client->_execute_query('<add_use_template><!-- create_domain --></add_use_template>'),
    {
        ':HTTP_AUTH_LOGIN'  => $TestData::online_expand_valid_params{'username'},
        ':HTTP_AUTH_PASSWD' => $TestData::online_expand_valid_params{'password'},
        ':HTTP_AUTH_OP'     => 'exp_plesk_domain'
    },
    'test request headers'
);

is_deeply(
    $expand_client->_execute_query('<add_use_template><!-- create_client --></add_use_template>'),
    {
        ':HTTP_AUTH_LOGIN'  => $TestData::online_expand_valid_params{'username'},
        ':HTTP_AUTH_PASSWD' => $TestData::online_expand_valid_params{'password'},
        ':HTTP_AUTH_OP'     => 'exp_plesk_client'
    },
    'exp_plesk_client'
);

$expand_client->{dump_headers} = 0;


my $req_answer1 = {
    errtext     => "[Operator] Client already exists. Plesk client 'hello_medved' is exist.",
    server_id   => 1,
    status      => 'error',
    tmpl_id     => 1,
    expiration  => -1,
    errcode     => 4203,
};

is_deeply(
    API::PleskExpand::Accounts::create_response_parse( $_ ),
    $req_answer1,
    'create with error parser'
) for
'<?xml version="1.0" encoding="UTF-8" standalone="no" ?>'           .
'<packet version="2.2.4.1"><add_use_template><result>'              .
'<status>error</status><errcode>4203</errcode><errtext>'            .
"[Operator] Client already exists. Plesk client 'hello_medved' "    .
'is exist.</errtext><server_id>1</server_id><tmpl_id>1</tmpl_id>'   .
'<expiration>-1</expiration></result></add_use_template></packet>';


is_deeply(
    API::PleskExpand::Accounts::create_response_parse( $_ ), 
    {
        'server_id'  => '1',
        'status'     => 'ok',
        'expiration' => '-1',
        'tmpl_id'    => '1',
        'id'         => '29'
    },
    'parse success create xml response '
) for '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>'    .
'<packet version="2.2.4.1"><add_use_template><result><status>ok'   .
'</status><id>29</id><server_id>1</server_id><tmpl_id>1</tmpl_id>' .
'<expiration>-1</expiration></result></add_use_template></packet>' ;



( run in 0.595 second using v1.01-cache-2.11-cpan-e1769b4cff6 )