Example #1
0
 /**
  * executed before each test
  */
 public function _before()
 {
     $this->markTestSkipped('Mocking up php functions doesnt work for zephir extensions.');
     $_FILES = ['photo' => ['name' => ['f0', 'f1', ['f2', 'f3'], [[[['f4']]]]], 'type' => ['text/plain', 'text/csv', ['image/png', 'image/jpeg'], [[[['application/octet-stream']]]]], 'tmp_name' => ['t0', 't1', ['t2', 't3'], [[[['t4']]]]], 'error' => [0, 0, [0, 0], [[[[8]]]]], 'size' => [10, 20, [30, 40], [[[[50]]]]]]];
     $request = new Request();
     $request->setDI($this->tester->getApplication()->getDI());
     $uploadedFiles = $request->getUploadedFiles();
     $files = [];
     /** @var Request\File $file */
     foreach ($uploadedFiles as $file) {
         $files[] = ['name' => $file->getName(), 'tmp_name' => $file->getTempName(), 'type' => $file->getType(), 'size' => $file->getSize(), 'error' => $file->getError()];
     }
     $this->files = $files;
     Test::func('Phalcon\\Validation\\Validator', 'getimagesize', function ($tmpName) {
         $tmpSizes = ['t0' => null, 't1' => null, 't2' => [500, 500], 't3' => [1000, 1000], 't4' => null];
         return $tmpSizes[$tmpName];
     });
     Test::func('Phalcon\\Validation\\Validator', 'finfo_open', function ($mimeType) {
         return null;
     });
     Test::func('Phalcon\\Validation\\Validator', 'finfo_file', function ($tmp, $tmpName) {
         $tmpTypes = ['t0' => 'text/plain', 't1' => 'text/csv', 't2' => 'image/png', 't3' => 'image/jpeg', 't4' => 'application/octet-stream'];
         return $tmpTypes[$tmpName];
     });
     Test::func('Phalcon\\Validation\\Validator', 'is_uploaded_file', function ($tmpName) {
         return true;
     });
     Test::func('Phalcon\\Validation\\Validator', 'finfo_close', function ($tmp, $tmpName) {
     });
     $_SERVER["REQUEST_METHOD"] = "POST";
 }
Example #2
0
 /**
  * Check if upload files are valid
  *
  * @return bool
  */
 public function isValid()
 {
     // get files for upload
     $this->files = $this->request->getUploadedFiles();
     if (sizeof($this->files) > 0) {
         // do any actions if files exists
         foreach ($this->files as $n => $file) {
             // apply all the validation rules for each file
             foreach ($this->rules as $key => $rule) {
                 if (method_exists($this->validator, 'check' . ucfirst($key)) === true) {
                     $this->validator->{'check' . ucfirst($key)}($file, $rule);
                 }
             }
         }
     }
     $errors = $this->getErrors();
     return empty($errors) === true ? true : false;
 }
Example #3
0
 public function uploadAndStoreAttachment(\Phalcon\Http\Request $request)
 {
     $user = \Phalcon\Di::getDefault()->get('auth');
     /** @var myModel $this */
     foreach ($request->getUploadedFiles() as $f) {
         $data = [];
         $data['name'] = $f->getName();
         $data['url'] = myTools::storeAttachment($f);
         $data['user_id'] = $user->id;
         $data['attachable_id'] = $this->id;
         $data['attachable_type'] = get_class($this);
         (new Attachments())->save($data);
         $this->increaseCount('attachmentCount');
     }
     if (is_a($this, 'Tags')) {
         $meta = $this->getTagmetaOrNew();
         $meta->save();
     }
     return $this;
 }
Example #4
0
 /**
  * @param bool $notErrored
  * @return \Phalcon\Http\Request\File[]
  */
 public function getUploadedFiles($notErrored = false)
 {
     return parent::getUploadedFiles($notErrored);
 }