You are not logged in.
testSomeController.php
public function testUploadCsvAndDataValidate(){
$this->dispatch("/index");
$this->assertController("index");
$this->assertAction("login");
$login_info = array(
'username' => 'test1',
'password' => '123',
'type' => '1'
);
$this->request->setMethod("POST")
->setPost($login_info);
//login into test1 and 123
$this->dispatch("/index/login");
$this->assertRedirectTo("/index/index"); //passed..
$this->resetRequest();
$this->resetResponse();
$file_name = "/home/vovovo/desktop/csvdir/test.csv";
$bool = file_exists($file_name);
$this->assertTrue($bool); //passed
$upload_post = array(
//'MAX_FILE_SIZE' => 2097152,
'ltcsv' => $file_name
);
$this->request->setMethod("POST")->setPost($upload_post);
//upload the csv
$this->dispatch("/rakuten/import");
//check is it redirect to confirm
$this->assertRedirectTo("/rakuten/confirm");The file 'ltcsv' was illegal uploaded, possible attack
Could you please suggest me how to test this situation?
the problem is only to emulate post upload..
Offline
hi mrgen,
you'd need some code here that's actually opening the file and sending a stream to the server... I don't see that here. That would be a good place to start.
Offline
Hi, i'm having problems testing actions with Zend_Form_Element_File. My test function:
public function testImportRequestAction($file)
{
$this->request->setMethod('POST')
->setPost(array(
'MAX_FILE_SIZE' => "2097152",
));
$_FILES = array('request' => array(
"name" => "rsaRequest.pem",
"type" => "text/plain",
"tmp_name" => "/tmp/phpi17KBB",
"error" => 0,
"size" => filesize('/tmp/phpi17KBB'),
));
$this->dispatch('/caoper/requests/importrarequest');
....
}But the form validation always returns false without any error messages. And when i force the form to pass validation i get "The file 'request' was illegal uploaded, possible attack".
Offline