12 use PHPUnit_Framework_MockObject_MockObject as MockObject;
33 $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
34 $this->model = $objectHelper->getObject(AttributeFilter::class);
44 public function testPrepareProductAttributes(
51 $productMockMap = $this->getMockBuilder(Product::class)
52 ->disableOriginalConstructor()
53 ->setMethods([
'getData',
'getAttributes'])
56 if (!empty($initialProductData)) {
57 $productMockMap->expects($this->any())->method(
'getData')->willReturnMap($initialProductData);
62 ->expects($this->once())
63 ->method(
'getAttributes')
65 $this->getProductAttributesMock($useDefaults)
69 $actualProductData = $this->model->prepareProductAttributes($productMockMap, $requestProductData, $useDefaults);
70 $this->assertEquals($expectedProductData, $actualProductData);
80 'create_new_product' => [
88 'expectedProductData' => [
93 'initialProductData' => [],
95 'update_product_without_use_defaults' => [
97 'name' =>
'testName2',
101 'special_price' =>
null,
104 'expectedProductData' => [
105 'name' =>
'testName2',
108 'special_price' =>
null,
110 'initialProductData' => [
111 [
'name',
'testName2'],
114 [
'special_price',
null],
117 'update_product_without_use_defaults_2' => [
119 'name' =>
'testName2',
122 'description' =>
'updated description',
123 'special_price' =>
null,
126 'expectedProductData' => [
127 'name' =>
'testName2',
130 'description' =>
'updated description',
131 'special_price' =>
null,
133 'initialProductData' => [
134 [
'name',
'testName2'],
137 [
'special_price',
null],
140 'update_product_with_use_defaults' => [
142 'name' =>
'testName2',
146 'special_price' =>
null,
149 'description' =>
'0',
151 'expectedProductData' => [
152 'name' =>
'testName2',
155 'special_price' =>
null,
158 'initialProductData' => [
159 [
'name',
'testName2'],
162 [
'special_price',
null],
163 [
'description',
'descr text'],
166 'update_product_with_use_defaults_2' => [
167 'requestProductData' => [
168 'name' =>
'testName3',
171 'description' =>
'descr modified',
172 'special_price' =>
'100',
175 'description' =>
'0',
177 'expectedProductData' => [
178 'name' =>
'testName3',
181 'special_price' =>
'100',
182 'description' =>
'descr modified',
184 'initialProductData' => [
185 [
'name',
null,
'testName2'],
186 [
'sku',
null,
'testSku2'],
187 [
'price',
null,
'101'],
188 [
'description',
null,
'descr text'],
191 'update_product_with_use_defaults_3' => [
192 'requestProductData' => [
193 'name' =>
'testName3',
196 'special_price' =>
'100',
197 'description' =>
'descr modified',
200 'description' =>
'1',
202 'expectedProductData' => [
203 'name' =>
'testName3',
206 'special_price' =>
'100',
207 'description' =>
false,
209 'initialProductData' => [
210 [
'name',
null,
'testName2'],
211 [
'sku',
null,
'testSku2'],
212 [
'price',
null,
'101'],
213 [
'description',
null,
'descr text'],
223 private function getProductAttributesMock(array $useDefaults): array
226 foreach ($useDefaults as $attributecode => $isDefault) {
227 if ($isDefault ===
'1') {
229 $attribute = $this->getMockBuilder(Attribute::class)
230 ->disableOriginalConstructor()
233 ->method(
'getBackendType')
234 ->willReturn(
'varchar');