<?php

include dirname(__FILE__) . '/../bootstrap/Doctrine.php';
include dirname(__FILE__) . '/../../lib/test/chartSourceUtilityTest.class.php';
$ut = new chartSourceUtilityTest(new sfBrowser());
$t = new lime_test(136, new lime_output_color());
$scenarios = $ut->getBaseScenarios();
$options = array('categories' => getCategories(), 'vehicles' => getVehicles($ut->getUserId('user_gs')), 'user_id' => $ut->getUserId('user_gs'));
$params = array('full_history' => false);
//foreach ($scenarios as $key => $scenario) {
for ($index = 0; $index < 16; $index++) {
    $scenario = $scenarios[$index];
    $y = getYForScenario($ut, $scenario);
    $x = getXForScenario($ut, $scenario);
    $fname = 'buildCostPieChartData';
    $options = array_merge($options, array('vehicle_display' => $scenario[0]));
    $g = $ut->runTest($t, $scenario, $fname, $x, $y, $options, $params);
}
function getYForScenario($ut, $scenario)
{
    $case = $ut->getCase($scenario[0], $scenario[1]);
    $range = $scenario[2];
    $limit = isset($scenario[3]) ? true : false;
    // categories
    //    [0] => Fuel
    //    [1] => Initial investment
    //    [2] => Leasing
    //    [3] => Tax
    //    [4] => Accessory
    //    [5] => Insurance
    //    [6] => Fine
    $vehicles = getVehicles($sessionID);
    echo count($vehicles->Devices) . " vehicle(s) available. \n";
    $vehicleID = getVehicleID(0);
    print_r(getAvailableActions(0));
    echo "Enter Command: ";
    $handle = fopen("php://stdin", "r");
    $line = fgets($handle);
    $result = json_decode(sendCommandToVehicle($vehicleID, $sessionID, trim($line)));
    if ($result->Return->ResponseSummary->StatusCode == 0) {
        echo "Command received successfully.\n";
    } else {
        echo "Error: " . $result->Return->ResponseSummary->ErrorMessage;
    }
} else {
    $sessionID = getSessionID($smartstart_username, $smartstart_password);
    $vehicles = getVehicles($sessionID);
    $vehicleID = getVehicleID(0);
    //print_r(getAvailableActions(0));
    //print_r($vehicles);
    echo sendCommandToVehicle($vehicleID, $sessionID, $action);
}
function curlGet($url, $referer = null, $headers = null)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_1; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9");
    if (!is_null($referer)) {
        curl_setopt($ch, CURLOPT_REFERER, $referer);