コード例 #1
0
    $NewString = AdATagOnAString($Tag, $SelectedText);
    $WaitedText = str_replace($SelectedText, $NewString, $InputText);
    return $WaitedText;
}
function GenerateAJsUnitTest($order, $StartChar, $SelectionSize, $Action, $InputText, $OuputText)
{
    $test = "function testScenariosGenerate_" . $order . "(){ \n \t SetContentToEditor(\"" . $InputText . "\n); \n \t setselectedtext(" . $StartChar . "," . $EndChar . "); \n \t ExecuteCommand(" . $Action . "); \n \t this->assertEqual(\"" . $OuputText . "\",GetContentFromEditor()) ;\n } \n";
    return $test;
}
@unlink(".../temp/JsUnitGeneratingTestsScenario.js");
$InputText = TakeAllDatasInAFile(INPUT_FILE);
$FirstTest = "\n function testExecutionOfScenariosGenerateByPhp(){ \n assertEquals('Hello World', 'Hello World') ;\n } \n \n";
Write_ToTheEndOfOutput_File('../temp/JsUnitGeneratingTestsScenario.js', $FirstTest);
$FileContent = file('TestScenario.csv');
$i = 0;
foreach ($FileContent as $FileLine) {
    $Line = split(";", $FileLine);
    $Scenarios[$i]['Order'] = $Line[0];
    $Scenarios[$i]['Action'] = $Line[1];
    $Scenarios[$i]['StartChar'] = $Line[2];
    $Scenarios[$i]['EndChar'] = $Line[3];
    $Scenarios[$i]['InputText'] = $Line[4];
    $Scenarios[$i]['OuputText'] = $Line[5];
    $i++;
}
foreach ($Scenarios as $Scenario) {
    $Tag = ConvertAnActionInATag($Scenario['Action']);
    $WaitedText = GenerateResult($InputText, $Scenario['StartChar'], $Scenario['SelectionSize'], $Tag);
    $UnitTest = GenerateAJsUnitTest($Scenario['Order'], $Scenario['StartChar'], $Scenario['EndChar'], $Scenario['Action'], $Scenario['InputText'], $Scenario['OuputText']);
    Write_ToTheEndOfOutput_File('../temp/JsUnitGeneratingTestsScenario.js', $UnitTest);
}
コード例 #2
0
 public function TableDefGenerator()
 {
     global $aParameter;
     require_once __DIR__ . "/../../php-includes/adodb/adodb.inc.php";
     $psModuleName = $aParameter['name'];
     $psDir = $aParameter['directory'];
     if (empty($psModuleName) or empty($psDir) or empty($aParameter['dbhostname']) or empty($aParameter['dbusername'])) {
         return GenerateResult(1, 'Uncomplete Parameter');
     }
     $psDatabase = 'mysql';
     if ($aParameter['dbtype'] == 0) {
         $psDatabase = 'mysql';
     }
     if ($aParameter['dbtype'] == 1) {
         $psDatabase = 'postgresql';
     }
     //--- koneksi database
     $pnrespon["db"] = 0;
     $db = ADONewConnection($psDatabase);
     //$db->port = 3306;
     $db->debug = false;
     $koneksi = $db->PConnect($aParameter['dbhostname'], $aParameter['dbusername'], $aParameter['dbpassword'], $aParameter['dbname']);
     //--- PROSES DISINI SMS-nya
     if (!$koneksi) {
         return GenerateResult(2, "Failed Connection Database: " . $aParameter['dbname']);
     }
     // get tables
     $lsSQL = "SHOW TABLES";
     $dq = $db->Execute($lsSQL);
     $liTableCount = $dq->RecordCount();
     while (!$dq->EOF) {
         $aNamaTabel[] = $dq->fields;
         $dq->MoveNext();
     }
     // prepare output
     $lsHasil = "<?php\n" . "// Dibuat Dengan AksiIDE - TableDef Generator\n" . "// kopirait (k) 2008, KIOSS Project, AksiIDE - http://aksiide.com\n" . "//\n";
     $lsHasil .= "" . "function {$psModuleName}" . "_tables(){\n" . "\tglobal \$Aksi;\n" . "\t\$tables = array();\n" . "\n";
     $lsResult = "";
     foreach ($aNamaTabel as $lsNamaTabel) {
         $liPos = strpos($lsNamaTabel[0], $aParameter['dbtableprefix']);
         if ($liPos === false) {
             continue;
         }
         $lsHasil .= "\n";
         $lsHasil .= "\t//-- Tabel : {$lsNamaTabel['0']}\n";
         $lsHasil .= "\t\$property = \"{$lsNamaTabel['0']}\";\n";
         $lsHasil .= "\t\$tables[ \"{$lsNamaTabel['0']}\"] = \$property;\n";
         $lsHasil .= "\t\$tables[ \"{$lsNamaTabel['0']}_column\"] = array(\n";
         $lsHasilColumnDef = "\t\$tables[ \"{$lsNamaTabel['0']}_column_def\"] = array(\n";
         $lsSQL = "SHOW COLUMNS FROM {$lsNamaTabel['0']}";
         $dq = $db->Execute($lsSQL);
         $liJmlField = $dq->RecordCount();
         while (!$dq->EOF) {
             $lsNamaField = $dq->fields[0];
             $lsFieldType = $dq->fields[1];
             $lsFieldDefault = $dq->fields[4];
             //int
             $lsFieldType = str_replace("tinyint", "I1", $lsFieldType);
             $lsFieldType = str_replace("bigint", "I8", $lsFieldType);
             if (strpos($lsFieldType, 'int') !== false) {
                 $lsFieldType = "I";
             }
             $lsFieldType = str_replace("varchar", "C", $lsFieldType);
             $lsFieldType = str_replace("longtext", "XL", $lsFieldType);
             $lsFieldType = str_replace("mediumtext", "X", $lsFieldType);
             $lsFieldType = str_replace("text", "X", $lsFieldType);
             $lsFieldType = str_replace("datetime", "T", $lsFieldType);
             $lsFieldType = str_replace("timestamp", "T", $lsFieldType);
             $lsFieldType = str_replace("time", "T", $lsFieldType);
             $lsFieldType = str_replace("year", "D", $lsFieldType);
             $lsFieldType = str_replace("date", "D", $lsFieldType);
             //$lsFieldType = str_replace("double", "N(10.2)", $lsFieldType);
             //$lsFieldType = str_replace("float", "N(10.2)", $lsFieldType);
             $lsFieldType = str_replace("double", "F", $lsFieldType);
             $lsFieldType = str_replace("float", "F", $lsFieldType);
             //
             $lsFieldNull = "";
             if ($dq->fields[2] == "NO") {
                 $lsFieldNull = "NOTNULL";
             }
             $lsFieldDefault = "";
             $lsS = trim($dq->fields[4]);
             if ($lsS == "") {
             } else {
                 $lsFieldDefault = "DEFAULT " . $dq->fields[4];
             }
             $lsFieldKey = "";
             if ($dq->fields[3] == "PRI") {
                 $lsFieldKey = "PRIMARY";
             }
             $lsFieldExtra = "";
             if ($dq->fields[5] == "auto_increment") {
                 $lsFieldExtra = "AUTO";
             }
             $lsFieldDef = "";
             $lsFieldDef .= "{$lsFieldType} {$lsFieldNull} {$lsFieldDefault} {$lsFieldExtra} {$lsFieldKey}";
             $lsFieldDef = trim($lsFieldDef);
             $lsHasil .= "\t\t\"{$lsNamaField}\" => \"{$lsNamaField}\", \n";
             $lsHasilColumnDef .= "\t\t\"{$lsNamaField}\" => \"{$lsFieldDef}\", \n";
             $dq->MoveNext();
         }
         //  $lsHasil .= "\t\t\"dummy\" => \"dummy\" \n";
         $lsHasilColumnDef .= "\t);\n";
         $lsHasil .= "\t);\n";
         $lsHasil .= $lsHasilColumnDef;
         $lsHasilColumnDef = "";
     }
     //-- foreach ( $aNamaTabel as $lsNamaTabel)
     $lsHasil .= "\n\n" . "  return \$tables;\n" . "}\n" . "\n";
     $lsHasil .= "?" . ">";
     $psTargetFile = $psDir . "/tables.php";
     $psTargetFile = str_replace("\\/", "/", $psTargetFile);
     $psTargetFile = str_replace("//", "/", $psTargetFile);
     $fp = fopen($psTargetFile, "w");
     fputs($fp, $lsHasil);
     fclose($fp);
     $lsParameter = print_r($aParameter, true);
     $laResult['err'] = 0;
     $laResult['msg'] = "Table Defs for '{$psModuleName}' generated." . "\nfile:{$psTargetFile}";
     $laResult['command'] = 'fileopen';
     $laResult['parameter'] = $psTargetFile;
     return json_encode($laResult);
 }