Error test upload php unit symfony2 - forms

Im following the tutorial from symfony's website to make my phpunit's test for my controller.
Im trying to test an upload on a form and i have 3 fields on this form : title,description and file.
I use :
public function testScenarioAdd() {
$client = static::createClient();
$x_wsse = 'UsernameToken Username="username#fai.fr", PasswordDigest="aeirugbjcUbfmùJK", Nonce="OTMzOGMwYzFkYTk2MzJmYzBh", Created="2013-11-12T10:22:15+01:00"';
//X_Wsse is for the connection systeme on my application.
$image = new UploadedFile(
'/past/to/your/images.jpg',
'images.jpg',
'image/jpeg',
100000
);
$crawler = $client->request('POST', '/ad/create', array('ad_form' => array('title' => 'test', 'description' => 'Test description')),array(), array('CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'HTTP_X-WSSE' => $x_wsse));
$response = $client->getResponse()->getContent();
$json_response = json_decode($response);
print_r($response);
}
When i launch it I have an error saying :
{"app_error":{"success":500,"result":[{"message":"Array to string conversion",...
Am i doing something wrong ? or missing something in my code ?
Thanks for your help :)
Edit :
Thanks but, what ive done there is working on another test without upload, i still tried it and its not working. I still have the error array to string... I think it come from the fonction UplaodedFile or maybe from my controller itself because when i try the other solution from symfony's web site with
$photo = array(
'tmp_name' => '/path/to/photo.jpg',
'name' => 'photo.jpg',
'type' => 'image/jpeg',
'size' => 123,
'error' => UPLOAD_ERR_OK
);
With putting the
$crawler = $client->request('POST', '/ad/create', array('ad_form[title]' => 'test', ad_form[description] => 'test description'),array('file' => $image),array('CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'HTTP_X-WSSE' => $x_wsse));
The important part of my controller is :
if ('POST' === $request->getMethod()) {
$form->bind($request);
if ($form->isValid())
{
$Ad->preCreate();
$odm->persist($Ad);
$odm->flush();
$odm->clear();
$data = $this->listAction($request, 1, 5);
Tags::setEvent($request, $this->container, 'member.create.ad', $user->getId(), $Ad->getId());
return $data;
} else {
$data = Errors::formatJson($form, $this->container);
}
}
}
return new JsonResponse(array('ad_create' => $data));
Im kinda new in symfony, i really dont know where this error can come from...

Client::Request method expects you to provide it with one-dimensional array of data. So try this code:
<?php
//...
$crawler = $client->request('POST', '/ad/create',
array('ad_form[title]' => 'test',
'ad_form[description]' => 'Test description'),
array(),
array('CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'HTTP_X-WSSE' => $x_wsse));

Related

Unable to get getConfigurationAndPricing in PromoStandard

I am trying to getting Product getConfigurationAndPricing using Promostandard Soap API but for some reason I am unable to get those information. Here is my code snapit
$productId = 'TM17907'
$client = new \SoapClient("https://pspriceconfig100.pcna.online/psPriceConfig.svc?singleWsdl", array('trace' => 1));
$options = array(
'wsVersion' => '1.0.0',
'id' => $apiUsername,
'password' => $apiPassword,
'productId' => $productId,
'currency' => 'USD',
'fobId' => '1',
'priceType' => 'List',
'localizationCountry'=>'US',
'localizationLanguage' => 'en',
'configurationType' => 'Decorated',
'cache_wsdl' => WSDL_CACHE_MEMORY
);
try{
$result = $client->__soapCall('getConfigurationAndPricing',[$options]);
} catch (\Exception $e){
$output->writeln("<error>HTTP issue generate in product ID : ".$productId.", Row No.".$currentRow."</error>");
continue;
}
I am using to get PCNA products.

First/Last record is not coming with data in cakephp+mongo

I m using the mongodb plugin
ichikaway/cakephp-mongodb
And cakephp 2.6.1
The data in post collection
link to image
And in cakephp it is showing me like
link to image
Cakephp controller side code:
$params = array(
'fields' => array('title', 'body', 'hoge'),
//'fields' => array('Post.title', ),
//'conditions' => array('title' => 'hehe'),
//'conditions' => array('hoge' => array('$gt' => '10', '$lt' => '34')),
//'order' => array('title' => 1, 'body' => 1),
'order' => array('_id' => "DESC"),
'limit' => 35,
'page' => 1,
);
$results = $this->Post->find('all', $params);
I want to pull each and every data from mongodb but this plugin is not providing me the last data.
I have checked the count that's correct.
Am I correct in assuming that this error only appeared after upgrading the PHP driver to 1.6.0? The CakePHP module uses hasNext() and getNext() in MongodbSource::read(), which will be affected by a bug (PHP-1382) introduced in 1.6.0. A fix has already been merged and should be released as 1.6.1 on 2015-02-05 (tomorrow).
For additional context, see a previous answer on the subject: https://stackoverflow.com/a/28304142/162228
In MongodbSource.php file I have made just simple change
in read function
There was a code
public function read(Model $Model, $query = array(), $recursive = null) {
........
while ($return->hasNext()) {
$mongodata = $return->getNext();
Changed it to
public function read(Model $Model, $query = array(), $recursive = null) {
........
foreach ($return as $data) {
$mongodata = $data;
And yurekaaaa,its working fine.

Drupal custom form and autocomplete issue

Some how I managed to get it work. But still the result is not coming along with the autocomplete.
Posting my latest code now,
the textfield code
$form['town'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#autocomplete_path' => 'hfind/town/autocomplete',
);
menu function code
function hfind_menu() {
$items = array();
$items['hfind/town/autocomplete'] = array (
'title' => 'Autocomplete for cities',
'page callback' => 'hfind_town_autocomplete',
'access arguments' => array('use autocomplete'),
'type' => MENU_CALLBACK
);
return $items;
}
the callback function code
function hfind_town_autocomplete($string){
$matches = array();
$result = db_select('towns', 't')
->fields('t', array('town_name'))
->condition('town_name', '%' . db_like($string) . '%', 'LIKE')
->execute();
foreach ($result as $row) {
$matches[$row->city] = check_plain($row->city);
}
drupal_json_output($matches);
}
I hope this may the final edit.
The current situation is, autocomplete is working
The url is hfind/town/autocomplete/mtw
but it is not able to find any data from the database. I found why and unable to fix it.
It is because in the last function I've added above the $string needs to be the 'search query' but it is always querying the database as 'autocomplete'. I mean the $string variable always having the value 'autocomplete' instead of user typed value.
One more problem is, even after providing the permission to all types of user to access search autocomplete on the forms, guests users are not able to use the feature.
Please please someone help me..
`drupal_json_output()` instead of `drupal_to_js` and remove `print` .
<code>
hook_menu() {
$items['cnetusers/autocomplete'] = array(
'title' => 'Auto complete path',
'page callback' => 'cnetusers_employees_autocomplete',
'page arguments' => array(2, 3, 4, 5),
'access arguments' => array('access user profiles'),
'type' => MENU_CALLBACK,
);
return $item;
}
// my autocomplete function is like this
function cnetusers_employees_autocomplete() {
// write your sql query
$matches["$record->ename $record->elname [id: $record->uid]"] = $value;
}
if (empty($matches)) {
$matches[''] = t('No matching records found.');
}
drupal_json_output($matches);
}
$form['disc_info']['approval'] = array(
'#type' => 'textfield',
'#title' => t('Approval By'),
'#autocomplete_path' => 'cnetusers/autocomplete',
);
</code>

SugarCRM soap call not linking contact to a target list

I'm using SugarCRM 6.4.4 and php 5.3.10 and trying to add a contact to a target list using a soap call...I've also tried using the ProspectList class directly but I can't get it to work. I know the SOAP calls are getting through because I can create the Contact just fine, but the problem is coming when I try to create the relationship between the Contact and the Target List (PropsectList). What am I doing wrong?
Here's the SOAP call I tried. I'm getting an error that says: "Call to a member function add() on a non-object in /data/servers/thesite.com/web/administrator/sales/soap/SoapSugarUsers.php on line 1350"...Here's the code around line 1350
if (!empty($key)) {
$mod->load_relationship($key);
$mod->$key->add($module2_id);
return $error->get_soap_array();
}
Here's the full code for the SOAP:
// set up options array
$options = array(
"location" => 'http://www.thesite.com/sales/soap.php',
"uri" => 'http://www.sugarcrm.com/sugarcrm',
"trace" => 1
);
//user authentication array
$user_auth = array(
"user_name" => 'theuser',
"password" => MD5('thepass'),
"version" => '.01'
);
// connect to soap server
$client = new SoapClient(NULL, $options);
// Login to SugarCRM
$response = $client->login($user_auth,'test');
$session_id = $response->id;
$user_id = $client->get_user_id($session_id);
//Add Contact to SugarCRM
$response = $client->set_entry($session_id, 'Contacts', array(
array('name' => 'first_name','value' => 'roneFirst2'),
array('name' => 'last_name','value' => 'roneLast2'),
array('name' => 'account_name','value' => 'jdam Props'),
array('name' => 'email1','value' => 'roneEmail2#gmail.com'),
array('name' => 'work_phone','value' => '1.888.888.8888'),
array('name' => 'description','value' => 'This is the message'),
array('name' => 'assigned_user_id','value' => $user_id)
));
$contact_id = $response->id;
//Add Contact to TARGET LIST
$relationship = array(
'module1' => 'Contacts',
'module1_id' => "$contact_id",
'module2' => 'ProspectLists',
'module2_id' => "24053784-f8d3-22a4-5e99-4fc6a7d5159f" //Note: this id was pulled from the table in the database directly for the target list we want to link the contact with.
);
//call set_relationship()
$response = $client->set_relationship($session_id, $relationship);
been googleing and trying to figure this out for 3 days now...Thanks for any help you are willing to give.

How to create sub category on Magento APi

I am currently using Magento ver. 1.5.0.1. Can anyone tell me how do i create a sub category using soapv2.
Here my code format
category_data = { "name" => "LIGHTING", "is_active" => 1 }
soap.call('catalogCategoryCreate',session,4,category_data,1, "include_in_menu")
I got some errors when i run this code.
: Attribute "include_in_menu" is required. (SOAP::FaultError)
Is that any solution for this problem.
Thanks.
category_data = { "name" => "LIGHTING", "is_active" => 1, "include_in_menu" => 1 }
This is how you can create category using SOAP V2
<?php
$host = "192.168.0.10/~aliasgar/magentoext/index.php"; //our online shop url
$client = new SoapClient("http://".$host."/api/v2_soap/?wsdl"); //soap handle
$apiuser= "aliasgar"; //webservice user login
$apikey = "aliasgar"; //webservice user pass
try {
$sess_id= $client->login($apiuser, $apikey); //we do login
$result = $client->catalogCategoryCreate($sess_id, 3, array(
'name' => 'Test Category',
'is_active' => 1,
'available_sort_by' => array('position'),
'default_sort_by' => 'position',
'include_in_menu' => '1',
));
var_dump ($result);
}
catch (Exception $e) { //while an error has occured
echo "==> Error: ".$e->getMessage(); //we print this
exit();
}
?>
Here 3 in the catalogCategoryCreate function is the parent category id.