Skip to content

Commit feac134

Browse files
committed
MC-23203: Admin: Simple product with all custom attributes
1 parent 806576a commit feac134

File tree

11 files changed

+61
-44
lines changed

11 files changed

+61
-44
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AbstractAttributeTest.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1111
use Magento\Catalog\Api\Data\ProductInterface;
1212
use Magento\Catalog\Api\ProductRepositoryInterface;
13-
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1413
use Magento\Eav\Api\AttributeRepositoryInterface;
1514
use Magento\Eav\Model\Entity\Attribute\Exception;
1615
use Magento\Framework\ObjectManagerInterface;
@@ -31,7 +30,7 @@ abstract class AbstractAttributeTest extends TestCase
3130
/** @var ProductRepositoryInterface */
3231
protected $productRepository;
3332

34-
/** @var Attribute */
33+
/** @var ProductAttributeInterface */
3534
protected $attribute;
3635

3736
/**
@@ -44,10 +43,6 @@ protected function setUp()
4443
$this->objectManager = Bootstrap::getObjectManager();
4544
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
4645
$this->attributeRepository = $this->objectManager->create(AttributeRepositoryInterface::class);
47-
$this->attribute = $this->attributeRepository->get(
48-
ProductAttributeInterface::ENTITY_TYPE_CODE,
49-
$this->getAttributeCode()
50-
);
5146
}
5247

5348
/**
@@ -71,7 +66,9 @@ public function testRequiredAttribute(string $productSku): void
7166
{
7267
$this->expectException(Exception::class);
7368
$messageFormat = 'The "%s" attribute value is empty. Set the attribute and try again.';
74-
$this->expectExceptionMessage((string)__(sprintf($messageFormat, $this->attribute->getDefaultFrontendLabel())));
69+
$this->expectExceptionMessage(
70+
(string)__(sprintf($messageFormat, $this->getAttribute()->getDefaultFrontendLabel()))
71+
);
7572
$this->prepareAttribute(['is_required' => true]);
7673
$this->unsetAttributeValueAndValidate($productSku);
7774
}
@@ -90,7 +87,7 @@ public function testDefaultValue(string $productSku): void
9087
}
9188

9289
/**
93-
* @dataProvider uniqueTestProvider
90+
* @dataProvider uniqueAttributeValueProvider
9491
* @param string $firstSku
9592
* @param string $secondSku
9693
* @return void
@@ -99,13 +96,32 @@ public function testUniqueAttribute(string $firstSku, string $secondSku): void
9996
{
10097
$this->expectException(Exception::class);
10198
$messageFormat = 'The value of the "%s" attribute isn\'t unique. Set a unique value and try again.';
102-
$this->expectExceptionMessage((string)__(sprintf($messageFormat, $this->attribute->getDefaultFrontendLabel())));
99+
$this->expectExceptionMessage(
100+
(string)__(sprintf($messageFormat, $this->getAttribute()->getDefaultFrontendLabel()))
101+
);
103102
$this->prepareAttribute(['is_unique' => 1]);
104103
$product = $this->setAttributeValueAndValidate($firstSku, $this->getDefaultAttributeValue());
105104
$this->productRepository->save($product);
106105
$this->setAttributeValueAndValidate($secondSku, $this->getDefaultAttributeValue());
107106
}
108107

108+
/**
109+
* Get attribute
110+
*
111+
* @return ProductAttributeInterface
112+
*/
113+
protected function getAttribute(): ProductAttributeInterface
114+
{
115+
if ($this->attribute === null) {
116+
$this->attribute = $this->attributeRepository->get(
117+
ProductAttributeInterface::ENTITY_TYPE_CODE,
118+
$this->getAttributeCode()
119+
);
120+
}
121+
122+
return $this->attribute;
123+
}
124+
109125
/**
110126
* Set attribute value to product and validate the product
111127
*
@@ -145,10 +161,7 @@ private function unsetAttributeValueAndValidate(string $productSku): ProductInte
145161
*/
146162
private function prepareAttribute(array $data): void
147163
{
148-
$attribute = $this->attributeRepository->get(
149-
ProductAttributeInterface::ENTITY_TYPE_CODE,
150-
$this->getAttributeCode()
151-
);
164+
$attribute = $this->getAttribute();
152165
$attribute->addData($data);
153166
$this->attributeRepository->save($attribute);
154167
}
@@ -179,5 +192,5 @@ abstract public function productProvider(): array;
179192
*
180193
* @return array
181194
*/
182-
abstract public function uniqueTestProvider(): array;
195+
abstract public function uniqueAttributeValueProvider(): array;
183196
}

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributeDateTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ protected function getAttributeCode(): string
3636
*/
3737
protected function getDefaultAttributeValue(): string
3838
{
39-
return $this->attribute->getBackend()->formatDate('11/20/19');
39+
return $this->getAttribute()->getBackend()->formatDate('11/20/19');
4040
}
4141

