$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); }
function TestGenerationOfAnJsUnitTest() { $test = GenerateAJsUnitTest("1", "0", "11", "Bold", "Hello World", "<strong>Hello World</strong>"); $this->assertEqual($test, "function 1_TestScenariosGenerate(){ \r\n\t\tSetContentToEditor('Hello World'); \r\n\t\tSetFocus(22,3); \r\n\t\tExecuteCommand(Bold); \r\n\t\tthis->assertEqual('<strong>Hello World</strong>',GetContentFromEditor()) ;\r\n\t}\r\n\t"); }