/** * @inheritdoc */ public function init() { if (!$this->authUser instanceof User) { throw new InvalidParamException('AuthUser must be an instance of ' . User::className()); } $this->items = [['url' => ['/user/profile/index'], 'label' => Yii::t('user', 'Common settings')], ['url' => ['/user/profile/vcs-bindings'], 'label' => Yii::t('user', 'VCS bindings')]]; parent::init(); }
/** * @inheritdoc */ public function init() { if (!$this->model instanceof User) { throw new InvalidParamException('Model must be an instance of ' . User::className()); } $this->items = [['url' => ['/user/user-manager/update', 'id' => $this->model->id], 'label' => Yii::t('user', 'Common settings')], ['url' => ['/user/user-manager/vcs-bindings', 'id' => $this->model->id], 'label' => Yii::t('user', 'VCS bindings')]]; parent::init(); }
/** * Prepare testing data and returns it * * @return array */ protected function prepareFixtures() { /* @var $contributor User */ $contributor = $this->getModule('Yii2')->grabFixture('users', 'activeUser1'); /* @var $reviewer User */ $reviewer = $this->getModule('Yii2')->grabFixture('users', 'activeUser2'); // authorized user model $authModel = new Auth(['identityClass' => User::className(), 'identity' => $reviewer]); /* @var $project Project */ $project = $this->getModule('Yii2')->grabFixture('projects', 'gitProject'); /* @var $history BaseCommit[] */ $history = $project->getRepositoryObject()->getHistory(1, 0); $this->assertNotEmpty($history); $commit = $history[0]; $this->assertInstanceOf(BaseCommit::className(), $commit); return [$contributor, $reviewer, $authModel, $project, $commit]; }
/** * Test model validation and save */ public function testValidationSaveAndDelete() { $model = new ContributionReview(); $attributes = ['commit_id' => [['value' => null, 'isValid' => false], ['value' => [], 'isValid' => false], ['value' => ['wrong string'], 'isValid' => false], ['value' => str_repeat('A', 41), 'isValid' => false], ['value' => 1, 'isValid' => false], ['value' => md5(uniqid()), 'isValid' => true]], 'project_id' => [['value' => null, 'isValid' => false], ['value' => [], 'isValid' => false], ['value' => ['wrong string'], 'isValid' => false], ['value' => 'string', 'isValid' => false], ['value' => $this->getModule('Yii2')->grabFixture('projects', 'gitProject')->id, 'isValid' => true]], 'date' => [['value' => null, 'isValid' => false], ['value' => [], 'isValid' => false], ['value' => ['wrong string'], 'isValid' => false], ['value' => 'string', 'isValid' => false], ['value' => 1, 'isValid' => false], ['value' => date('Y-m-d H:i:s'), 'isValid' => true]], 'contributor_id' => [['value' => null, 'isValid' => true], ['value' => [], 'isValid' => true], ['value' => '', 'isValid' => true], ['value' => 'wrong integer', 'isValid' => false], ['value' => ['wrong integer'], 'isValid' => false], ['value' => $this->getModule('Yii2')->grabFixture('users', 'activeUser1')->id, 'isValid' => true]], 'reviewer_id' => [['value' => null, 'isValid' => true], ['value' => [], 'isValid' => true], ['value' => '', 'isValid' => true], ['value' => 'wrong integer', 'isValid' => false], ['value' => ['wrong integer'], 'isValid' => false], ['value' => $this->getModule('Yii2')->grabFixture('users', 'activeUser2')->id, 'isValid' => true]], 'message' => [['value' => null, 'isValid' => true], ['value' => 0, 'isValid' => false], ['value' => [], 'isValid' => true], ['value' => ['wrong string'], 'isValid' => false], ['value' => 'test message', 'isValid' => true]], 'contributor_email' => [['value' => null, 'isValid' => true], ['value' => [], 'isValid' => true], ['value' => 0, 'isValid' => false], ['value' => ['wrong string'], 'isValid' => false], ['value' => 'test contributor', 'isValid' => true]], 'contributor_name' => [['value' => null, 'isValid' => false], ['value' => [], 'isValid' => false], ['value' => 0, 'isValid' => false], ['value' => '', 'isValid' => false], ['value' => ['wrong string'], 'isValid' => false], ['value' => 'test contributor', 'isValid' => true]], 'repo_type' => [['value' => null, 'isValid' => false], ['value' => [], 'isValid' => false], ['value' => 0, 'isValid' => false], ['value' => '', 'isValid' => false], ['value' => ['wrong string'], 'isValid' => false], ['value' => 'wrong repo', 'isValid' => false], ['value' => 'svn', 'isValid' => true], ['value' => 'git', 'isValid' => true], ['value' => 'hg', 'isValid' => true]], 'reviewed' => [['value' => null, 'isValid' => true], ['value' => [], 'isValid' => true], ['value' => ['wrong string'], 'isValid' => false], ['value' => 'string', 'isValid' => false], ['value' => 1, 'isValid' => false], ['value' => date('Y-m-d H:i:s'), 'isValid' => true]]]; $this->getModule('\\Helper\\Unit')->validateModelAttributes($model, $attributes, $this); $this->assertTrue($model->validate()); $this->assertTrue($model->save()); $this->assertInstanceOf(Project::className(), $model->project); $this->assertEquals($model->project->id, $this->getModule('Yii2')->grabFixture('projects', 'gitProject')->id); $this->assertInstanceOf(User::className(), $model->contributor); $this->assertEquals($model->contributor->id, $this->getModule('Yii2')->grabFixture('users', 'activeUser1')->id); $this->assertInstanceOf(User::className(), $model->reviewer); $this->assertEquals($model->reviewer->id, $this->getModule('Yii2')->grabFixture('users', 'activeUser2')->id); // test unique model $attributes = $model->getAttributes(); unset($attributes['id']); $newModel = new ContributionReview(); $newModel->setAttributes($attributes); $this->assertFalse($newModel->validate()); $this->assertArrayHasKey('commit_id', $newModel->getErrors()); // delete test $this->assertEquals(1, $model->delete()); }
/** * @inheritdoc */ public function rules() { return [['email', 'filter', 'filter' => 'trim'], ['email', 'required', 'message' => Yii::t('app/form', 'Required email')], ['email', 'email', 'enableIDN' => true, 'message' => Yii::t('app/form', 'Valid email')], ['email', 'exist', 'targetClass' => User::className(), 'message' => Yii::t('app/form', 'Exist email')], ['token', 'filter', 'filter' => 'trim'], ['token', 'required'], ['token', 'string', 'length' => 32], ['username', 'filter', 'filter' => 'trim'], ['username', 'required', 'message' => 'Введите имя.'], ['username', 'string', 'min' => 4, 'tooShort' => 'Ваше имя должно содержать минимум {min} символа.'], ['username', 'string', 'max' => 40, 'tooLong' => 'Ваше имя не должно быть длиннее {max} символов.'], ['username', 'match', 'pattern' => '/^[\\w-]+$/', 'message' => 'В вашем имени можно использовать только латинские буквы, цифры, знаки «_» и «-».'], ['username', 'match', 'pattern' => '/^[a-zA-Z]/', 'message' => 'Первым символом в имени должна быть латинская буква.'], ['username', 'unique', 'targetClass' => User::className(), 'message' => 'Указанное вами имя занято.'], ['password', 'required', 'message' => 'Введите пароль.'], ['password', 'string', 'min' => 6, 'tooShort' => 'Пароль должен содержать минимум {min} символа.'], ['password', 'string', 'max' => 32, 'tooLong' => 'Пароль не должен быть длиннее {max} символов.'], ['repassword', 'required', 'message' => 'Введите повторно пароль.'], ['repassword', 'compare', 'compareAttribute' => 'password', 'message' => 'Введенные пароли не совпадают.'], ['verifyCode', 'required', 'message' => 'Введите код безопасности с изображения.'], ['verifyCode', 'captcha', 'captchaAction' => '/captcha/default/index', 'message' => 'Код безопасности указан неверно.']]; }
/** * @return ActiveQuery */ public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id'])->inverseOf('posts'); }
/** * @inheritdoc */ public function rules() { return [['email', 'required', 'message' => Yii::t('app/form', 'Required email')], ['email', 'filter', 'filter' => 'trim'], ['email', 'email', 'enableIDN' => true, 'message' => Yii::t('app/form', 'Valid email')], ['email', 'unique', 'targetClass' => User::className(), 'message' => Yii::t('app/form', 'Unique email')], ['username', 'filter', 'filter' => 'trim'], ['username', 'required', 'message' => Yii::t('app/form', 'Required username')], ['username', 'string', 'min' => 2, 'tooShort' => Yii::t('app/form', 'String short username')], ['username', 'string', 'max' => 40, 'tooLong' => Yii::t('app/form', 'String long username')], ['username', 'match', 'pattern' => '/^[a-zA-Z]/', 'message' => Yii::t('app/form', 'Username match first letter')], ['username', 'match', 'pattern' => '/^[\\w-]+$/', 'message' => Yii::t('app/form', 'Username match common')], ['username', 'unique', 'targetClass' => User::className(), 'message' => Yii::t('app/form', 'Unique username')], ['password', 'required', 'message' => 'Введите пароль.'], ['password', 'string', 'min' => 6, 'tooShort' => 'Пароль должен содержать минимум {min} символа.'], ['password', 'string', 'max' => 32, 'tooLong' => 'Пароль не должен быть длиннее {max} символов.'], ['repassword', 'required', 'message' => 'Введите пароль повторно.'], ['repassword', 'compare', 'compareAttribute' => 'password', 'message' => 'Введенные пароли не совпадают.'], ['termsAgree', 'boolean'], ['termsAgree', 'required', 'requiredValue' => true, 'message' => 'Вам необходимо согласиться с правилами сайта.'], ['verifyCode', 'required', 'message' => 'Введите код безопасности с изображения.'], ['verifyCode', 'captcha', 'captchaAction' => '/captcha/default/index', 'message' => 'Код безопасности указан неверно.']]; }
/** * Returns user's model * * @return ActiveQuery */ public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); }
/** * @return ActiveQuery */ public function getLastPostUser() { return $this->hasOne(User::className(), ['id' => 'last_post_user_id']); }
/** * Tests VCS bindings update * * @return User * * @depends testLockAndActivate */ public function testVCSBindings() { /* @var $user User */ $user = $this->getModule('Yii2')->grabFixture('users', 'activeUser1'); $accounts = [0 => new UserAccountForm(['username' => 'testing user name git', 'type' => UserAccount::TYPE_GIT]), 1 => new UserAccountForm(['username' => 'testing user name hg', 'type' => UserAccount::TYPE_HG])]; $this->assertTrue($this->userModule->updateVcsBindings($user, $accounts)); $this->assertEquals(count($accounts), count($user->accounts)); unset($user->accounts); $accounts[0]->deletionFlag = true; $this->assertTrue($this->userModule->updateVcsBindings($user, $accounts)); $this->assertEquals(1, count($user->accounts)); /* @var $contributorApi ContributorApi */ $contributorApi = Yii::$app->contributors; $getByName = $contributorApi->getContributor(UserAccount::TYPE_HG, 'testing user name hg'); $this->assertInstanceOf(User::className(), $getByName); $this->assertEquals($getByName->id, $user->id); return $user; }
/** * @inheritdoc */ public function rules() { return [['email', 'required', 'message' => Yii::t('app/form', 'Required email')], ['email', 'filter', 'filter' => 'trim'], ['email', 'email', 'enableIDN' => true, 'message' => Yii::t('app/form', 'Valid email')], ['email', 'exist', 'targetClass' => User::className(), 'message' => Yii::t('app/form', 'Exist email')], ['password', 'trim'], ['password', 'required', 'message' => Yii::t('app/form', 'Required password')], ['password', 'string', 'min' => 6, 'tooShort' => Yii::t('app/form', 'String short password')], ['password', 'string', 'max' => 32, 'tooLong' => Yii::t('app/form', 'String long password')], ['password', 'passwordValidation'], ['remember', 'boolean'], ['verifyCode', 'required', 'message' => 'Введите код безопасности с изображения.'], ['verifyCode', 'captcha', 'captchaAction' => '/captcha/default/index', 'message' => 'Код безопасности указан неверно.']]; }
/** * Test user accounts relations * * @depends testValidationAndSave * * @return User */ public function testUserAccounts() { /* @var $user User */ $user = $this->getModule('Yii2')->grabFixture('users', 'activeUser1'); $model = new UserAccount(); $attributes = ['user_id' => [['value' => null, 'isValid' => false], ['value' => [], 'isValid' => false], ['value' => 0, 'isValid' => false], ['value' => -100, 'isValid' => false], ['value' => $user->id, 'isValid' => true]], 'username' => [['value' => null, 'isValid' => false], ['value' => [], 'isValid' => false], ['value' => 0, 'isValid' => false], ['value' => str_repeat('A', 101), 'isValid' => false], ['value' => str_repeat('A', 100), 'isValid' => true]], 'type' => [['value' => null, 'isValid' => false], ['value' => [], 'isValid' => false], ['value' => 'wrong type', 'isValid' => false], ['value' => UserAccount::TYPE_HG, 'isValid' => true], ['value' => UserAccount::TYPE_SVN, 'isValid' => true], ['value' => UserAccount::TYPE_GIT, 'isValid' => true]]]; $this->getModule('\\Helper\\Unit')->validateModelAttributes($model, $attributes, $this); $this->assertTrue($model->save()); // check unique record with type and username columns $newModel = new UserAccount(); $newModel->setAttributes($model->getAttributes()); $this->assertFalse($newModel->validate()); $this->assertArrayHasKey('type', $newModel->getErrors()); $this->assertArrayHasKey('username', $newModel->getErrors()); $newModel->type = UserAccount::TYPE_HG; $this->assertTrue($newModel->validate()); $this->assertTrue($newModel->save()); $this->assertContainsOnly(UserAccount::className(), $user->accounts); $this->assertCount(2, $user->accounts); $this->assertInstanceOf(User::className(), $model->user); $this->assertEquals($user->id, $model->user->id); $this->assertInstanceOf(User::className(), $newModel->user); $this->assertEquals($user->id, $newModel->user->id); return $user; }