/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * @title: Создание * @return mixed */ public function actionCreate() { $model = new User(); $model->setScenario(User::CREATE_SCENARIO); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function testSaveOneImageInOneField() { $_POST['User'] = ['username' => 'test', 'email' => '*****@*****.**', 'password' => '123456789', 'image' => $this->pathToImage]; $user = new User(); $user->load($_POST); $user->save(); $pathToImage = "/models/User/{$user->id}/test.jpg"; $user->trigger(\yii\db\ActiveRecord::EVENT_AFTER_FIND); $newImageWebPath = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array_slice(explode(DIRECTORY_SEPARATOR, (string) $user->image), -4)); $this->assertEquals($pathToImage, $newImageWebPath); $this->assertFileExists($user->image->fullPath); }