function ChooseMenuOption($ch, $RootPath, $ServerPath, $TestSessionID, $IndexPage, $MenuOption) { $i = 0; do { $i++; } while ($i < sizeOf($IndexPage[1]) and $IndexPage[1][$i]['value'] != $MenuOption); if ($i >= sizeOf($IndexPage[1])) { error_log('Error finding option ' . $MenuOption . '. Link not found.' . "\n", 3, '/home/tim/weberp' . date('Ymd') . '.log'); return false; } $SelectedPage = new URLDetails($TestSessionID); $SelectedPage->SetURL($ServerPath . $IndexPage[1][$i]['href']); $SelectedPage->SetPostArray(array()); $Page = $SelectedPage->FetchPage($RootPath, $ServerPath, $ch); return $Page; }
function webERPLogIn($ch, $TestSessionID, $RootPath, $ServerPath, $Company, $UserName, $Password) { $LoginScreenDetails = new URLDetails($TestSessionID); $LoginScreenDetails->SetURL($RootPath . 'index.php'); $LoginScreenDetails->SetPostArray(array()); $LoginScreenDetails->FetchPage($RootPath, $ServerPath, $ch); $FormDetails = $LoginScreenDetails->GetFormDetails(); for ($i = 0; $i < sizeOf($FormDetails['Selects']['select']['CompanyNameField']['options']); $i++) { if ($FormDetails['Selects']['select']['CompanyNameField']['options'][$i]['label'] == $Company) { $PostArray['CompanyNameField'] = $FormDetails['Selects']['select']['CompanyNameField']['options'][$i]['label']; break; } } for ($i = 0; $i < sizeOf($FormDetails['Texts']['text']); $i++) { if ($FormDetails['Texts']['text'][$i]['name'] == 'UserNameEntryField') { $PostArray['UserNameEntryField'] = $UserName; break; } } for ($i = 0; $i < sizeOf($FormDetails['Passwords']['password']); $i++) { if ($FormDetails['Passwords']['password'][$i]['name'] == 'Password') { $PostArray['Password'] = $Password; break; } } for ($i = 0; $i < sizeOf($FormDetails['Hiddens']['hidden']); $i++) { if ($FormDetails['Hiddens']['hidden'][$i]['name'] == 'FormID') { $PostArray['FormID'] = $FormDetails['Hiddens']['hidden'][$i]['value']; break; } } for ($i = 0; $i < sizeOf($FormDetails['Submits']['submit']); $i++) { if ($FormDetails['Submits']['submit'][$i]['name'] == 'SubmitUser') { $PostArray['SubmitUser'] = '******'; break; } } $IndexScreenDetails = new URLDetails($TestSessionID); $IndexScreenDetails->SetURL($RootPath . 'index.php'); $IndexScreenDetails->SetPostArray($PostArray); $IndexPage = $IndexScreenDetails->FetchPage($RootPath, $ServerPath, $ch); return $IndexPage; }
#!/usr/bin/php5 <?php include 'includes/config.php'; include 'includes/login.php'; include 'includes/SelectModule.php'; include 'includes/SelectMenuOption.php'; include 'includes/FillForm.php'; include 'includes/validators/XhtmlValidator.php'; include 'classes/URLDetails.class.php'; include 'data/suppliers.data'; //Set up the session ID //open connection $ch = curl_init(); $TestSessionID = sha1(uniqid(mt_rand(), true)); $IndexPage = webERPLogIn($ch, $TestSessionID, $RootPath, $ServerPath, $CompanyName, $UserName, $Password); $APPage = FindModule($ch, $RootPath, $ServerPath, $TestSessionID, $IndexPage, 'Payables'); $SupplierPage = ChooseMenuOption($ch, $RootPath, $ServerPath, $TestSessionID, $APPage, 'Add Supplier'); $PostData = FillFormWithRandomData($SupplierPage[2]); $SupplierInsertPage = new URLDetails($TestSessionID); $SupplierInsertPage->SetURL($ServerPath . $SupplierPage[2]['Action']); $SupplierInsertPage->SetPostArray($PostData); $Page = $SupplierInsertPage->FetchPage($RootPath, $ServerPath, $ch); if (!strstr($Page[0], 'success')) { $InputDump = print_r($PostData, true); error_log('**Error**' . ' The supplier does not seem to have been inserted correctly using the following data:' . "\n", 3, '/home/tim/weberp' . date('Ymd') . '.log'); error_log($InputDump . "\n\n", 3, '/home/tim/weberp' . date('Ymd') . '.log'); } curl_close($ch);