From df12f02968f1fb89ec2c685e61ec655266e7bf80 Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Sun, 24 Mar 2024 21:48:49 +0300 Subject: [PATCH] test --- erp24/actions/payroll/ManagementAction.php | 1 - erp24/records/Products1c.php | 5 +- erp24/tests/_support/FunctionalTester.php | 1 - erp24/tests/_support/UnitTester.php | 1 - erp24/tests/fixtures/CityFixture.php | 2 +- erp24/tests/functional/CityCest.php | 124 ------- erp24/tests/functional/ContactFormCest.php | 57 --- erp24/tests/functional/LoginFormCest.php | 59 --- erp24/tests/functional/PageListCest.php | 5 +- erp24/tests/unit/models/CityTest.php | 389 -------------------- erp24/tests/unit/models/ContactFormTest.php | 41 --- erp24/tests/unit/models/LoginFormTest.php | 51 --- 12 files changed, 5 insertions(+), 731 deletions(-) delete mode 100755 erp24/tests/functional/CityCest.php delete mode 100644 erp24/tests/functional/ContactFormCest.php delete mode 100644 erp24/tests/functional/LoginFormCest.php delete mode 100755 erp24/tests/unit/models/CityTest.php delete mode 100644 erp24/tests/unit/models/ContactFormTest.php delete mode 100644 erp24/tests/unit/models/LoginFormTest.php diff --git a/erp24/actions/payroll/ManagementAction.php b/erp24/actions/payroll/ManagementAction.php index 6d01e990..a0d10128 100755 --- a/erp24/actions/payroll/ManagementAction.php +++ b/erp24/actions/payroll/ManagementAction.php @@ -88,7 +88,6 @@ class ManagementAction extends Action $scriptLauncherLogObj->active = 0; $scriptLauncherLogObj->status = 9; $scriptLauncherLogObj->save(); - Yii::$app->cache->set("addAssignmentTask", false); } else { if ($scriptLauncherLog['active'] == 1) { $errorText = 'Процесс формирования ведомости уже запущен в ' . $scriptLauncherLog['date_start']; diff --git a/erp24/records/Products1c.php b/erp24/records/Products1c.php index 6816a715..72889c21 100644 --- a/erp24/records/Products1c.php +++ b/erp24/records/Products1c.php @@ -245,10 +245,7 @@ class Products1c extends \yii\db\ActiveRecord WHERE products_1c.name != '' - ", - [ - ':search_in' => $searchIn, - ] + " ); $data = $command->queryAll(); diff --git a/erp24/tests/_support/FunctionalTester.php b/erp24/tests/_support/FunctionalTester.php index 43327cb3..b7d40461 100755 --- a/erp24/tests/_support/FunctionalTester.php +++ b/erp24/tests/_support/FunctionalTester.php @@ -1,5 +1,4 @@ [ - 'class' => UserFixture::className(), - 'dataFile' => codecept_data_dir() . 'login_data.php' - ], - 'city' => [ - 'class' => CityFixture::className(), - 'dataFile' => codecept_data_dir() . 'city.php' - ] - - ]; - } - - /** - * @param FunctionalTester $I - * @dataProvider pageProvider - */ - public function testSortLinkClick(FunctionalTester $I, Example $data) - { - $pageH1 = 'Города'; - $I->amLoggedInAs(1); - - $I->amOnPage('/city/'); - $I->see($pageH1, 'h1'); - $I->click(['link' => $data['link']]); - $I->see($pageH1, 'h1'); - $I->seeInTitle($pageH1); - $I->click(['link' => $data['link']]); - $I->see($pageH1, 'h1'); - $I->seeInTitle($pageH1); - - } - - /** - * @return array - */ - protected function pageProvider() - { - return [ - ['link'=>"Название"], - ['link'=>"Символьный код"], - ['link'=>"Телефон"], - ['link'=>"Активность"], - ]; - } - - - - /** - * @param FunctionalTester $I - */ - public function createCity(FunctionalTester $I) - { - - $I->amLoggedInAs(1); - - $I->amOnPage('/city/create/'); - $I->fillField('City[name]', 'Город Город'); - $I->fillField('City[code]', 'codecity'); - $I->fillField('City[phone]', '+7 (132) 4-542-132'); - $I->click('Сохранить'); - - $I->see('Город Город'); - - } - - /** - * @param FunctionalTester $I - */ - public function viewCity(FunctionalTester $I) - { - $I->amLoggedInAs(1); - - $model = City::find()->one(); - - $urlView = '/city/view/'.$model->id.'/'; - $name = $model->name; - $I->amOnPage($urlView); - $I->click(['link' => 'Изменить']); - - $I->see($name); - - } - - /** - * @param FunctionalTester $I - */ - public function updateCity(FunctionalTester $I) - { - $I->amLoggedInAs(1); - - $model = City::find()->one(); - - $urlView = '/city/update/'.$model->id.'/'; - $name = $model->name; - $I->amOnPage($urlView); - $I->click('Сохранить'); - - $I->see($name); - - } -} diff --git a/erp24/tests/functional/ContactFormCest.php b/erp24/tests/functional/ContactFormCest.php deleted file mode 100644 index d17ef52f..00000000 --- a/erp24/tests/functional/ContactFormCest.php +++ /dev/null @@ -1,57 +0,0 @@ -amOnRoute('site/contact'); - } - - public function openContactPage(\FunctionalTester $I) - { - $I->see('Contact', 'h1'); - } - - public function submitEmptyForm(\FunctionalTester $I) - { - $I->submitForm('#contact-form', []); - $I->expectTo('see validations errors'); - $I->see('Contact', 'h1'); - $I->see('Name cannot be blank'); - $I->see('Email cannot be blank'); - $I->see('Subject cannot be blank'); - $I->see('Body cannot be blank'); - $I->see('The verification code is incorrect'); - } - - public function submitFormWithIncorrectEmail(\FunctionalTester $I) - { - $I->submitForm('#contact-form', [ - 'ContactForm[name]' => 'tester', - 'ContactForm[email]' => 'tester.email', - 'ContactForm[subject]' => 'test subject', - 'ContactForm[body]' => 'test content', - 'ContactForm[verifyCode]' => 'testme', - ]); - $I->expectTo('see that email address is wrong'); - $I->dontSee('Name cannot be blank', '.help-inline'); - $I->see('Email is not a valid email address.'); - $I->dontSee('Subject cannot be blank', '.help-inline'); - $I->dontSee('Body cannot be blank', '.help-inline'); - $I->dontSee('The verification code is incorrect', '.help-inline'); - } - - public function submitFormSuccessfully(\FunctionalTester $I) - { - $I->submitForm('#contact-form', [ - 'ContactForm[name]' => 'tester', - 'ContactForm[email]' => 'tester@example.com', - 'ContactForm[subject]' => 'test subject', - 'ContactForm[body]' => 'test content', - 'ContactForm[verifyCode]' => 'testme', - ]); - $I->seeEmailIsSent(); - $I->dontSeeElement('#contact-form'); - $I->see('Thank you for contacting us. We will respond to you as soon as possible.'); - } -} diff --git a/erp24/tests/functional/LoginFormCest.php b/erp24/tests/functional/LoginFormCest.php deleted file mode 100644 index 7a83a27d..00000000 --- a/erp24/tests/functional/LoginFormCest.php +++ /dev/null @@ -1,59 +0,0 @@ -amOnRoute('site/login'); - } - - public function openLoginPage(\FunctionalTester $I) - { - $I->see('Login', 'h1'); - - } - - // demonstrates `amLoggedInAs` method - public function internalLoginById(\FunctionalTester $I) - { - $I->amLoggedInAs(100); - $I->amOnPage('/'); - $I->see('Logout (admin)'); - } - - // demonstrates `amLoggedInAs` method - public function internalLoginByInstance(\FunctionalTester $I) - { - $I->amLoggedInAs(\app\models\User::findByUsername('admin')); - $I->amOnPage('/'); - $I->see('Logout (admin)'); - } - - public function loginWithEmptyCredentials(\FunctionalTester $I) - { - $I->submitForm('#login-form', []); - $I->expectTo('see validations errors'); - $I->see('Username cannot be blank.'); - $I->see('Password cannot be blank.'); - } - - public function loginWithWrongCredentials(\FunctionalTester $I) - { - $I->submitForm('#login-form', [ - 'LoginForm[username]' => 'admin', - 'LoginForm[password]' => 'wrong', - ]); - $I->expectTo('see validations errors'); - $I->see('Incorrect username or password.'); - } - - public function loginSuccessfully(\FunctionalTester $I) - { - $I->submitForm('#login-form', [ - 'LoginForm[username]' => 'admin', - 'LoginForm[password]' => 'admin', - ]); - $I->see('Logout (admin)'); - $I->dontSeeElement('form#login-form'); - } -} \ No newline at end of file diff --git a/erp24/tests/functional/PageListCest.php b/erp24/tests/functional/PageListCest.php index c9a1e607..ada59ba5 100644 --- a/erp24/tests/functional/PageListCest.php +++ b/erp24/tests/functional/PageListCest.php @@ -1,11 +1,12 @@ amLoggedInAs(\app\models\User::findByUsername('admin')); + $tt = 2; +// $I->amLoggedInAs(Admin::findByUsername('root')); $I->amOnPage('/info-table/shift-sales'); $I->see('Login', 'h1'); } diff --git a/erp24/tests/unit/models/CityTest.php b/erp24/tests/unit/models/CityTest.php deleted file mode 100755 index 788ab43a..00000000 --- a/erp24/tests/unit/models/CityTest.php +++ /dev/null @@ -1,389 +0,0 @@ -className = City::className(); - - } - - - /** - * @return array - */ - public function _fixtures() - { - return [ - 'city' => [ - 'class' => CityFixture::className(), - 'dataFile' => codecept_data_dir() . 'city.php' - ] - ]; - } - - public function testEmptyValues() - { - $model = new $this->className; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - } - - public function testNameOnly() - { - $model = new $this->className; - - $model->attributes = [ - 'name' => 'Город' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - - } - public function testWrongName() - { - $model = new $this->className; - - $model->attributes = [ - 'name' => 'one title' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key name must have in array errors', $model->errors)->hasKey('name'); - - } - - public function testShortName() - { - $model = new $this->className; - - $model->attributes = [ - 'name' => 'H' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key name must have in array errors', $model->errors)->hasKey('name'); - - } - - public function testFieldActiveNotInteger() - { - $model = new $this->className; - - $model->attributes = [ - 'active' => 'string' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key active must have in array errors', $model->errors)->hasKey('active'); - - } - - public function testLongPhoneSupport() - { - $model = new $this->className; - - $model->attributes = [ - 'phone_support' => '123456789012345678901' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key phone_support must have in array errors', $model->errors)->hasKey('phone_support'); - - } - - /** - * @dataProvider providerIntegerFields - */ - public function testIntegerFieldsWrongSetRussianText($a) - { - $model = new $this->className; - - $model->attributes = [ - $a => 'Название' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key '.$a.' must have in array errors', $model->errors)->hasKey($a); - - } - - /** - * @return array - */ - public function providerIntegerFields() - { - $obj = new City(); - return $obj->getAllFieldsGroupByType()->getFieldsByType('integer'); - } - - - public function testLongPhone() - { - $model = new $this->className; - - $model->attributes = [ - 'phone' => '123456789012345678901' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key phone must have in array errors', $model->errors)->hasKey('phone'); - - } - - public function testLongName() - { - $model = new $this->className; - - $model->attributes = [ - 'name' => 'цщукзшгецзщушкгезщцушкгезщцшугкещзшугкцезщшгцзукешгцушгкеншщцугкенщшгншщгцункещшцгукеншщгцкежрлордорфжваопрфваопрылжвоапрыдлвоапрывалопрылдвоапрылваопрлыдпаловаарыплдоршдкгеншгукрпвшгкеершупоыаршгнкешыгарлыовврппршгыукрлпоыршгыукршшывгралопршыгкршорпчлоавр' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key name must have in array errors', $model->errors)->hasKey('name'); - - } - - public function testLongCode() - { - $model = new $this->className; - - $model->attributes = [ - 'code' => 'qwertwpieurtypiweurtyiweurtyioweurytioweurytioweurtyioaslkjdfhklajfhlkjahfklgjahdkfjghkadjfgkajdfgkajddfhgkajddfhkgkjaddhfkgkjadhfkgkjahdkfjghklazcvbvbzkcvjhblzkcvjhblkzjcvhblkzuvycoiuzyoiuyzouvybozhvblzvzuvbhoizuvcybiozucvhbzjcvhobzciuvhkjewrhtklwjehrtklj' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key code must have in array errors', $model->errors)->hasKey('code'); - - } - -//[['name', 'code', 'phone', 'email'], 'string', 'min' => 2, 'max' => 255], - public function testShortPhoneSupport() - { - $model = new $this->className; - - $model->attributes = [ - 'phone_support' => '1' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key phone_support must have in array errors', $model->errors)->hasKey('phone_support'); - - } - - public function testShortPhone() - { - $model = new $this->className; - - $model->attributes = [ - 'phone' => '1' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key phone must have in array errors', $model->errors)->hasKey('phone'); - - } - - public function testNotUniqueName() - { - $model = new $this->className; - - $nameCityTest = 'Город тест'; - - $model->attributes = [ - 'name' => $nameCityTest, - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect($model->getFirstError('name')); - expect('key name must have in array errors', $model->errors)->hasKey('name'); - - } - - public function testNotUniqueCode() - { - $model = new $this->className; - - $codeTest = 'city-test'; - -// $message = 'Значение «'.$codeTest.'» для «Символьный код» уже занято.'; - - $model->attributes = [ - 'code' => $codeTest, - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); - expect('key code must have in array errors', $model->errors)->hasKey('code'); - } - - public function testWrongCode() - { - $model = new $this->className; - - $codeTest = 'фываы'; - -// $message = 'Значение «'.$codeTest.'» для «Символьный код» уже занято.'; - - $model->attributes = [ - 'code' => $codeTest, - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); -// $test = $model->getFirstError('code'); -// expect($model->getFirstError('code'))->equals($message); - expect('key code must have in array errors', $model->errors)->hasKey('code'); - - } - - public function testCityWrongMail() - { - $model = new $this->className; - $model->attributes = [ - 'email' => 'WrongMail' - ]; - - $validate = $model->validate(); - - expect('Validation should be failed', $validate)->false(); - expect($model->hasErrors())->true(); -// expect($model->getFirstError('email'))->equals('Значение «E-mail» не является правильным email адресом.'); - expect('key email must have in array errors', $model->errors)->hasKey('email'); - } - - public function testTrueCity() - { - $model = new $this->className; - $expectedAttrs = [ - 'name' => 'Город Тест Тест', - 'code' => 'testcode', - 'phone' => '+7 (332) 4-375-847', - 'email' => 'nicuole.pacek@schultz.info', - 'phone_support' => '8 800 770 70 22', - 'active' => '1', - 'created_at' => '1402312317', - 'updated_at' => '1402312317', - ]; - - $model->attributes = $expectedAttrs; - - expect('Validation should be success', $model->validate())->true(); - expect($model->hasErrors())->false(); - - $this->assertTrue($model->save()); - - $expectedAttrs['id'] = $model->id; - - $city = City::find()->where(['id' =>$expectedAttrs['id']])->one(); - $this->assertNotNull($city); - - $this->assertEquals($expectedAttrs['name'], $city->name); - $this->tester->assertEquals($expectedAttrs['name'], $city->name); - - $this->assertEquals($expectedAttrs['email'], $city->email); - $this->assertEquals($expectedAttrs['code'], $city->code); - - } - - public function testDeleteCity() - { - // delete - $record = new $this->className; - $record->name = 'Город Тест Тест Первый Тест'; - $record->code = 'testcode'; - $record->phone = '+7 (332) 4-375-847'; - $record->email = 'nicuole.pacek@schultz.info'; - $record->phone_support = '8 800 770 70 22'; - $record->active = 1; - $record->created_at = 1402312317; - $record->updated_at = 1402312317; - - $record->save(); - - $recordId = $record->id; - - $record = City::findOne($recordId); - $record->delete(); - $record = City::findOne($recordId); - $this->assertNull($record); - - // deleteAll - $record = new $this->className; - $record->name = 'Город Тест Тест Второй Тест'; - $record->code = 'testcode'; - $record->phone = '+7 (332) 4-375-847'; - $record->email = 'nicuole.pacek@schultz.info'; - $record->phone_support = '8 800 770 70 22'; - $record->active = 1; - $record->created_at = 1402312317; - $record->updated_at = 1402312317; - $record->save(); - - $ret = City::deleteAll(['name' => 'Город Тест Тест Второй Тест']); - $this->assertEquals(1, $ret); - $records = City::find()->where(['name' => 'Город Тест Тест Второй Тест'])->all(); - $this->assertEquals(0, count($records)); - } -} diff --git a/erp24/tests/unit/models/ContactFormTest.php b/erp24/tests/unit/models/ContactFormTest.php deleted file mode 100644 index 1bb1bb2d..00000000 --- a/erp24/tests/unit/models/ContactFormTest.php +++ /dev/null @@ -1,41 +0,0 @@ -attributes = [ - 'name' => 'Tester', - 'email' => 'tester@example.com', - 'subject' => 'very important letter subject', - 'body' => 'body of current message', - 'verifyCode' => 'testme', - ]; - - verify($model->contact('admin@example.com'))->notEmpty(); - - // using Yii2 module actions to check email was sent - $this->tester->seeEmailIsSent(); - - /** @var MessageInterface $emailMessage */ - $emailMessage = $this->tester->grabLastSentEmail(); - verify($emailMessage)->instanceOf('yii\mail\MessageInterface'); - verify($emailMessage->getTo())->arrayHasKey('admin@example.com'); - verify($emailMessage->getFrom())->arrayHasKey('noreply@example.com'); - verify($emailMessage->getReplyTo())->arrayHasKey('tester@example.com'); - verify($emailMessage->getSubject())->equals('very important letter subject'); - verify($emailMessage->toString())->stringContainsString('body of current message'); - } -} diff --git a/erp24/tests/unit/models/LoginFormTest.php b/erp24/tests/unit/models/LoginFormTest.php deleted file mode 100644 index 3c1dcdda..00000000 --- a/erp24/tests/unit/models/LoginFormTest.php +++ /dev/null @@ -1,51 +0,0 @@ -user->logout(); - } - - public function testLoginNoUser() - { - $this->model = new LoginForm([ - 'username' => 'not_existing_username', - 'password' => 'not_existing_password', - ]); - - verify($this->model->login())->false(); - verify(\Yii::$app->user->isGuest)->true(); - } - - public function testLoginWrongPassword() - { - $this->model = new LoginForm([ - 'username' => 'demo', - 'password' => 'wrong_password', - ]); - - verify($this->model->login())->false(); - verify(\Yii::$app->user->isGuest)->true(); - verify($this->model->errors)->arrayHasKey('password'); - } - - public function testLoginCorrect() - { - $this->model = new LoginForm([ - 'username' => 'demo', - 'password' => 'demo', - ]); - - verify($this->model->login())->true(); - verify(\Yii::$app->user->isGuest)->false(); - verify($this->model->errors)->arrayHasNotKey('password'); - } - -} -- 2.39.5