Hi Matteo,
My first advice would be read this mate
http://book.cakephp.org/2.0/en/development/testing.html
it will help you.
If you are using cake 2.0, which I'm starting to think you are.. the
simplest solution for controller testing would be to use the kick ass
generate method to stub out the wrapped methods and set the return
values to true or whatever you need.
<?php
App::uses('UploadsController', 'Controller');
class UploadsControllerTestCase extends ControllerTestCase {
public function testAdd() {
$Uploads = $this->generate('Uploads', array(
'methods' => array(
'isAuthorized'
),
'models' => array(
'Upload' => array('isUploadedFile',
'MoveUploadedFile')
)
));
#override return values
$Uploads->Upload
->expects($this->any())
->method('isUploadedFile')
->will($this->returnValue(true));
$Uploads->Upload
->expects($this->any())
->method('MoveUploadedFile')
->will($this->returnValue(true));
$data = array(Your post data);
$this->testAction('/Uploads/add', array('data' => $data));
}
}
If you want to test all the uploading and resizing like Miles said,
which is a good idea! do that in your Model test. That is where you
would override 'isUploadedFile', 'MoveUploadedFile' and that should be
pretty straight forward it's all on the manual mate.
kind regards,
Leigh
On Dec 13, 7:46 pm, Matteo Landi <[email protected]> wrote:
> On Tue, Dec 13, 2011 at 3:49 AM, leigh <[email protected]> wrote:
> > Hello Matteo,
>
> > Looks like the only way is to wrap the functions, on a second look
> > Sebastian Bergmann's php-test-helpers is only for user created
> > functions.
>
> > kind regards,
>
> > Leigh
>
> Leigh, thanks for the hint.
>
> I made a quick search on Google and found a Stackoverflow discussion
> in which a user describe the "wrapper" solution, but I don't get how
> to override model isUplaodedFile and moveUploadedFile methods from the
> within the test-controller class: any advices?
>
> regards,
> Matteo
>
> --http://www.matteolandi.net/
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php