#!/usr/bin/perl use strict; use warnings; use Carp; use Test::More; use Data::Dumper; use lib 't'; use TestData; BEGIN { plan tests => 25; } BEGIN { use_ok( 'API::Plesk::Accounts' ); } ## ## API::Plesk::Accounts ## my $test_user_data = $TestData::test_user_data; ok( ! API::Plesk::Methods::xml_extract_values( ), 'blank query to xml_extract_values' ); ## client_add_gen_info_check ok( API::Plesk::Accounts::client_add_gen_info_check( %$test_user_data ), 'check valid add gen_info by client_add_gen_info_check' ); ok( ! API::Plesk::Accounts::client_add_gen_info_check( %$test_user_data, passwd => '11' ), 'check invalid (short pass) add gen_info by client_add_gen_info_check ' ); ok( ! API::Plesk::Accounts::client_add_gen_info_check( login => 'nrg_nnn' ), 'check invalid (not all flds) gen_info by client_add_gen_info_check ' ); # create test ok( ! API::Plesk::Accounts::create( ), 'create account without params' ); is_deeply( API::Plesk::Accounts::create( 'general_info' => $test_user_data, 'template-name' => 'tarif' ), "$test_user_data->{passwd}" . "$test_user_data->{email}". "$test_user_data->{country}" . "pavel$test_user_data->{phone}" . "$test_user_data->{login}" . "tarif", 'create account without params' ); # delete test is_deeply( API::Plesk::Accounts::delete( all => 1 ), '', 'generation XML for delete all' ); is_deeply( API::Plesk::Accounts::delete( id => 152 ), '152', 'generation XML for delete by id' ); is_deeply( API::Plesk::Accounts::delete( login => 'nrg' ), 'nrg', 'generation XML for delete by login' ); ok( ! API::Plesk::Accounts::delete, 'generation XML for delete by login (blank args)' ); # modify test ok( ! API::Plesk::Accounts::modify( ), 'generation XML for get all' ); ok( ! API::Plesk::Accounts::modify( login => 'nrg' ), 'generation XML (without new data block) for get all' ); is_deeply( API::Plesk::Accounts::modify( all => 1, new_data => { phone => '55555' } ), '55555' . '', 'generation XML for modify all' ); is_deeply( API::Plesk::Accounts::modify( id => 12345, new_data => {phone => '55555'} ), '12345' . '55555' . '', 'generation XML for modify elem by id' ); is_deeply( API::Plesk::Accounts::modify( login => 'nrg_pavel', new_data => {phone => '55555'} ), 'nrg_pavel' . '55555' . '', 'generation XML for modify elem by login' ); # get test is_deeply( API::Plesk::Accounts::get( all => 1 ), '', 'generation XML for get all' ); is_deeply( API::Plesk::Accounts::get( login => 'nrg' ), 'nrg' . '', 'generation XML for get by login' ); # abstract_parser tests ok( ! API::Plesk::Accounts::abstract_parser(), 'blank request to abstract_parser' ); is_deeply( API::Plesk::Accounts::abstract_parser( 'aaa', 'fsf' . '', ['status'] ), { status => 'fsf' }, 'one result block, abstract_parser' ); is_deeply( API::Plesk::Accounts::abstract_parser( 'aaa', 'error' . 'ok' . '', ['status'] ), [ { status => 'error' }, { status => 'ok' } ], 'multiple result block, abstract_parser' ); ok( ! API::Plesk::Accounts::abstract_parser( 'aaa', 'error'. '' . 'ok', [ 'another_status' ] ), 'error in input data to abstract_parser' ); # get_response_parse ok( ! API::Plesk::Accounts::get_response_parse( ), 'call get_response_parse without args' ); is_deeply( API::Plesk::Accounts::get_response_parse(< ok nrg DOC { status => 'ok', data => { login => 'nrg' } }, 'call get_response_parse with one rsult block' ); is_deeply( API::Plesk::Accounts::get_response_parse(< ok nrg ok user DOC [ { status => 'ok', data => { login => 'nrg' } }, { status => 'ok', data => { login => 'user'} } ], 'call get_response_parse with multiple result blocks' );