Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateProductWithAttributeSetStep.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Fixture\FixtureFactory;
10 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
11 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
13 use Magento\Catalog\Test\Fixture\CatalogProductAttribute;
14 use Magento\Mtf\TestStep\TestStepInterface;
15 
19 class CreateProductWithAttributeSetStep implements TestStepInterface
20 {
26  protected $fixtureFactory;
27 
34 
41 
47  protected $attribute;
48 
54  protected $attributeSet;
55 
61  protected $attributeValue;
62 
72  public function __construct(
73  FixtureFactory $fixtureFactory,
74  CatalogProductIndex $catalogProductIndex,
75  CatalogProductEdit $catalogProductEdit,
76  CatalogProductAttribute $attribute,
77  CatalogAttributeSet $attributeSet,
78  $attributeValue = null
79  ) {
80  $this->fixtureFactory = $fixtureFactory;
81  $this->catalogProductIndex = $catalogProductIndex;
82  $this->catalogProductEdit = $catalogProductEdit;
83  $this->attribute = $attribute;
84  $this->attributeSet = $attributeSet;
85  $this->attributeValue = $attributeValue;
86  }
87 
93  public function run()
94  {
95  // Create product with attribute set mentioned above:
96  $customAttribute = $this->attribute;
97  if ($this->attributeValue !== null) {
98  $customAttribute = ['value' => $this->attributeValue, 'attribute' => $customAttribute];
99  }
100  $product = $this->fixtureFactory->createByCode(
101  'catalogProductSimple',
102  [
103  'dataset' => 'product_with_category_with_anchor',
104  'data' => [
105  'attribute_set_id' => ['attribute_set' => $this->attributeSet],
106  'custom_attribute' => $customAttribute
107  ],
108  ]
109  );
110  $this->catalogProductIndex->open()->getGridPageActionBlock()->addProduct('simple');
111  $productForm = $this->catalogProductEdit->getProductForm();
112  $productForm->fill($product);
113  $this->catalogProductEdit->getFormPageActions()->save();
114 
115  return ['product' => $product];
116  }
117 }
__construct(FixtureFactory $fixtureFactory, CatalogProductIndex $catalogProductIndex, CatalogProductEdit $catalogProductEdit, CatalogProductAttribute $attribute, CatalogAttributeSet $attributeSet, $attributeValue=null)