/** * @param $data * @param $expected * * @dataProvider validateDataProvider */ public function testValidate($data, $expected) { $this->_config->expects($this->exactly(3))->method('getAttribute')->will($this->returnValue($this->attributeCustomerMock)); $this->attributeCustomerMock->expects($this->exactly(3))->method('getIsRequired')->will($this->returnValue(true)); $this->_model->setData($data); $this->assertEquals($expected, $this->_model->validate()); }
/** * @param int $isFilterableInGrid * @param string $frontendInput * @param bool $result * @dataProvider dataProviderCanBeFilterableInGrid */ public function testCanBeFilterableInGrid($isFilterableInGrid, $frontendInput, $result) { $this->attribute->setData('is_filterable_in_grid', $isFilterableInGrid); $this->attribute->setData(AttributeInterface::FRONTEND_INPUT, $frontendInput); $this->assertEquals($result, $this->attribute->canBeFilterableInGrid()); }
/** * Create AttributeMetadata Data object from the Attribute Model * * @param \Magento\Customer\Model\Attribute $attribute * @return \Magento\Customer\Api\Data\AttributeMetadataInterface */ public function createMetadataAttribute($attribute) { $options = []; if ($attribute->usesSource()) { foreach ($attribute->getSource()->getAllOptions() as $option) { $optionDataObject = $this->optionFactory->create(); if (!is_array($option['value'])) { $optionDataObject->setValue($option['value']); } else { $optionArray = []; foreach ($option['value'] as $optionArrayValues) { $optionObject = $this->optionFactory->create(); $this->dataObjectHelper->populateWithArray($optionObject, $optionArrayValues, '\\Magento\\Customer\\Api\\Data\\OptionInterface'); $optionArray[] = $optionObject; } $optionDataObject->setOptions($optionArray); } $optionDataObject->setLabel($option['label']); $options[] = $optionDataObject; } } $validationRules = []; foreach ($attribute->getValidateRules() as $name => $value) { $validationRule = $this->validationRuleFactory->create()->setName($name)->setValue($value); $validationRules[] = $validationRule; } return $this->attributeMetadataFactory->create()->setAttributeCode($attribute->getAttributeCode())->setFrontendInput($attribute->getFrontendInput())->setInputFilter((string) $attribute->getInputFilter())->setStoreLabel($attribute->getStoreLabel())->setValidationRules($validationRules)->setIsVisible((bool) $attribute->getIsVisible())->setIsRequired((bool) $attribute->getIsRequired())->setMultilineCount((int) $attribute->getMultilineCount())->setDataModel((string) $attribute->getDataModel())->setOptions($options)->setFrontendClass($attribute->getFrontend()->getClass())->setFrontendLabel($attribute->getFrontendLabel())->setNote((string) $attribute->getNote())->setIsSystem((bool) $attribute->getIsSystem())->setIsUserDefined((bool) $attribute->getIsUserDefined())->setBackendType($attribute->getBackendType())->setSortOrder((int) $attribute->getSortOrder())->setIsUsedInGrid($attribute->getIsUsedInGrid())->setIsVisibleInGrid($attribute->getIsVisibleInGrid())->setIsFilterableInGrid($attribute->getIsFilterableInGrid())->setIsSearchableInGrid($attribute->getIsSearchableInGrid()); }
/** * Get field type for attribute * * @param Attribute $attribute * @return string */ protected function getType(Attribute $attribute) { if ($attribute->canBeSearchableInGrid()) { $type = 'searchable'; } elseif ($attribute->canBeFilterableInGrid()) { $type = 'filterable'; } else { $type = 'virtual'; } return $type; }
/** * Test method */ public function testAfterDeleteEavCache() { $this->configMock->expects($this->once())->method('clear'); $this->attribute->afterDelete(); }
/** * Create AttributeMetadata Data object from the Attribute Model * * @param \Magento\Customer\Model\Attribute $attribute * @return AttributeMetadata */ public function createMetadataAttribute($attribute) { $options = []; if ($attribute->usesSource()) { foreach ($attribute->getSource()->getAllOptions() as $option) { $options[] = $this->_optionBuilder->setLabel($option['label'])->setValue($option['value'])->create(); } } $validationRules = []; foreach ($attribute->getValidateRules() as $name => $value) { $validationRules[] = $this->_validationRuleBuilder->setName($name)->setValue($value)->create(); } $this->_attributeMetadataBuilder->setAttributeCode($attribute->getAttributeCode())->setFrontendInput($attribute->getFrontendInput())->setInputFilter((string) $attribute->getInputFilter())->setStoreLabel($attribute->getStoreLabel())->setValidationRules($validationRules)->setVisible((bool) $attribute->getIsVisible())->setRequired((bool) $attribute->getIsRequired())->setMultilineCount((int) $attribute->getMultilineCount())->setDataModel((string) $attribute->getDataModel())->setOptions($options)->setFrontendClass($attribute->getFrontend()->getClass())->setFrontendLabel($attribute->getFrontendLabel())->setNote((string) $attribute->getNote())->setIsSystem((bool) $attribute->getIsSystem())->setIsUserDefined((bool) $attribute->getIsUserDefined())->setBackendType($attribute->getBackendType())->setSortOrder((int) $attribute->getSortOrder()); return $this->_attributeMetadataBuilder->create(); }