Zendcasts Forum

A community of developers who work with the Zend Framework and other enterprise PHP technologies

You are not logged in.

#1 2010-04-07 01:53:16

mrgen
New member
Registered: 2010-04-07
Posts: 1

help (zend_form_element_file and zend_test)

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

#2 2010-04-09 19:57:02

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: help (zend_form_element_file and zend_test)

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

#3 2010-08-12 20:45:47

anderson.ls
New member
Registered: 2010-08-12
Posts: 1

Re: help (zend_form_element_file and zend_test)

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

Board footer

Powered by FluxBB