public function testWrongFileId() { extract($this->uploadFile(['modelName' => News::className(), 'attribute' => 'image_id', 'inputName' => 'file-300'], false)); $model->image_id = 100; $model->save(); $this->assertTrue($model->image_id === $file->id); $model = new News(); $model->image_id = 100; $model->save(); $this->assertTrue($model->image_id === 0); }
/** * 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]; }