public function testResizeAndReplace()
 {
     extract($this->uploadFile(['modelName' => News::className(), 'attribute' => 'image_path', 'inputName' => 'file-500']));
     $thumb = $model->thumb('image_path', '400x400', null, true);
     $this->assertContains('400x400', $thumb);
     $this->assertFileNotExists($thumb);
     $this->checkImageSize($file->path(true), 400, 400);
 }
 public function testImageWithOnlyMinHeight()
 {
     $model = new News();
     $rules = $model->getFileRulesDescription('image_only_minheight');
     $this->assertContains('Min. height 300px', $rules);
 }
 public function testRealPath()
 {
     extract($this->uploadFile(['modelName' => News::className(), 'attribute' => 'image_path', 'inputName' => 'file-300']));
     $this->assertFileExists($model->getFileRealPath('image_path'));
 }
 /**
  * Upload and test a gallery
  *
  * @param array $config see Properties UploadAction
  * @return array $files and $model
  */
 protected function uploadGallery($config)
 {
     $response = $this->runAction($config);
     $response = $this->checkUploadGalleryResponse($response);
     $file = File::findOne($response[1]);
     $model = new News(['title' => 'test', $config['attribute'] => ['files' => [$file->id => 'test']]]);
     $ownerType = $model->getFileOwnerType($config['attribute']);
     $this->checkTmpFile($file, -1, $ownerType);
     $this->assertTrue($model->save());
     $files = $model->getFiles($config['attribute']);
     $this->assertCount(1, $files);
     foreach ($files as $file) {
         $this->checkNotTmpFile($file, $model->id, $ownerType);
     }
     return ['files' => $files, 'model' => $model];
 }
 public function testFailSaveGallery()
 {
     extract($this->uploadGallery(['modelName' => News::className(), 'attribute' => 'image_gallery', 'inputName' => 'file-300', 'multiple' => true, 'template' => Yii::getAlias('@tests/data/views/gallery-item.php')]));
     $oldFiles = $files;
     $response = $this->runAction(['modelName' => News::className(), 'attribute' => 'image_gallery', 'inputName' => 'file-500']);
     $file = File::findOne($response['id']);
     unlink($file->path(true));
     $model->image_gallery = ['files' => [$response['id'] => 'test']];
     $model->save();
     $files = $model->getFiles('image_gallery');
     $this->assertCount(0, $files);
 }