Пример #1
0
 /**
  * Save photo
  *
  * @param \app\models\UserProfile $profile
  * @param string $photo
  * @return void
  */
 private function savePhoto($profile, $photo)
 {
     $file = $this->makeUploadedFile($photo);
     $model = new DynamicModel(compact('file'));
     $model->addRule('file', 'image', $profile->fileRules('photo', true))->validate();
     if (!$model->hasErrors()) {
         $profile->createFile('photo', $file->tempName, $model->file->name);
     }
 }
Пример #2
0
 public function testAddPhoto($I)
 {
     $model = new UserProfile();
     $file = $model->createFile('photo', Yii::getAlias('@tests/_data/files/300x300.png'), '300x300.png');
     $I->click('user-2');
     $I->click('Profile');
     $I->submitForm($this->formId, [$this->formName . '[photo]' => $file->id]);
     $I->expectTo('see success');
     $I->see('Saved successfully');
     $I->seeInField($this->formName . '[photo]', $model->fileUrl('photo', $file));
 }