I'm testing my validations and I send wrong values in all my input :
$crawler = $this->client->getCrawler();
$form = $crawler->selectButton('Créer')->form();
$form->setValues([
'Contractor[lastName]' => str_repeat('maxLength', self::OVER_MAX_LENGTH,),
'Contractor[firstName]' => str_repeat('maxLength', self::OVER_MAX_LENGTH,),
'Contractor[email]' => str_repeat('maxLength', self::OVER_MAX_LENGTH,).'#society.com',
'Contractor[phone]' => str_repeat('0', self::UNDER_MIN_LENGTH,),
'Contractor[password][password][first]' => 'first',
'Contractor[password][password][second]' => 'second',
'Contractor[status]' => 'admin.crud.user.field.choices.boss'
]);
$this->client->submitForm('Créer');
$this->client->waitFor('.invalid-feedback');
$this->client->waitForVisibility('.invalid-feedback');
$this->client->takeScreenshot('add.png');
$totalErrors = $crawler->filter('div.invalid-feedback')->count();
$errorExpected = 5;
$this->assertNotCount($totalErrors, [$errorExpected]);
When I test I ask to wait until the errors are displayed. Then I count the number of errors and I compare. The problem is when this line is test $totalErrors = $crawler->filter('div.invalid-feedback')->count(); I've got an error which say :
Facebook\WebDriver\Exception\StaleElementReferenceException: stale element reference: element is not attached to the page document.
In the screenshot, the errors are displayed.
I really don't understand why because I asked to wait for the element to be in the DOM and I had no errors.
Any idea ?
It's possible that the Crawler instance you have has a "stale" HTML in its state. I don't know the exact internals, but what helped me with a similar case was to get a fresh crawler from the Client object:
// some actions that redraws the Client HTML
$crawler = $client->getCrawler();
$totalErrors = $crawler->filter('div.invalid-feedback')->count();
Related
I am trying to create a report so I can import products in bulk. The issue i am facing right now is that whatever I have done always got Invalid input error. It seems very very ambiguous error message I have checked issue here and similar once but unfortunately no solution worked.
So if you check below received error from sp-api
{
"notifications": [],
"text": "{\"message\":\"[400] [{\\\"code\\\":\\\"InvalidInput\\\",\\\"message\\\":\\\"Could not match input arguments\\\"}]\",\"success\":false}"
}
you will notice that it seems there is a mistake with my code regarding datatype(as I understood from error) But I have made sure many times of datatype, even I have wrote data as string[] but honestly it took too much time. Please find my code
$config = new Configuration([
"lwaClientId" => $account_data['lwa_client_id'],
"lwaClientSecret" => $account_data['lwa_client_secret'],
"lwaRefreshToken" => $account_data['lwa_refresh_token'],
"awsAccessKeyId" => $account_data['aws_access_key'],
"awsSecretAccessKey" => $account_data['aws_secret_key'],
"endpoint" => SellingPartnerApi\Endpoint::NA ,
]);
$apiInstance = new SellingPartnerApi\Api\ReportsApi($config);
$body = new SellingPartnerApi\Model\Reports\CreateReportSpecification([
'marketplace_ids' => [$merchant_data['marketplace_ids']],
'report_type' => ReportType::GET_MERCHANT_LISTINGS_ALL_DATA['name'],
]);
try{
$report_id = $apiInstance->createReport($body);
}catch(Exception $e){
return array("message"=>$e->getMessage(),'success'=>false);
}
Btw, I am using this lib https://github.com/jlevers/selling-partner-api
Please note that 3 of CreateReportSpecification parameter are optional (report_options, data_start_time, data_end_time) I didn't passed it at constructor.
Could you please advise what's went wrong with my code? Why I am receiving Invalid Input ??
Thanks in advance
Check that AWS_ENV=PRODUCTION (not SANDBOX)
I'm using hostfact https://www.hostfact.nl for our billing. Now I want to extend the code and get a loop on executing the internalAPI in hooks.php. I tried to find an answer in the documentation https://www.hostfact.nl/developer/api/ but without success.
// When a client is edited, the bankParameters are checked and validated.
// That is only an example
function action_debtor_is_edited($parameters){
$params = array(
'DebtorCode' => $parameters['DebtorCode']
);
$hostfactResult = internalAPI('debtor', 'show', $params);
$bankParams = array(
'Identifier' => '2',
'AccountNumber' => 'AT6734080000000000',
'AccountBank' => 'test bank',
'AccountCity' => 'city',
'AccountBIC' => 'RLNODASD'
);
$bankResult = internalAPI('debtor', 'edit', $bankParams);
}
I've already asked the support and got follwoing answer:
One of the option is keeping track of the situation. For example, use
a static or global variable. When you call an (internal)API call from
a webhook, first flag that variable, so in the newly called webhook
you know that is not needed to execute the webhook again (at least not
the part which causes the loop). In the original call, after receiving
the result, the flag can be unset again.
My Problem is, I'm new to PHP and don't understand what I should do to avoid the loop. The $bankParams variable is intentionally hardcoded.
Can you help?
I have setup a Google Actions conversational project, with dialogflow and webhook intents served by my server in PHP.
Upon new dialogflow conversation startup, e.g. just before replying to the welcome intent, the php code is pushing some session entities to the dialogflow engine.
The dialogflow engine recognized correctly the session entity words until two weeks ago, when it suddendly stopped working (I have changed nothing in the code), and right now it's still not working.
The session entities are created with no errors (I added code to query dialogflow api and list session entitites after creation, and google is replying with all the words I send).
However the Intent does not recognize and does not fill in the entity parameters.
Here is the code I'm using to push the entities (using google dialogflow v2 library):
$names = [....array of strings....];
$parent = 'projects/inim-prova/agent/sessions/' . $sessionId;
$client = new SessionEntityTypesClient(['credentials' => $keyfile]]);
$entities = array_map(function($item) { return new Entity(['value' => $item, 'synonyms' => [$item]]); }, array_unique($names));
$entityType = new SessionEntityType([
'name' => $parent . "/entityTypes/$displayName",
'entity_override_mode' => EntityOverrideMode::ENTITY_OVERRIDE_MODE_SUPPLEMENT,
'entities' => $entities
]);
$client->createSessionEntityType($parent, $entityType);
this code runs with no exception thrown.
After a few lines I'm querying the server to see if everything is ok:
$req = $client->listSessionEntityTypes($this->webhookRequest->getSession());
foreach ($req as $element) {
Logger::log(Logger::DEV, __METHOD__, "SessionEntityType: " . $element->getName());
$entities = $element->getEntities();
foreach ($entities as $entity) {
$synonyms = [];
foreach ($entity->getSynonyms() as $synonym) $synonyms[] = $synonym;
Logger::log(Logger::DEV, __METHOD__, ">> " . $entity->getValue() . ": " . implode(', ', $synonyms));
}
}
and this is an extract from the debug log:
SessionEntityType: projects/inim-prova/agent/sessions/ABwppHHhgwxi5OGznpUtUq2D7BQrOKWB5Y5UYr20HRKI14iASKugPw2dL2VKMwfvZ193Mq_DUb2emQ/entityTypes/NomiLuoghiUscite
>> sala: sala
>> cucina: cucina
>> giardino: giardino
SessionEntityType: projects/inim-prova/agent/sessions/ABwppHHhgwxi5OGznpUtUq2D7BQrOKWB5Y5UYr20HRKI14iASKugPw2dL2VKMwfvZ193Mq_DUb2emQ/entityTypes/NomiUscite
>> luci: luci
>> irrigazione: irrigazione
>> cappa: cappa
therefore all the entities seem to be in the right place.
This is the intent training phrase:
(please note that ArticoliDeterminativi and Preposizioni are static entities which I'm ignoring).
and these are the parameters I get on webhook request when I say Accendi le luci in cucina:
'parameters' => array (
'NomiUscite.original' => '',
'Preposizioni.original' => '',
'NomiLuoghiUscite' => '',
'NomiUscite' => '',
'Preposizioni' => '',
'ArticoliDeterminativi.original' => 'le',
'NomiLuoghiUscite.original' => '',
'ArticoliDeterminativi' => 'il',
)
As you can see, NomiUscite and NomiLuoghiUscite are empty. I expect them to be luci and cucina.
I'm really clueless.
It looks like it really was a dialogflow bug, not a flaw in my code.
After a couple of week, Support guys from Google replied me telling that the issue has been resolved.
I've run again tests with no modification on code at all, and now it works.
You should add words 'uscita' and 'luogo' to the Session Entities. I can how the parameters can be empty if you annotate words that are not part of the entity.
You also can try adding 'Accendi le luci in cucina' as a Training Phrase.
Given that I have a WHMCS addon that I call 'my_addon'. I created the main addon file 'my_addon.php' which does contain nothing than:
<?php
function my_addon_clientarea($vars) {
$client = null;
return array(
'pagetitle' => 'My Addon',
'breadcrumb' => array('index.php?m=my_addon'=>'My Addon'),
'templatefile' => 'views/myaddon_view',
'vars' => array(
'client' => $client
)
);
}
This does basically work. It does give me my template file, everything is passed through. My question is: How do I get the currently logged in client from within that function?
I didn't find any API method and I can't see any constant which does hold this information.
There must be a way to get the current client within the clientarea? Thanks for your help!
For those who do come after me and have the same problem: it's easy to solve. Turned out, that I just had to think it through... I found the client id to be available in the $_SESSION-variable.
So, if you are looking for the client's id:
<?php
function my_addon_clientarea($vars) {
$clientid = $_SESSION['uid'];
// And so on...
}
The official way to get current user information is:
$currentUser = new \WHMCS\Authentication\CurrentUser;
$user = $currentUser->user();
You can find more information here
I've got some problem with symfony form value (i guess it's the clean value, but not so clear yet). Here's the problem :
I got a sfFormDateJQueryUI widget setup like this in my form :
$this->setWidgets(array(
'needDate' => new sfWidgetFormDateJQueryUI(),
));
$this->setValidators(array(
'needDate' => new sfValidatorDate(array(
'required' => true,
'date_format' => '/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/',
'date_output' => 'd/m/Y'
)),
));
Then when i submit, say 26/06/2010, it turns out right in the HTTP Header (viewed via Firebug) and $request (i just print it). But after i get the value via
$formVal = $form->getValues();
the date value in $formVal["needDate"] become today's date (03/06/2010). I really don't understand, and after checking in the API documentation it says that the getValues will return the 'cleaned' value. Is that because of it ? I don't understand what's 'clean'.
Thanks before..
Somehow I solved the problem.
It turns out that the value can't validate, so when I changed the validator to:
'needDate' => new sfValidatorRegex(array(
'pattern' => '/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/'
))
everything works fine.