Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetDefaultAttributeValueStep.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Fixture\CatalogProductAttribute;
10 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
11 use Magento\Mtf\Fixture\FixtureFactory;
12 use Magento\Mtf\TestStep\TestStepInterface;
13 
17 class SetDefaultAttributeValueStep implements TestStepInterface
18 {
24  protected $attribute;
25 
31  protected $fixtureFactory;
32 
39 
45  protected $attributeValue;
46 
54  public function __construct(
55  CatalogProductAttribute $attribute,
56  CatalogProductEdit $catalogProductEdit,
57  FixtureFactory $fixtureFactory,
58  $attributeValue = null
59  ) {
60  $this->attribute = $attribute;
61  $this->catalogProductEdit = $catalogProductEdit;
62  $this->fixtureFactory = $fixtureFactory;
63  $this->attributeValue = $attributeValue;
64  }
65 
71  public function run()
72  {
73  $customAttribute = $this->attribute;
74  if ($this->attributeValue !== null) {
75  $customAttribute = ['value' => $this->attributeValue, 'attribute' => $customAttribute];
76  }
77  $product = $this->fixtureFactory->createByCode(
78  'catalogProductSimple',
79  ['data' => ['custom_attribute' => $customAttribute]]
80  );
81  $this->catalogProductEdit->getProductForm()->fill($product);
82  }
83 }
__construct(CatalogProductAttribute $attribute, CatalogProductEdit $catalogProductEdit, FixtureFactory $fixtureFactory, $attributeValue=null)