public function testRegister() { $this->model = new RegistrationForm(); $this->model->setAttributes(['email' => '*****@*****.**', 'username' => 'foobar', 'password' => 'foobar']); /** @var User $user */ verify($this->model->register())->true(); $user = User::findOne(['email' => '*****@*****.**']); verify('$user is instance of User', $user instanceof User)->true(); verify('email is valid', $user->email)->equals($this->model->email); verify('username is valid', $user->username)->equals($this->model->username); verify('password is valid', Password::validate($this->model->password, $user->password_hash))->true(); $token = Token::findOne(['user_id' => $user->id, 'type' => Token::TYPE_CONFIRMATION]); verify($token)->notNull(); $mock = $this->getMock(RegistrationForm::className(), ['validate']); $mock->expects($this->once())->method('validate')->will($this->returnValue(false)); verify($mock->register())->false(); }
/** * Displays the registration page. * After successful registration if enableConfirmation is enabled shows info message otherwise redirects to home page. * @return string * @throws \yii\web\HttpException */ public function actionRegister() { if (!$this->module->enableRegistration) { throw new NotFoundHttpException(); } $model = \Yii::createObject(RegistrationForm::className()); $this->performAjaxValidation($model); if ($model->load(\Yii::$app->request->post()) && $model->register()) { return $this->render('/message', ['title' => \Yii::t('user', 'Your account has been created'), 'module' => $this->module]); } return $this->render('register', ['model' => $model, 'module' => $this->module]); }