Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateProductAttributeEntityTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Fixture\CatalogProductAttribute;
12 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductAttributeIndex;
13 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductAttributeNew;
14 use Magento\Mtf\Fixture\FixtureFactory;
15 use Magento\Mtf\TestCase\Injectable;
16 
34 class UpdateProductAttributeEntityTest extends Injectable
35 {
36  /* tags */
37  const MVP = 'yes';
38  /* end tags */
39 
45  protected $fixtureFactory;
46 
53  public function __prepare(FixtureFactory $fixtureFactory)
54  {
55  $this->fixtureFactory = $fixtureFactory;
56  }
57 
68  public function testUpdateProductAttribute(
69  CatalogProductAttribute $productAttributeOriginal,
70  CatalogProductAttribute $attribute,
71  CatalogAttributeSet $attributeSet,
72  CatalogProductAttributeIndex $attributeIndex,
73  CatalogProductAttributeNew $attributeNew
74  ) {
75  //Precondition
76  $attributeSet->persist();
77  $productAttributeOriginal->persist();
78 
79  $filter = [
80  'attribute_code' => $productAttributeOriginal->getAttributeCode(),
81  ];
82 
84  $product = $this->fixtureFactory->createByCode(
85  'catalogProductSimple',
86  [
87  'dataset' => 'default',
88  'data' => ['attribute_set_id' => ['attribute_set' => $attributeSet]]
89  ]
90  );
91  $product->persist();
92 
93  $this->objectManager->create(
94  \Magento\Catalog\Test\TestStep\AddAttributeToAttributeSetStep::class,
95  [
96  'attribute' => $productAttributeOriginal,
97  'attributeSet' => $attributeSet
98  ]
99  )->run();
100 
101  //Steps
102  $attributeIndex->open();
103  $attributeIndex->getGrid()->searchAndOpen($filter);
104  $attributeNew->getAttributeForm()->fill($attribute);
105  $attributeNew->getPageActions()->save();
106  $attribute = $this->prepareAttribute($attribute, $productAttributeOriginal);
107 
108  return ['product' => $this->prepareProduct($product, $attribute, $attributeSet)];
109  }
110 
120  {
121  $data = [
122  'attribute_set_id' => ['attribute_set' => $attributeSet],
123  'custom_attribute' => $attribute
124  ];
125  $data = array_merge($data, $product->getData());
126 
127  return $this->fixtureFactory->createByCode('catalogProductSimple', ['data' => $data]);
128  }
129 
137  protected function prepareAttribute($attribute, $productAttributeOriginal)
138  {
139  $attributeData = array_merge($attribute->getData(), $productAttributeOriginal->getData());
140 
141  return $this->fixtureFactory->createByCode('catalogProductAttribute', ['data' => $attributeData]);
142  }
143 }