public function testPrepareCodes() { $C = new Codes(); $C->format = "ABC******"; // 9 characters + ',' will be 10 chars $C->prefix = $C->setPrefix($C->format); $C->num_random_chars = strlen($C->format) - strlen($C->prefix); $C->fieldlength = 100; // sets fieldlength artifically low just for test usually 32768 $num_codes = 101; $codes = $C->generateMany($num_codes); $code_length = strlen($codes[0]); $prep = $C->prepareCodesForInsert($codes); $c = ceil($num_codes * ($code_length + 1) / $C->fieldlength); // echo "\n | first code : $codes[0] "; // echo " | num_codes : $num_codes "; // echo " | code_length : $code_length \n"; print_r($prep); // we expect the number of strings of codes to be 11 $this->assertTrue(count($prep) == $c); }
<?php require './codes.php'; // contains the DB credentials and connection require_once './Force.com-Toolkit-for-PHP/soapclient/SforceEnterpriseClient.php'; $mySforceConnection = new SforceEnterpriseClient(); $wsdl = './test.enterprise.wsdl.xml'; //$wsdl = './enterprise.wsdl.xml'; $mySforceConnection->createConnection($wsdl); $mySforceConnection->login(USERNAME, PASSWORD . SECURITY_TOKEN); $C = new Codes(); $codes = $C->generateMany($number_of_codes); $prep = $C->prepareCodesForInsert($codes); // echo 'Prefix : ' .$C->prefix .'<br />'; // echo '<pre>'; // print_r($codes); // echo '</pre>'; /************************** INSERT DATA INTO SF **************************/ $records = array(); $i = 0; foreach ($prep as $code) { $records[$i] = new stdclass(); $records[$i]->Contract_Deal_Attribute__c = $cda; $records[$i]->Voucher_Code__c = $code; $i++; } $response = $mySforceConnection->create($records, 'External_Voucher_Code__c'); print_r(json_encode($response));