/**
  * @param $frontendInput
  * @param $frontendClass
  * @param array $eavConfig
  * @param array $expectedResult
  * @return void
  * @dataProvider buildDataProvider
  */
 public function testBuild($frontendInput, $frontendClass, array $eavConfig, array $expectedResult)
 {
     /** @var \Magento\Catalog\Api\Data\ProductAttributeInterface|MockObject $attribute */
     $attribute = $this->getMock(\Magento\Catalog\Api\Data\ProductAttributeInterface::class);
     $attribute->expects($this->once())->method('getFrontendInput')->willReturn($frontendInput);
     $attribute->expects($this->once())->method('getFrontendClass')->willReturn($frontendClass);
     $this->assertEquals($expectedResult, $this->catalogEavValidationRules->build($attribute, $eavConfig));
 }
示例#2
0
 /**
  * Initial meta setup
  *
  * @param ProductAttributeInterface $attribute
  * @param string $groupCode
  * @param int $sortOrder
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @api
  */
 public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupCode, $sortOrder)
 {
     $configPath = ltrim(static::META_CONFIG_PATH, ArrayManager::DEFAULT_PATH_DELIMITER);
     $meta = $this->arrayManager->set($configPath, [], ['dataType' => $attribute->getFrontendInput(), 'formElement' => $this->getFormElementsMapValue($attribute->getFrontendInput()), 'visible' => $attribute->getIsVisible(), 'required' => $attribute->getIsRequired(), 'notice' => $attribute->getNote(), 'default' => $attribute->getDefaultValue(), 'label' => $attribute->getDefaultFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'source' => $groupCode, 'scopeLabel' => $this->getScopeLabel($attribute), 'globalScope' => $this->isScopeGlobal($attribute), 'sortOrder' => $sortOrder * self::SORT_ORDER_MULTIPLIER]);
     // TODO: Refactor to $attribute->getOptions() when MAGETWO-48289 is done
     $attributeModel = $this->getAttributeModel($attribute);
     if ($attributeModel->usesSource()) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['options' => $attributeModel->getSource()->getAllOptions()]);
     }
     if ($this->canDisplayUseDefault($attribute)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['service' => ['template' => 'ui/form/element/helper/service']]);
     }
     if (!$this->arrayManager->exists($configPath . '/componentType', $meta)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['componentType' => Field::NAME]);
     }
     if (in_array($attribute->getAttributeCode(), $this->attributesToDisable)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['disabled' => true]);
     }
     // TODO: getAttributeModel() should not be used when MAGETWO-48284 is complete
     $childData = $this->arrayManager->get($configPath, $meta, []);
     if ($rules = $this->catalogEavValidationRules->build($this->getAttributeModel($attribute), $childData)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['validation' => $rules]);
     }
     $meta = $this->addUseDefaultValueCheckbox($attribute, $meta);
     switch ($attribute->getFrontendInput()) {
         case 'boolean':
             $meta = $this->customizeCheckbox($attribute, $meta);
             break;
         case 'textarea':
             $meta = $this->customizeWysiwyg($attribute, $meta);
             break;
         case 'price':
             $meta = $this->customizePriceAttribute($attribute, $meta);
             break;
         case 'gallery':
             // Gallery attribute is being handled by "Images And Videos" section
             $meta = [];
             break;
     }
     return $meta;
 }