/**
  * @param \yii\base\Model $model
  * @param string $attribute
  */
 public function validateAttribute($model, $attribute)
 {
     $regexpValidator = new RegularExpressionValidator(['pattern' => '/^9[0-9]{9}$/']);
     if (!$regexpValidator->validate($model->{$attribute})) {
         $this->addError($model, $attribute, '{attribute} имеет неверный формат');
         return;
     }
     $existValidator = new ExistValidator(['targetClass' => Number::className(), 'targetAttribute' => 'number']);
     if (!$existValidator->validate($model->{$attribute})) {
         $this->addError($model, $attribute, "{attribute} не существует");
     }
 }
Esempio n. 2
0
 public function rules()
 {
     return array_merge(parent::rules(), [[['ownerId', 'contentType'], 'required'], ['ownerId', 'exist', 'targetClass' => Number::className(), 'targetAttribute' => '_id'], [['file'], 'file']]);
 }
Esempio n. 3
0
use app\tests\codeception\_pages\mobile\number\UpdatePage;
use app\modules\mobile\models\Number;
use app\modules\directory\models\Employee;
/**
 * @var $model app\modules\mobile\models\Number
 */
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that update Number model works');
$page = UpdatePage::openBy($I);
$model = $I->grabRecord(Number::className(), ['_id' => 'number1']);
$I->seeInTitle('Номер ' . $model['number']);
$I->dontSeeElement($page->fieldSelector('number'));
$I->SeeElement("#documents-panel-body");
$I->SeeElement("#history-panel-body");
$I->seeInField($page->fieldSelector('ownerName'), $model->owner['fullName']);
$I->seeInField($page->fieldSelector('ownerPost'), $model->owner['post']);
$I->seeInField($page->fieldSelector('operatorId'), $model['operatorId']);
$I->seeInField($page->fieldSelector('destination'), $model['destination']);
$I->seeInField($page->fieldSelector('limit'), $model['limit']);
foreach (array_keys(Number::optionItems()) as $option) {
    in_array($option, $model->options) ? $I->seeCheckboxIsChecked($page->fieldSelector($option)) : $I->dontSeeCheckboxIsChecked($page->fieldSelector($option));
}
$I->seeInField($page->fieldSelector('comment'), $model['comment']);
$owner = $I->grabRecord(Employee::className(), ['_id' => 'employee2']);
$page->submit(['number' => '1234567890', 'ownerName' => $owner['fullName'], 'ownerPost' => $owner['post'], 'operatorId' => 'operator2', 'destination' => Number::DESTINATION_MODEM, 'limit' => '2000', 'options' => [Number::OPTION_TRIP], 'comment' => 'This is update comment']);
$I->see("Данные успешно обновлены", '.alert-success');
$history = $model['history'];
$history[count($history) - 1]['returnDate'] = time();
$history[] = ['ownerId' => 'employee2', 'rentDate' => time()];
$I->seeRecord(Number::className(), ['_id' => 'number1', 'number' => $model['number'], 'ownerId' => 'employee2', 'operatorId' => 'operator2', 'destination' => Number::DESTINATION_MODEM, 'limit' => 2000, 'options' => [Number::OPTION_TRIP], 'history' => $history, 'comment' => 'This is update comment']);
Esempio n. 4
0
$I = new FunctionalTester($scenario);
$I->wantTo('test validation of Number model');
CreatePage::openBy($I);
$I->seeInTitle('Новый номер');
$I->amGoingTo("send empty form");
CreatePage::openBy($I)->submit();
$I->see('Необходимо заполнить «Номер».');
$I->amGoingTo("introduce too short number");
CreatePage::openBy($I)->submit(['number' => '1234']);
$I->see('Значение «Номер» должно содержать 10 символов.');
$I->amGoingTo("introduce number and limit of letters and numbers");
CreatePage::openBy($I)->submit(['number' => '123abc', 'limit' => '123abc']);
$I->see('Значение «Номер» должно быть целым числом.');
$I->see('Значение «Лимит» должно быть целым числом.');
$I->amGoingTo("introduce negative value of number and limit");
CreatePage::openBy($I)->submit(['number' => '-123', 'limit' => '-456']);
$I->see('Значение «Номер» должно быть не меньше 0.');
$I->see('Значение «Лимит» должно быть не меньше 0.');
$I->amGoingTo("introduce non unique value of number");
$I->haveRecord(Number::className(), ['number' => '9101234567']);
CreatePage::openBy($I)->submit(['number' => '9101234567']);
$I->see('Номер «9101234567» уже занят.');
$I->amGoingTo("check accounting option and empty limit");
CreatePage::openBy($I)->submit(['number' => '0123456789', 'options' => [Number::OPTION_ACCOUNTING]]);
$I->see("При выбранной опции «Учитывать перерасход» лимит должен быть указан");
$I->amGoingTo("introduce non existent owner name");
CreatePage::openBy($I)->submit(['number' => '0123456789', 'ownerName' => 'Non Existent Employee']);
$I->see("Сотрудник «Non Existent Employee» не найден.");
$I->amGoingTo("introduce non existent owner post");
CreatePage::openBy($I)->submit(['number' => '0123456789', 'ownerName' => 'Иванов Иван Иванович', 'ownerPost' => 'Non Existent Post']);
$I->see("Сотрудник «Иванов Иван Иванович» c должностью «Non Existent Post» не найден.");
Esempio n. 5
0
 * User: bill
 * Date: 26.01.15
 * Time: 11:31
 */
