MeioUpload icon indicating copy to clipboard operation
MeioUpload copied to clipboard

example on how to run testcases on models that actAs MeioUpload

Open simkimsia opened this issue 15 years ago • 7 comments

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);

simkimsia avatar May 01 '10 09:05 simkimsia

You will need to define what your Product->createProductDetails() method does, or we cannot help you.

josegonzalez avatar May 01 '10 13:05 josegonzalez

createProductDetails is just a wrapper for saveAll($data, array('validate'=>'first'));

simkimsia avatar May 01 '10 14:05 simkimsia

then why are you not just calling that instead?

josegonzalez avatar May 01 '10 16:05 josegonzalez

Your ProductImage model are using MeioUpload as behavior? You are using master or 3.0 version?

jrbasso avatar May 01 '10 23:05 jrbasso

i am using master

simkimsia avatar May 02 '10 09:05 simkimsia

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.

simkimsia avatar May 16 '10 04:05 simkimsia

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.

jrbasso avatar May 17 '10 00:05 jrbasso