example on how to run testcases on models that actAs MeioUpload
Hi,
i have a Product that hasMany ProductImage which actsAs MeioUpload.
i run the below test case, but apprently i cannot create the image record in my database.
please advise how to overcome this situation.
code also found in http://bin.cakephp.org/saved/58605
$data = array(); $data['Product']['title'] = 'ally'; $data['Product']['description'] = 'ally'; $data['Product']['shop_id'] = '1'; $data['Product']['status'] = true; $data['Product']['price'] = 1001; $data['Product']['code'] = '0001'; $data['ProductImage']['0']['filename'] = array( 'name' => 'test_product_model.jpg', 'type' => 'image/jpeg', 'tmp_name' => realpath(WWW_ROOT.DS.'img'.DS.'test_product_model.jpg'), 'error' => 0, 'size' => 107266, );
$this->Product->saveAll($data, array('validate'=>'first'));
$result = $this->Product->find('first', array(
'conditions' => array('Product.title' => 'ally',
'Product.description' => 'ally',
'Product.shop_id' => 1,
'Product.status' => true,
'Product.price' => 1001,
'Product.code' => '0001',),
'contain' => array('ProductImage')
)
);
$this->assertTrue(!empty($result));
debug($result);
$this->assertEqual(count($result['ProductImage']), 1);
You will need to define what your Product->createProductDetails() method does, or we cannot help you.
createProductDetails is just a wrapper for saveAll($data, array('validate'=>'first'));
then why are you not just calling that instead?
Your ProductImage model are using MeioUpload as behavior? You are using master or 3.0 version?
i am using master
okie i have changed this code to using saveAll. Please let me know if there is any error in the way i test my models. Thank you.
By security questions, the code test if the file is uploaded (using is_uploaded_file ). You can't test using simple test case, you need create a web test case. In 3.0 branch you can see some exemples.