Exemplo n.º 1
0
 public function testApplyEditing()
 {
     $this->column->expects($this->once())->method('getConfiguration')->willReturn(['dataType' => 'text', 'visible' => true]);
     $this->validationRules->expects($this->once())->method('getValidationRules')->with(true, [$this->validationRule])->willReturn(['validate-email' => true, 'required-entry' => true]);
     $this->column->expects($this->once())->method('setData')->with('config', ['dataType' => 'text', 'visible' => true, 'editor' => ['editorType' => 'text', 'validation' => ['validate-email' => true, 'required-entry' => true]]]);
     $this->component->applyEditing($this->column, 'text', [$this->validationRule], true);
 }
 public function testCreate()
 {
     $columnName = 'created_at';
     $config = ['data' => ['js_config' => ['component' => 'Magento_Ui/js/grid/columns/column'], 'config' => ['label' => __('Label'), 'dataType' => 'text', 'align' => 'left', 'visible' => true, 'options' => [['label' => 'Label', 'value' => 'Value']], 'component' => 'Magento_Ui/js/grid/columns/column']], 'context' => $this->context];
     $attributeData = ['attribute_code' => 'billing_attribute_code', 'frontend_input' => 'text', 'frontend_label' => 'Label', 'backend_type' => 'backend-type', 'options' => [['label' => 'Label', 'value' => 'Value']], 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true, 'entity_type_code' => 'customer', 'validation_rules' => [], 'required' => false];
     $this->inlineEditUpdater->expects($this->once())->method('applyEditing')->with($this->column, 'text', []);
     $this->componentFactory->expects($this->once())->method('create')->with($columnName, 'column', $config)->willReturn($this->column);
     $this->assertSame($this->column, $this->columnFactory->create($attributeData, $columnName, $this->context));
 }
Exemplo n.º 3
0
 /**
  * @param array $attributeData
  * @param string $columnName
  * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
  * @param array $config
  * @return \Magento\Ui\Component\Listing\Columns\ColumnInterface
  */
 public function create(array $attributeData, $columnName, $context, array $config = [])
 {
     $config = array_merge(['label' => __($attributeData[AttributeMetadata::FRONTEND_LABEL]), 'dataType' => $this->getDataType($attributeData[AttributeMetadata::FRONTEND_INPUT]), 'align' => 'left', 'visible' => (bool) $attributeData[AttributeMetadata::IS_VISIBLE_IN_GRID]], $config);
     if (count($attributeData[AttributeMetadata::OPTIONS]) && !isset($config[AttributeMetadata::OPTIONS])) {
         $config[AttributeMetadata::OPTIONS] = $attributeData[AttributeMetadata::OPTIONS];
     }
     if ($attributeData[AttributeMetadata::OPTIONS]) {
         $config['options'] = $attributeData[AttributeMetadata::OPTIONS];
     }
     $arguments = ['data' => ['js_config' => ['component' => $this->getJsComponent($config['dataType'])], 'config' => $config], 'context' => $context];
     $column = $this->componentFactory->create($columnName, 'column', $arguments);
     $this->inlineEditUpdater->applyEditing($column, $attributeData[AttributeMetadata::FRONTEND_INPUT], $attributeData[AttributeMetadata::VALIDATION_RULES], $attributeData[AttributeMetadata::REQUIRED]);
     return $column;
 }
Exemplo n.º 4
0
 public function testPrepareWithUpdateStaticColumn()
 {
     $attributeCode = 'billing_attribute_code';
     $backendType = 'static';
     $attributeData = ['attribute_code' => 'billing_attribute_code', 'frontend_input' => 'text', 'frontend_label' => 'frontend-label', 'backend_type' => $backendType, 'options' => [['label' => 'Label', 'value' => 'Value']], 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true, 'validation_rules' => [], 'required' => false, 'entity_type_code' => 'customer'];
     $this->inlineEditUpdater->expects($this->once())->method('applyEditing')->with($this->column, 'text', [], false);
     $this->attributeRepository->expects($this->atLeastOnce())->method('getList')->willReturn([$attributeCode => $attributeData]);
     $this->columnFactory->expects($this->once())->method('create')->willReturn($this->column);
     $this->column->expects($this->once())->method('prepare');
     $this->column->expects($this->atLeastOnce())->method('getData')->with('config')->willReturn(['editor' => 'text']);
     $this->column->expects($this->at(3))->method('setData')->with('config', ['editor' => 'text', 'options' => [['label' => 'Label', 'value' => 'Value']]]);
     $this->column->expects($this->at(6))->method('setData')->with('config', ['editor' => 'text', 'visible' => true]);
     $this->component->addColumn($attributeData, $attributeCode);
     $this->component->prepare();
 }
Exemplo n.º 5
0
 /**
  * @param array $attributeData
  * @param string $newAttributeCode
  * @return void
  */
 public function updateColumn(array $attributeData, $newAttributeCode)
 {
     $component = $this->components[$attributeData[AttributeMetadata::ATTRIBUTE_CODE]];
     $this->addOptions($component, $attributeData);
     if ($attributeData[AttributeMetadata::BACKEND_TYPE] != 'static') {
         if ($attributeData[AttributeMetadata::IS_USED_IN_GRID]) {
             $config = array_merge($component->getData('config'), ['name' => $newAttributeCode, 'dataType' => $attributeData[AttributeMetadata::BACKEND_TYPE], 'visible' => (bool) $attributeData[AttributeMetadata::IS_VISIBLE_IN_GRID]]);
             $component->setData('config', $config);
         }
     } else {
         if ($attributeData['entity_type_code'] == CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER && !empty($component->getData('config')['editor'])) {
             $this->inlineEditUpdater->applyEditing($component, $attributeData[AttributeMetadata::FRONTEND_INPUT], $attributeData[AttributeMetadata::VALIDATION_RULES], $attributeData[AttributeMetadata::REQUIRED]);
         }
         $component->setData('config', array_merge($component->getData('config'), ['visible' => (bool) $attributeData[AttributeMetadata::IS_VISIBLE_IN_GRID]]));
     }
 }