Commit 207c9e2a4db8751f42ecefb4fb2f67a0c0a0a144
1 parent
61795805
add details description model and base converter test
Showing
5 changed files
with
198 additions
and
31 deletions
Show diff stats
| 1 | +/FieldEditor |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace common\models; | ||
| 4 | + | ||
| 5 | +use Yii; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * This is the model class for table "{{%details_criteria}}". | ||
| 9 | + * | ||
| 10 | + * @property string $name | ||
| 11 | + * @property string $brand | ||
| 12 | + * @property string $key | ||
| 13 | + * @property string $value | ||
| 14 | + * @property integer $if_tecdoc | ||
| 15 | + * @property string $filter_id | ||
| 16 | + * @property string $timestamp | ||
| 17 | + */ | ||
| 18 | +class DetailsCriteria extends \backend\components\base\BaseActiveRecord | ||
| 19 | +{ | ||
| 20 | + /** | ||
| 21 | + * @inheritdoc | ||
| 22 | + */ | ||
| 23 | + public static function tableName() | ||
| 24 | + { | ||
| 25 | + return '{{%details_criteria}}'; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * @inheritdoc | ||
| 30 | + */ | ||
| 31 | + public function rules() | ||
| 32 | + { | ||
| 33 | + return [ | ||
| 34 | + [['name', 'brand', 'key', 'value'], 'required'], | ||
| 35 | + [['if_tecdoc', 'filter_id'], 'integer'], | ||
| 36 | + [['timestamp'], 'safe'], | ||
| 37 | + [['name', 'brand'], 'string', 'max' => 100], | ||
| 38 | + [['key'], 'string', 'max' => 200], | ||
| 39 | + [['value'], 'string', 'max' => 255] | ||
| 40 | + ]; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * @inheritdoc | ||
| 45 | + */ | ||
| 46 | + public function attributeLabels() | ||
| 47 | + { | ||
| 48 | + return [ | ||
| 49 | + 'name' => Yii::t('app', 'Name'), | ||
| 50 | + 'brand' => Yii::t('app', 'Brand'), | ||
| 51 | + 'key' => Yii::t('app', 'Key'), | ||
| 52 | + 'value' => Yii::t('app', 'Value'), | ||
| 53 | + 'if_tecdoc' => Yii::t('app', 'If Tecdoc'), | ||
| 54 | + 'filter_id' => Yii::t('app', 'Filter ID'), | ||
| 55 | + 'timestamp' => Yii::t('app', 'Timestamp'), | ||
| 56 | + ]; | ||
| 57 | + } | ||
| 58 | +} |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace common\models; | ||
| 4 | + | ||
| 5 | +use Yii; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * This is the model class for table "{{%details_description}}". | ||
| 9 | + * | ||
| 10 | + * @property string $id | ||
| 11 | + * @property string $name | ||
| 12 | + * @property string $brand | ||
| 13 | + * @property string $tecdoc_id | ||
| 14 | + * @property string $tecdoc_article | ||
| 15 | + * @property string $description | ||
| 16 | + * @property string $tecdoc_description | ||
| 17 | + * @property string $supplier_description | ||
| 18 | + * @property string $article | ||
| 19 | + * @property string $image | ||
| 20 | + * @property string $tecdoc_image | ||
| 21 | + * @property string $category_id | ||
| 22 | + * @property string $timestamp | ||
| 23 | + */ | ||
| 24 | +class DetailsDescription extends \backend\components\base\BaseActiveRecord | ||
| 25 | +{ | ||
| 26 | + /** | ||
| 27 | + * @inheritdoc | ||
| 28 | + */ | ||
| 29 | + public static function tableName() | ||
| 30 | + { | ||
| 31 | + return '{{%details_description}}'; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * @inheritdoc | ||
| 36 | + */ | ||
| 37 | + public function rules() | ||
| 38 | + { | ||
| 39 | + return [ | ||
| 40 | + [['name', 'brand'], 'required'], | ||
| 41 | + [['tecdoc_id', 'category_id'], 'integer'], | ||
| 42 | + [['timestamp'], 'safe'], | ||
| 43 | + [['name', 'brand', 'tecdoc_article'], 'string', 'max' => 100], | ||
| 44 | + [['description', 'tecdoc_description'], 'string', 'max' => 255], | ||
| 45 | + [['supplier_description', 'image'], 'string', 'max' => 200], | ||
| 46 | + [['article'], 'string', 'max' => 150], | ||
| 47 | + [['tecdoc_image'], 'string', 'max' => 50] | ||
| 48 | + ]; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * @inheritdoc | ||
| 53 | + */ | ||
| 54 | + public function attributeLabels() | ||
| 55 | + { | ||
| 56 | + return [ | ||
| 57 | + 'id' => Yii::t('app', 'ID'), | ||
| 58 | + 'name' => Yii::t('app', 'Name'), | ||
| 59 | + 'brand' => Yii::t('app', 'Brand'), | ||
| 60 | + 'tecdoc_id' => Yii::t('app', 'Tecdoc ID'), | ||
| 61 | + 'tecdoc_article' => Yii::t('app', 'Tecdoc Article'), | ||
| 62 | + 'description' => Yii::t('app', 'Description'), | ||
| 63 | + 'tecdoc_description' => Yii::t('app', 'Tecdoc Description'), | ||
| 64 | + 'supplier_description' => Yii::t('app', 'Supplier Description'), | ||
| 65 | + 'article' => Yii::t('app', 'Article'), | ||
| 66 | + 'image' => Yii::t('app', 'Image'), | ||
| 67 | + 'tecdoc_image' => Yii::t('app', 'Tecdoc Image'), | ||
| 68 | + 'category_id' => Yii::t('app', 'Category ID'), | ||
| 69 | + 'timestamp' => Yii::t('app', 'Timestamp'), | ||
| 70 | + ]; | ||
| 71 | + } | ||
| 72 | +} |
| 1 | +<?php | ||
| 2 | +namespace tests\unit; | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +use Yii; | ||
| 6 | +use yii\multiparser\Converter; | ||
| 7 | + | ||
| 8 | +class BaseConverterTest extends \Codeception\TestCase\Test | ||
| 9 | +{ | ||
| 10 | + /** | ||
| 11 | + * @var \UnitTester | ||
| 12 | + */ | ||
| 13 | + | ||
| 14 | + private $converter; | ||
| 15 | + private $configuration; | ||
| 16 | + private $wrong_configuration; | ||
| 17 | + private $data_in; | ||
| 18 | + private $data_out; | ||
| 19 | + | ||
| 20 | + public function _before() | ||
| 21 | + { | ||
| 22 | + $this->converter = new Converter(); | ||
| 23 | + | ||
| 24 | + $this->configuration = ['configuration' => | ||
| 25 | + ["encode" => 'encode', | ||
| 26 | + "string" => ['string1', 'string2' ], | ||
| 27 | + "float" => 'float', | ||
| 28 | + "integer" => ['integer1', 'integer2' ], | ||
| 29 | + ]]; | ||
| 30 | + | ||
| 31 | + $this->wrong_configuration = ['config' => | ||
| 32 | + ["encode" => 'encode', | ||
| 33 | + "string" => 'string', | ||
| 34 | + "float" => 'float', | ||
| 35 | + "integer" => 'integer', | ||
| 36 | + ]]; | ||
| 37 | + | ||
| 38 | + $this->data_in = [ | ||
| 39 | + "encode" => iconv( 'UTF-8', 'windows-1251', 'test encode string' ), | ||
| 40 | + "string1" => 43, | ||
| 41 | + "string2" => 45.45, | ||
| 42 | + "float" => '100.67', | ||
| 43 | + "integer1" => '43.5', | ||
| 44 | + "integer2" => 45.45, | ||
| 45 | + ]; | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public function testConvertByConfig(){ | ||
| 51 | + | ||
| 52 | + $this->data_out = $this->converter->convertByConfiguration($this->data_in, $this->configuration ); | ||
| 53 | + $this->assertEquals( $this->data_out['encode'], iconv( 'windows-1251', 'UTF-8', 'test encode string' ), 'Encoding failed' ); | ||
| 54 | + $this->assertInternalType( 'float', $this->data_out['float'], 'Convert to float is failed' ); | ||
| 55 | + | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public function testConvertToException(){ | ||
| 59 | + | ||
| 60 | + $this->setExpectedException('\Exception'); | ||
| 61 | + $this->data_out = $this->converter->convertByConfiguration($this->data_in, $this->wrong_configuration ); | ||
| 62 | + | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + | ||
| 67 | +} | ||
| 0 | \ No newline at end of file | 68 | \ No newline at end of file |
tests/unit/CsvParsingTest.php
| @@ -41,38 +41,7 @@ class CsvParsingTest extends \Codeception\TestCase\Test | @@ -41,38 +41,7 @@ class CsvParsingTest extends \Codeception\TestCase\Test | ||
| 41 | $this->assertNotEmpty( $this->data, 'Output array is empty' ); | 41 | $this->assertNotEmpty( $this->data, 'Output array is empty' ); |
| 42 | $this->assertArrayHasKey( 'ARTICLE', $this->data[0], 'Output array don`t have key - ARTICLE' ); | 42 | $this->assertArrayHasKey( 'ARTICLE', $this->data[0], 'Output array don`t have key - ARTICLE' ); |
| 43 | } | 43 | } |
| 44 | -// public function imagineCustomer(){ | ||
| 45 | -// $fake = \Faker\Factory::create(); | ||
| 46 | -// return [ | ||
| 47 | -// 'name' => $fake->name, | ||
| 48 | -// 'email' => $fake->email, | ||
| 49 | -// 'pass' => $fake->password(19), | ||
| 50 | -// ]; | ||
| 51 | -// | ||
| 52 | -// } | ||
| 53 | -// | ||
| 54 | -// public function testGetUser(){ | ||
| 55 | -// $imagineUser = $this->imagineCustomer(); | ||
| 56 | -// $this->store->addUser($imagineUser['name'],$imagineUser['email'],$imagineUser['pass']); | ||
| 57 | -// $user = $this->store->getUser($imagineUser['email']); | ||
| 58 | -// $this->assertEquals($user['name'], $imagineUser['name']); | ||
| 59 | -// $this->assertEquals($user['email'], $imagineUser['email']); | ||
| 60 | -// $this->assertEquals($user['pass'], $imagineUser['pass']); | ||
| 61 | -// } | ||
| 62 | -// | ||
| 63 | -// public function testAddUser_ShortPass(){ | ||
| 64 | -// $this->setExpectedException('\yii\base\Exception'); | ||
| 65 | -// $this->store->addUser('Some Name','collmail@gig.com','ff'); | ||
| 66 | -// } | ||
| 67 | 44 | ||
| 68 | - protected function _after() | ||
| 69 | - { | ||
| 70 | - } | ||
| 71 | 45 | ||
| 72 | - // tests | ||
| 73 | -// public function testMe() | ||
| 74 | -// { | ||
| 75 | -// | ||
| 76 | -// } | ||
| 77 | 46 | ||
| 78 | } | 47 | } |
| 79 | \ No newline at end of file | 48 | \ No newline at end of file |