Exemple #1
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [TimestampBehavior::className(), SaveUserRole::className(), 'uploadFile' => ['class' => UploadBehaviour::className(), 'fields' => ['image'], 'allowedFileExtentions' => ['png', 'jpg']], 'multipleUploadFile' => ['class' => UploadBehaviour::className(), 'fields' => ['file_collection_id'], 'allowedFileExtentions' => ['png', 'jpg'], 'multiple' => true], 'galleryBehavior' => ['class' => GalleryBehavior::className(), 'type' => 'user', 'extension' => 'jpg', 'directory' => Yii::getAlias('@webroot') . '/files/User/gallery', 'url' => Yii::getAlias('@web') . '/files/User/gallery']];
 }
 public function testUpdateExistingUploadCollection()
 {
     $user = new User();
     $user->username = '******';
     $user->email = '*****@*****.**';
     $user->password = '******';
     $user->image_path = [$this->pathToImage, $this->pathToImage];
     $user->attachBehavior('multipleUpload', ['class' => behaviors\UploadBehaviour::className(), 'multiple' => true, 'fields' => ['image_path']]);
     $user->save();
     $user->trigger(yii\db\ActiveRecord::EVENT_AFTER_FIND);
     $collectionId = $user->image_path->id;
     $compareUser = User::findOne($user->id);
     $compareUser->image_path = [$this->pathToImage];
     $compareUser->attachBehavior('multipleUpload', ['class' => behaviors\UploadBehaviour::className(), 'multiple' => true, 'fields' => ['image_path']]);
     $compareUser->save();
     $compareUser->trigger(yii\db\ActiveRecord::EVENT_AFTER_FIND);
     $compareUserCollectionId = $compareUser->image_path->id;
     $files = $user->image_path->getUploads();
     $this->assertCount(3, $files);
     $this->assertEquals($collectionId, $compareUserCollectionId);
 }