4242
/**
4343
* @magentoDataFixture Magento/Catalog/_files/product_date_attribute.php
4444
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
4545
* @magentoDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
46-
* @dataProvider uniqueTestProvider
46+
* @dataProvider uniqueAttributeValueProvider
4747
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
4848
* @inheritdoc
4949
*/
@@ -67,7 +67,7 @@ public function productProvider(): array
6767
/**
6868
* @inheritdoc
6969
*/
70-
public function uniqueTestProvider(): array
70+
public function uniqueAttributeValueProvider(): array
7171
{
7272
return [
7373
[

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributeDropdownTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ protected function getAttributeCode(): string
2727
*/
2828
protected function getDefaultAttributeValue(): string
2929
{
30-
return $this->attribute->getSource()->getOptionId('Option 1');
30+
return $this->getAttribute()->getSource()->getOptionId('Option 1');
3131
}
3232

3333
/**
3434
* @magentoDataFixture Magento/Catalog/_files/dropdown_attribute.php
3535
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
3636
* @magentoDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
37-
* @dataProvider uniqueTestProvider
37+
* @dataProvider uniqueAttributeValueProvider
3838
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
3939
* @inheritdoc
4040
*/
@@ -58,7 +58,7 @@ public function productProvider(): array
5858
/**
5959
* @inheritdoc
6060
*/
61-
public function uniqueTestProvider(): array
61+
public function uniqueAttributeValueProvider(): array
6262
{
6363
return [
6464
[

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributeMultiSelectTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function getAttributeCode(): string
2727
*/
2828
protected function getDefaultAttributeValue(): string
2929
{
30-
return $this->attribute->getSource()->getOptionId('Option 1');
30+
return $this->getAttribute()->getSource()->getOptionId('Option 1');
3131
}
3232

3333
/**
@@ -43,7 +43,7 @@ public function testDefaultValue(string $productSku): void
4343
* @magentoDataFixture Magento/Catalog/_files/multiselect_attribute.php
4444
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
4545
* @magentoDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
46-
* @dataProvider uniqueTestProvider
46+
* @dataProvider uniqueAttributeValueProvider
4747
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
4848
* @inheritdoc
4949
*/
@@ -67,7 +67,7 @@ public function productProvider(): array
6767
/**
6868
* @inheritdoc
6969
*/
70-
public function uniqueTestProvider(): array
70+
public function uniqueAttributeValueProvider(): array
7171
{
7272
return [
7373
[

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributePriceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class AttributePriceTest extends AbstractAttributeTest
2020
* @magentoDataFixture Magento/Catalog/_files/product_decimal_attribute.php
2121
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
2222
* @magentoDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
23-
* @dataProvider uniqueTestProvider
23+
* @dataProvider uniqueAttributeValueProvider
2424
* @inheritdoc
2525
*/
2626
public function testUniqueAttribute(string $firstSku, string $secondSku): void
2727
{
28-
$this->markTestSkipped('Test is blocked by issue MC-29019');
28+
$this->markTestSkipped('Test is blocked by issue MC-29018');
2929
parent::testUniqueAttribute($firstSku, $secondSku);
3030
}
3131

@@ -65,7 +65,7 @@ public function productProvider(): array
6565
/**
6666
* @inheritdoc
6767
*/
68-
public function uniqueTestProvider(): array
68+
public function uniqueAttributeValueProvider(): array
6969
{
7070
return [
7171
[

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributeTextAreaTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function getDefaultAttributeValue(): string
3434
* @magentoDataFixture Magento/Catalog/_files/product_text_attribute.php
3535
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
3636
* @magentoDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
37-
* @dataProvider uniqueTestProvider
37+
* @dataProvider uniqueAttributeValueProvider
3838
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
3939
* @inheritdoc
4040
*/
@@ -58,7 +58,7 @@ public function productProvider(): array
5858
/**
5959
* @inheritdoc
6060
*/
61-
public function uniqueTestProvider(): array
61+
public function uniqueAttributeValueProvider(): array
6262
{
6363
return [
6464
[

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributeTextTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function getDefaultAttributeValue(): string
3434
* @magentoDataFixture Magento/Catalog/_files/product_varchar_attribute.php
3535
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
3636
* @magentoDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
37-
* @dataProvider uniqueTestProvider
37+
* @dataProvider uniqueAttributeValueProvider
3838
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
3939
* @inheritdoc
4040
*/
@@ -58,7 +58,7 @@ public function productProvider(): array
5858
/**
5959
* @inheritdoc
6060
*/
61-
public function uniqueTestProvider(): array
61+
public function uniqueAttributeValueProvider(): array
6262
{
6363
return [
6464
[

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributeYesNoTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function getDefaultAttributeValue(): string
3434
* @magentoDataFixture Magento/Catalog/_files/product_boolean_attribute.php
3535
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
3636
* @magentoDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
37-
* @dataProvider uniqueTestProvider
37+
* @dataProvider uniqueAttributeValueProvider
3838
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
3939
* @inheritdoc
4040
*/
@@ -58,7 +58,7 @@ public function productProvider(): array
5858
/**
5959
* @inheritdoc
6060
*/
61-
public function uniqueTestProvider(): array
61+
public function uniqueAttributeValueProvider(): array
6262
{
6363
return [
6464
[
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\Catalog\Model\Product\Attribute\Save;
8+
namespace Magento\Swatches\Model;
9+
10+
use Magento\Catalog\Model\Product\Attribute\Save\AbstractAttributeTest;
911

1012
/**
1113
* @magentoDbIsolation enabled
@@ -27,14 +29,14 @@ protected function getAttributeCode(): string
2729
*/
2830
protected function getDefaultAttributeValue(): string
2931
{
30-
return $this->attribute->getSource()->getOptionId('Option 2');
32+
return $this->getAttribute()->getSource()->getOptionId('Option 2');
3133
}
3234

3335
/**
3436
* @magentoDataFixture Magento/Swatches/_files/product_text_swatch_attribute.php
3537
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
3638
* @magentoDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
37-
* @dataProvider uniqueTestProvider
39+
* @dataProvider uniqueAttributeValueProvider
3840
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
3941
* @inheritdoc
4042
*/
@@ -58,7 +60,7 @@ public function productProvider(): array
5860
/**
5961
* @inheritdoc
6062
*/
61-
public function uniqueTestProvider(): array
63+
public function uniqueAttributeValueProvider(): array
6264
{
6365
return [
6466
[
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\Catalog\Model\Product\Attribute\Save;
8+
namespace Magento\Swatches\Model;
9+
10+
use Magento\Catalog\Model\Product\Attribute\Save\AbstractAttributeTest;
911

1012
/**
1113
* @magentoDbIsolation enabled
@@ -27,14 +29,14 @@ protected function getAttributeCode(): string
2729
*/
2830
protected function getDefaultAttributeValue(): string
2931
{
30-
return $this->attribute->getSource()->getOptionId('option 2');
32+
return $this->getAttribute()->getSource()->getOptionId('option 2');
3133
}
3234

3335
/**
3436
* @magentoDataFixture Magento/Swatches/_files/product_visual_swatch_attribute.php
3537
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
3638
* @magentoDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
37-
* @dataProvider uniqueTestProvider
39+
* @dataProvider uniqueAttributeValueProvider
3840
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
3941
* @inheritdoc
4042
*/
@@ -58,7 +60,7 @@ public function productProvider(): array
5860
/**
5961
* @inheritdoc
6062
*/
61-
public function uniqueTestProvider(): array
63+
public function uniqueAttributeValueProvider(): array
6264
{
6365
return [
6466
[

0 commit comments

Comments
 (0)