use app\tests\codeception\_pages\mobile\number\CreatePage;
use app\modules\mobile\models\Number;
use app\modules\mobile\models\Document;
use app\modules\directory\models\Employee;
$I = new FunctionalTester($scenario);
$I->wantTo("ensure that creation Number model works");
$owner = $I->grabRecord(Employee::className(), ['id' => 1]);
$newDocument = 'file1.jpg';
$number = '9876543210';
$I->amGoingTo("prepare database.");
Document::deleteAll(['filename' => $newDocument]);
Number::deleteAll(['number' => $number]);
$page = CreatePage::openBy($I);
$I->dontSeeElement("input[type=file]");
$I->dontSeeElement("#documents-panel-body");
$I->dontSeeElement("#history-panel-body");
$page->submit(['number' => $number, 'ownerName' => $owner->fullName, 'ownerPost' => $owner->post, 'operatorId' => 'operator2', 'destination' => Number::DESTINATION_MODEM, 'limit' => "1000", 'options' => [Number::OPTION_ACCOUNTING, Number::OPTION_DIRECTORY], 'comment' => 'This is comment of testing number.']);
$I->SeeRecord(Number::className(), ['number' => $number, 'ownerId' => 1, 'operatorId' => 'operator2', 'destination' => Number::DESTINATION_MODEM, 'limit' => 1000, 'options' => [Number::OPTION_ACCOUNTING, Number::OPTION_DIRECTORY], 'history' => [['ownerId' => 'employee1', 'rentDate' => time()]], 'comment' => 'This is comment of testing number.']);
$I->see("Номер успешно создан", '.alert-success');
$I->seeInField($page->fieldSelector('ownerName'), $owner->fullName);
$I->seeInField($page->fieldSelector('ownerPost'), $owner->posts[1]);
$I->seeOptionIsSelected($page->fieldSelector('operatorId'), "Оператор 2");
$I->seeOptionIsSelected($page->fieldSelector('destination'), Number::DESTINATION_MODEM);
$I->seeCheckboxIsChecked($page->fieldSelector(Number::OPTION_ACCOUNTING));
$I->seeCheckboxIsChecked($page->fieldSelector(Number::OPTION_DIRECTORY));
$I->dontSeeCheckboxIsChecked($page->fieldSelector(Number::OPTION_TRIP));
$I->seeInField($page->fieldSelector('comment'), 'This is comment of testing number.');
Esempio n. 6
0
 public function testGetDocuments()
 {
     Document::deleteAll();
     $this->specify("Attachment must be exist", function () {
         $numberId = $this->tester->haveRecord(Number::className(), ['number' => '9999999999']);
         $model = $this->tester->grabRecord(Number::className(), ['_id' => $numberId]);
         $model->attachDocument(\Yii::getAlias('@data') . '/file1.jpg');
         $model->attachDocument(\Yii::getAlias('@data') . '/file2.pdf');
         expect(count($model->documents))->equals(2);
         foreach ($model->documents as $document) {
             expect($document instanceof Document)->true();
             expect($document->ownerId)->equals($model->getPrimaryKey());
         }
     });
 }
Esempio n. 7
0
 /**
  * @return \yii\db\ActiveQueryInterface
  */
 public function getNumber()
 {
     return $this->hasOne(Number::className(), ['_id' => 'numberId']);
 }