|
9 | 9 | use Magento\Framework\ObjectManagerInterface;
|
10 | 10 | use Magento\TestFramework\Helper\Bootstrap;
|
11 | 11 | use PHPUnit\Framework\TestCase;
|
| 12 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 13 | +use Magento\Framework\Exception\CouldNotSaveException; |
| 14 | +use Magento\Framework\Exception\InputException; |
| 15 | +use Magento\Framework\Exception\StateException; |
12 | 16 |
|
13 | 17 | class ProductTest extends TestCase
|
14 | 18 | {
|
@@ -53,6 +57,87 @@ public function testGetAttributeRawValue()
|
53 | 57 | self::assertEquals($product->getName(), $actual);
|
54 | 58 | }
|
55 | 59 |
|
| 60 | + /** |
| 61 | + * @magentoAppArea adminhtml |
| 62 | + * @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_store_scope_attribute.php |
| 63 | + * @throws NoSuchEntityException |
| 64 | + * @throws CouldNotSaveException |
| 65 | + * @throws InputException |
| 66 | + * @throws StateException |
| 67 | + */ |
| 68 | + public function testGetAttributeRawValueGetDefault() |
| 69 | + { |
| 70 | + $product = $this->productRepository->get('simple_with_store_scoped_custom_attribute', true, 0, true); |
| 71 | + $product->setCustomAttribute('store_scoped_attribute_code', 'default_value'); |
| 72 | + $this->productRepository->save($product); |
| 73 | + |
| 74 | + $actual = $this->model->getAttributeRawValue($product->getId(), 'store_scoped_attribute_code', 1); |
| 75 | + $this->assertEquals('default_value', $actual); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @magentoAppArea adminhtml |
| 80 | + * @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_store_scope_attribute.php |
| 81 | + * @throws NoSuchEntityException |
| 82 | + * @throws CouldNotSaveException |
| 83 | + * @throws InputException |
| 84 | + * @throws StateException |
| 85 | + */ |
| 86 | + public function testGetAttributeRawValueGetStoreSpecificValueNoDefault() |
| 87 | + { |
| 88 | + $product = $this->productRepository->get('simple_with_store_scoped_custom_attribute', true, 0, true); |
| 89 | + $product->setCustomAttribute('store_scoped_attribute_code', null); |
| 90 | + $this->productRepository->save($product); |
| 91 | + |
| 92 | + $product = $this->productRepository->get('simple_with_store_scoped_custom_attribute', true, 1, true); |
| 93 | + $product->setCustomAttribute('store_scoped_attribute_code', 'store_value'); |
| 94 | + $this->productRepository->save($product); |
| 95 | + |
| 96 | + $actual = $this->model->getAttributeRawValue($product->getId(), 'store_scoped_attribute_code', 1); |
| 97 | + $this->assertEquals('store_value', $actual); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @magentoAppArea adminhtml |
| 102 | + * @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_store_scope_attribute.php |
| 103 | + * @throws NoSuchEntityException |
| 104 | + * @throws CouldNotSaveException |
| 105 | + * @throws InputException |
| 106 | + * @throws StateException |
| 107 | + */ |
| 108 | + public function testGetAttributeRawValueGetStoreSpecificValueWithDefault() |
| 109 | + { |
| 110 | + $product = $this->productRepository->get('simple_with_store_scoped_custom_attribute', true, 0, true); |
| 111 | + $product->setCustomAttribute('store_scoped_attribute_code', 'default_value'); |
| 112 | + $this->productRepository->save($product); |
| 113 | + |
| 114 | + $product = $this->productRepository->get('simple_with_store_scoped_custom_attribute', true, 1, true); |
| 115 | + $product->setCustomAttribute('store_scoped_attribute_code', 'store_value'); |
| 116 | + $this->productRepository->save($product); |
| 117 | + |
| 118 | + $actual = $this->model->getAttributeRawValue($product->getId(), 'store_scoped_attribute_code', 1); |
| 119 | + $this->assertEquals('store_value', $actual); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @magentoAppArea adminhtml |
| 124 | + * @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_store_scope_attribute.php |
| 125 | + * @throws NoSuchEntityException |
| 126 | + * @throws CouldNotSaveException |
| 127 | + * @throws InputException |
| 128 | + * @throws StateException |
| 129 | + * @throws NoSuchEntityException |
| 130 | + */ |
| 131 | + public function testGetAttributeRawValueGetStoreValueFallbackToDefault() |
| 132 | + { |
| 133 | + $product = $this->productRepository->get('simple_with_store_scoped_custom_attribute', true, 0, true); |
| 134 | + $product->setCustomAttribute('store_scoped_attribute_code', 'default_value'); |
| 135 | + $this->productRepository->save($product); |
| 136 | + |
| 137 | + $actual = $this->model->getAttributeRawValue($product->getId(), 'store_scoped_attribute_code', 1); |
| 138 | + $this->assertEquals('default_value', $actual); |
| 139 | + } |
| 140 | + |
56 | 141 | /**
|
57 | 142 | * @magentoAppArea adminhtml
|
58 | 143 | * @magentoDataFixture Magento/Catalog/_files/product_special_price.php
|
|
0 commit comments