From 207c9e2a4db8751f42ecefb4fb2f67a0c0a0a144 Mon Sep 17 00:00:00 2001 From: Mihail Date: Fri, 13 Nov 2015 10:37:42 +0200 Subject: [PATCH] add details description model and base converter test --- backend/components/.gitignore | 1 + common/models/DetailsCriteria.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/DetailsDescription.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/unit/BaseConverterTest.php | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/unit/CsvParsingTest.php | 31 ------------------------------- 5 files changed, 198 insertions(+), 31 deletions(-) create mode 100644 backend/components/.gitignore create mode 100644 common/models/DetailsCriteria.php create mode 100644 common/models/DetailsDescription.php create mode 100644 tests/unit/BaseConverterTest.php diff --git a/backend/components/.gitignore b/backend/components/.gitignore new file mode 100644 index 0000000..b47e7f9 --- /dev/null +++ b/backend/components/.gitignore @@ -0,0 +1 @@ +/FieldEditor diff --git a/common/models/DetailsCriteria.php b/common/models/DetailsCriteria.php new file mode 100644 index 0000000..3eed639 --- /dev/null +++ b/common/models/DetailsCriteria.php @@ -0,0 +1,58 @@ + 100], + [['key'], 'string', 'max' => 200], + [['value'], 'string', 'max' => 255] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'name' => Yii::t('app', 'Name'), + 'brand' => Yii::t('app', 'Brand'), + 'key' => Yii::t('app', 'Key'), + 'value' => Yii::t('app', 'Value'), + 'if_tecdoc' => Yii::t('app', 'If Tecdoc'), + 'filter_id' => Yii::t('app', 'Filter ID'), + 'timestamp' => Yii::t('app', 'Timestamp'), + ]; + } +} diff --git a/common/models/DetailsDescription.php b/common/models/DetailsDescription.php new file mode 100644 index 0000000..bbd33cf --- /dev/null +++ b/common/models/DetailsDescription.php @@ -0,0 +1,72 @@ + 100], + [['description', 'tecdoc_description'], 'string', 'max' => 255], + [['supplier_description', 'image'], 'string', 'max' => 200], + [['article'], 'string', 'max' => 150], + [['tecdoc_image'], 'string', 'max' => 50] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'ID'), + 'name' => Yii::t('app', 'Name'), + 'brand' => Yii::t('app', 'Brand'), + 'tecdoc_id' => Yii::t('app', 'Tecdoc ID'), + 'tecdoc_article' => Yii::t('app', 'Tecdoc Article'), + 'description' => Yii::t('app', 'Description'), + 'tecdoc_description' => Yii::t('app', 'Tecdoc Description'), + 'supplier_description' => Yii::t('app', 'Supplier Description'), + 'article' => Yii::t('app', 'Article'), + 'image' => Yii::t('app', 'Image'), + 'tecdoc_image' => Yii::t('app', 'Tecdoc Image'), + 'category_id' => Yii::t('app', 'Category ID'), + 'timestamp' => Yii::t('app', 'Timestamp'), + ]; + } +} diff --git a/tests/unit/BaseConverterTest.php b/tests/unit/BaseConverterTest.php new file mode 100644 index 0000000..935e836 --- /dev/null +++ b/tests/unit/BaseConverterTest.php @@ -0,0 +1,67 @@ +converter = new Converter(); + + $this->configuration = ['configuration' => + ["encode" => 'encode', + "string" => ['string1', 'string2' ], + "float" => 'float', + "integer" => ['integer1', 'integer2' ], + ]]; + + $this->wrong_configuration = ['config' => + ["encode" => 'encode', + "string" => 'string', + "float" => 'float', + "integer" => 'integer', + ]]; + + $this->data_in = [ + "encode" => iconv( 'UTF-8', 'windows-1251', 'test encode string' ), + "string1" => 43, + "string2" => 45.45, + "float" => '100.67', + "integer1" => '43.5', + "integer2" => 45.45, + ]; + + + } + + public function testConvertByConfig(){ + + $this->data_out = $this->converter->convertByConfiguration($this->data_in, $this->configuration ); + $this->assertEquals( $this->data_out['encode'], iconv( 'windows-1251', 'UTF-8', 'test encode string' ), 'Encoding failed' ); + $this->assertInternalType( 'float', $this->data_out['float'], 'Convert to float is failed' ); + + } + + public function testConvertToException(){ + + $this->setExpectedException('\Exception'); + $this->data_out = $this->converter->convertByConfiguration($this->data_in, $this->wrong_configuration ); + + } + + + +} \ No newline at end of file diff --git a/tests/unit/CsvParsingTest.php b/tests/unit/CsvParsingTest.php index c91a2b6..2907165 100644 --- a/tests/unit/CsvParsingTest.php +++ b/tests/unit/CsvParsingTest.php @@ -41,38 +41,7 @@ class CsvParsingTest extends \Codeception\TestCase\Test $this->assertNotEmpty( $this->data, 'Output array is empty' ); $this->assertArrayHasKey( 'ARTICLE', $this->data[0], 'Output array don`t have key - ARTICLE' ); } -// public function imagineCustomer(){ -// $fake = \Faker\Factory::create(); -// return [ -// 'name' => $fake->name, -// 'email' => $fake->email, -// 'pass' => $fake->password(19), -// ]; -// -// } -// -// public function testGetUser(){ -// $imagineUser = $this->imagineCustomer(); -// $this->store->addUser($imagineUser['name'],$imagineUser['email'],$imagineUser['pass']); -// $user = $this->store->getUser($imagineUser['email']); -// $this->assertEquals($user['name'], $imagineUser['name']); -// $this->assertEquals($user['email'], $imagineUser['email']); -// $this->assertEquals($user['pass'], $imagineUser['pass']); -// } -// -// public function testAddUser_ShortPass(){ -// $this->setExpectedException('\yii\base\Exception'); -// $this->store->addUser('Some Name','collmail@gig.com','ff'); -// } - protected function _after() - { - } - // tests -// public function testMe() -// { -// -// } } \ No newline at end of file -- libgit2 0.21.4