Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example on how to run testcases on models that actAs MeioUpload #44

Open
simkimsia opened this issue May 1, 2010 · 7 comments
Open

Comments

@simkimsia
Copy link
Contributor

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);
@josegonzalez
Copy link
Contributor

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

@simkimsia
Copy link
Contributor Author

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

@josegonzalez
Copy link
Contributor

then why are you not just calling that instead?

@jrbasso
Copy link
Owner

jrbasso commented May 1, 2010

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

@simkimsia
Copy link
Contributor Author

i am using master

@simkimsia
Copy link
Contributor Author

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.

@jrbasso
Copy link
Owner

jrbasso commented May 17, 2010

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants