function test_ParcelPoint() { $result = default_value(); $start = microtime_float(); /* Initialisation */ $env = new ParcelPoint(); $env->getParcelPoint("dropoff_point", "MONR-003921"); $env->getParcelPoint("dropoff_point", "SOGP-C1160"); $env->getParcelPoint("pickup_point", "MONR-018481"); $env->getParcelPoint("pickup_point", "SOGP-C3210"); /* Reception test */ if ($env->curl_error) { $result['reception'] = max($result['reception'], ERROR); $result['reception_info'][count($result['reception_info'])] = 'Error while sending the query'; } elseif ($env->resp_error) { $result['reception'] = max($result['reception'], ERROR); $result['reception_info'][count($result['reception_info'])] = 'Invalid query : ' . $userData["api_key"]; foreach ($env->resp_errors_list as $message) { $result['reception_info'][count($result['reception_info'])] = $message['message']; } } else { $result['reception'] = max($result['reception'], OK); $result['reception_info'][count($result['reception_info'])] = 'Reception time : ' . (microtime_float() - $start) . 's'; } /* Additionals test */ /* Test for the result structure */ $result['additionals'][0]['name'] = 'Structure'; $result['additionals'][0]['state'] = OK; if (count($env->points) != 2) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$points should contains 2 elements, contains ' . count($env->points) . ' instead'; } else { foreach ($env->points as $type => $points) { if (count($env->points[$type]) == 0) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$points["' . $type . '"] array is empty'; } else { foreach ($points as $point) { if (!isset($point['code'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"code" not defined in $points["' . $type . '"] array'; } if (!isset($point['name'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"name" not defined in $points["' . $type . '"] array'; } if (!isset($point['address'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"address" not defined in $points["' . $type . '"] array'; } if (!isset($point['city'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"city" not defined in $points["' . $type . '"] array'; } if (!isset($point['zipcode'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"zipcode" not defined in $points["' . $type . '"] array'; } if (!isset($point['country'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"country" not defined in $points["' . $type . '"] array'; } if (!isset($point['description'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"description" not defined in $points["' . $type . '"] array'; } if (!isset($point['schedule'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"days" not defined in $points["' . $type . '"] array'; } elseif (count($point['schedule']) != 7) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"days" should contains 7 days info, but contains ' . count($env->points[$type]['schedule']) . ' instead'; } if (isset($point['schedule'])) { foreach ($point['schedule'] as $j => $day) { if (!isset($point['schedule'][$j]['weekday'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"weekday" not defined in $points["' . $type . '"]["days"][' . $j . '] array'; } if (!isset($point['schedule'][$j]['open_am'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"open_am" not defined in $points["' . $type . '"]["days"][' . $j . '] array'; } if (!isset($point['schedule'][$j]['close_am'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"close_am" not defined in $points["' . $type . '"]["days"][' . $j . '] array'; } if (!isset($point['schedule'][$j]['open_pm'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"open_pm" not defined in $points["' . $type . '"]["days"][' . $j . '] array'; } if (!isset($point['schedule'][$j]['close_pm'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"close_pm" not defined in $points["' . $type . '"]["days"][' . $j . '] array'; } } } } } } } $result['duration'] = microtime_float() - $start; return $result; }
<?php use Emc\ParcelPoint; /* Example of use for EnvParcelPoint class * Load parcel point informations from their codes */ require_once '../config/autoload.php'; require_once EMC_PARENT_DIR . 'layout/header.php'; // Prepare and execute the request $lib = new ParcelPoint(); // load multiple parcel points // if you plan to load multiple parcel points around the same address, get_list_parcel_points.php is a better solution $lib->getParcelPoint("dropoff_point", "MONR-003921"); $lib->getParcelPoint("dropoff_point", "SOGP-C1160"); $lib->getParcelPoint("pickup_point", "MONR-018481"); $lib->getParcelPoint("pickup_point", "SOGP-C3210"); $lib->getParcelPoint("pickup_point", "SOGP-C3059"); $lib->getParcelPoint("pickup_point", "SOGP-C1250"); // Display loaded parcel points if (!$lib->curl_error && !$lib->resp_error) { $week_days = array(1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday'); ?> <h3>API ParcelPoint</h3> <div class="row"> <ul class="list-group"> <li class="list-group-item active"><b>Pickup points :</b></li> <?php foreach ($lib->points['pickup_point'] as $point) { ?> <li class="list-group-item"> <div class="row">