/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testGetConfigurableOptions() { $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); /** @var Configurable|\PHPUnit_Framework_MockObject_MockObject $configurable */ $configurable = $this->getMockBuilder(Configurable::class)->setMethods(['getTable', 'getConnection'])->setConstructorArgs([$context, $this->relation])->getMock(); $reflection = new \ReflectionClass(Configurable::class); $reflectionProperty = $reflection->getProperty('metadataPool'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($configurable, $this->metadataPoolMock); /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */ $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->setMethods(['__sleep', '__wakeup', 'getData'])->disableOriginalConstructor()->getMock(); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn('link'); $product->expects($this->once())->method('getData')->with('link')->willReturn('getId value'); $configurable->expects($this->exactly(7))->method('getTable')->will($this->returnValueMap([['catalog_product_super_attribute', 'catalog_product_super_attribute value'], ['catalog_product_entity', 'catalog_product_entity value'], ['catalog_product_super_link', 'catalog_product_super_link value'], ['eav_attribute', 'eav_attribute value'], ['catalog_product_entity', 'catalog_product_entity value'], ['eav_attribute_option_value', 'eav_attribute_option_value value'], ['catalog_product_super_attribute_label', 'catalog_product_super_attribute_label value']])); $select = $this->getMock(\Magento\Framework\DB\Select::class, ['from', 'joinInner', 'joinLeft', 'where'], [], '', false); $select->expects($this->once())->method('from')->with(['super_attribute' => 'catalog_product_super_attribute value'], ['sku' => 'entity.sku', 'product_id' => 'product_entity.entity_id', 'attribute_code' => 'attribute.attribute_code', 'option_title' => 'option_value.value', 'super_attribute_label' => 'attribute_label.value'])->will($this->returnSelf()); $superAttribute = $this->getMock(\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute::class, ['getBackendTable', 'getAttributeId'], [], '', false); $superAttribute->expects($this->once())->method('getBackendTable')->willReturn('getBackendTable value'); $superAttribute->expects($this->once())->method('getAttributeId')->willReturn('getAttributeId value'); $attributes = [$superAttribute]; $select->expects($this->exactly(5))->method('joinInner')->will($this->returnSelf())->withConsecutive([['product_entity' => 'catalog_product_entity value'], 'product_entity.link = super_attribute.product_id', []], [['product_link' => 'catalog_product_super_link value'], 'product_link.parent_id = super_attribute.product_id', []], [['attribute' => 'eav_attribute value'], 'attribute.attribute_id = super_attribute.attribute_id', []], [['entity' => 'catalog_product_entity value'], 'entity.entity_id = product_link.product_id', []], [['entity_value' => 'getBackendTable value'], implode(' AND ', ['entity_value.attribute_id = super_attribute.attribute_id', 'entity_value.store_id = 0', 'entity_value.link = entity.link']), []]); $select->expects($this->exactly(2))->method('joinLeft')->will($this->returnSelf())->withConsecutive([['option_value' => 'eav_attribute_option_value value'], implode(' AND ', ['option_value.option_id = entity_value.value', 'option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID]), []], [['attribute_label' => 'catalog_product_super_attribute_label value'], implode(' AND ', ['super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id', 'attribute_label.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID]), []]); $select->expects($this->once())->method('where')->will($this->returnSelf())->with('super_attribute.product_id = ?', 'getId value'); $readerAdapter = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)->setMethods(['select', 'fetchAll'])->disableOriginalConstructor()->getMockForAbstractClass(); $readerAdapter->expects($this->once())->method('select')->willReturn($select); $readerAdapter->expects($this->once())->method('fetchAll')->with($select)->willReturn('fetchAll value'); $configurable->expects($this->exactly(2))->method('getConnection')->willReturn($readerAdapter); $expectedAttributesOptionsData = ['getAttributeId value' => 'fetchAll value']; $actualAttributesOptionsData = $configurable->getConfigurableOptions($product, $attributes); $this->assertEquals($expectedAttributesOptionsData, $actualAttributesOptionsData); }
public function testSaveCreate() { $this->hydrator->expects($this->once())->method('extract')->with($this->abstractEntity)->willReturn(['test_field_1' => 'test_value_1', 'test_filed_2' => 'test_field_2']); $this->metadata->expects($this->never())->method('checkIsEntityExists'); $this->orchestratorPool->expects($this->once())->method('getWriteOperation')->with('Test\\Entity\\Type', 'create')->willReturn($this->writeOperation); $this->writeOperation->expects($this->once())->method('execute')->with('Test\\Entity\\Type', $this->abstractEntity)->willReturn($this->abstractEntity); $result = $this->subject->save('Test\\Entity\\Type', $this->abstractEntity); $this->assertEquals($this->abstractEntity, $result); }
/** * {@inheritdoc} */ public function retrieve(EntityMetadata $metadata, array $entityData) { $contextFields = $metadata->getEntityContext(); $context = []; if (isset($contextFields[\Magento\Store\Model\Store::STORE_ID])) { $context[\Magento\Store\Model\Store::STORE_ID] = $this->addStoreIdContext($entityData, \Magento\Store\Model\Store::STORE_ID); } return $context; }
/** * @param EntityMetadata $metadata * @param array $data * @return array */ protected function prepareData(EntityMetadata $metadata, $data) { $output = []; foreach ($metadata->getEntityConnection()->describeTable($metadata->getEntityTable()) as $column) { if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP' || $column['IDENTITY']) { continue; } if (isset($data[strtolower($column['COLUMN_NAME'])])) { $output[strtolower($column['COLUMN_NAME'])] = $data[strtolower($column['COLUMN_NAME'])]; } } return $output; }
/** * @param string $entityType * @param array $entity * @param string $identifier * @param string $linkField * @dataProvider executeParameters */ public function testExecute($entityType, $entity, $identifier, $linkField) { $this->metadataPoolMock->expects($this->once())->method('getMetadata')->with($entityType)->willReturn($this->metadataMock); $entityWithMainRead = array_merge($entity, ['main_read' => 'some info']); $this->readMainMock->expects($this->once())->method('execute')->with($entityType, $entity, $identifier)->willReturn($entityWithMainRead); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($linkField); $entityWithExtensionAndRelation = $entityWithMainRead; if (isset($entity[$linkField])) { $entityWithExtension = array_merge($entityWithMainRead, ['ext' => 'extParameter']); $this->readExtensionMock->expects($this->once())->method('execute')->with($entityType, $entityWithMainRead)->willReturn($entityWithExtension); $entityWithExtensionAndRelation = array_merge($entityWithExtension, ['relation' => 'some_relation']); $this->readRelationMock->expects($this->once())->method('execute')->with($entityType, $entityWithExtension)->willReturn($entityWithExtensionAndRelation); } $this->assertEquals($entityWithExtensionAndRelation, $this->read->execute($entityType, $entity, $identifier)); }
/** * Test `Save` method */ public function testSave() { $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['getIsDuplicate', 'dataHasChangedFor', 'getConfigurableAttributesData', 'getStoreId', 'getId', 'getData', 'hasData', 'getAssociatedProductIds', '__wakeup', '__sleep'])->disableOriginalConstructor()->getMock(); $product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValue('false')); $product->expects($this->any())->method('getConfigurableAttributesData')->will($this->returnValue($this->attributeData)); $product->expects($this->once())->method('getIsDuplicate')->will($this->returnValue(true)); $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1)); $product->expects($this->any())->method('getAssociatedProductIds')->will($this->returnValue([2])); $product->expects($this->any())->method('hasData')->with('_cache_instance_used_product_attribute_ids')->will($this->returnValue(true)); $extensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class)->setMethods(['getConfigurableProductOptions', 'getConfigurableProductLinks'])->getMockForAbstractClass(); $this->entityMetadata->expects(static::once())->method('getLinkField')->willReturn('link'); $dataMap = [['extension_attributes', null, $extensionAttributes], ['_cache_instance_used_product_attribute_ids', null, 1], ['link', null, 1]]; $product->expects($this->any())->method('getData')->willReturnMap($dataMap); $attribute = $this->getMockBuilder('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute')->disableOriginalConstructor()->setMethods(['addData', 'setStoreId', 'setProductId', 'save', '__wakeup', '__sleep'])->getMock(); $expectedAttributeData = $this->attributeData[1]; unset($expectedAttributeData['id']); $attribute->expects($this->once())->method('addData')->with($expectedAttributeData)->will($this->returnSelf()); $attribute->expects($this->once())->method('setStoreId')->with(1)->will($this->returnSelf()); $attribute->expects($this->once())->method('setProductId')->with(1)->will($this->returnSelf()); $attribute->expects($this->once())->method('save')->will($this->returnSelf()); $this->_configurableAttributeFactoryMock->expects($this->any())->method('create')->will($this->returnValue($attribute)); $attributeCollection = $this->getMockBuilder('\\Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable\\Attribute\\Collection')->setMethods(['setProductFilter', 'addFieldToFilter', 'walk'])->disableOriginalConstructor()->getMock(); $this->_attributeCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($attributeCollection)); $this->_typeConfigurableFactory->expects($this->once())->method('create')->will($this->returnSelf()); $this->_typeConfigurableFactory->expects($this->once())->method('saveProducts')->withAnyParameters()->will($this->returnSelf()); $this->_model->save($product); }
/** * @param \Magento\Catalog\Model\Product $product * @return $this */ protected function duplicate($product) { $mediaGalleryData = $product->getData($this->getAttribute()->getAttributeCode()); if (!isset($mediaGalleryData['images']) || !is_array($mediaGalleryData['images'])) { return $this; } $this->resourceModel->duplicate($this->getAttribute()->getAttributeId(), isset($mediaGalleryData['duplicate']) ? $mediaGalleryData['duplicate'] : [], $product->getOriginalId(), $product->getData($this->metadata->getLinkField())); return $this; }
/** * Returns product images in specific stores. * * @param \Magento\Catalog\Model\Product $product * @param int|array $storeIds * @return array */ public function getProductImages($product, $storeIds) { if (!is_array($storeIds)) { $storeIds = [$storeIds]; } $mainTable = $product->getResource()->getAttribute('image')->getBackend()->getTable(); $select = $this->getConnection()->select()->from(['images' => $mainTable], ['value as filepath', 'store_id'])->joinLeft(['attr' => $this->getTable('eav_attribute')], 'images.attribute_id = attr.attribute_id', ['attribute_code'])->where($this->metadata->getLinkField() . ' = ?', $product->getData($this->metadata->getLinkField()))->where('store_id IN (?)', $storeIds)->where('attribute_code IN (?)', ['small_image', 'thumbnail', 'image']); return $this->getConnection()->fetchAll($select); }
/** * @param AdapterInterface $connection * @param string $attributeTableName * @return array * @throws \Zend_Db_Statement_Exception */ private function getAffectedAttributeIds(AdapterInterface $connection, $attributeTableName) { $linkField = $this->metadata->getLinkField(); $select = $connection->select()->reset(); $select->from(['e' => $this->attributeResource->getTable('catalog_product_entity')], 'ei.value_id'); $select->join(['ei' => $attributeTableName], 'ei.' . $linkField . ' = e.' . $linkField . ' AND ei.store_id != 0', ''); $select->join(['s' => $this->attributeResource->getTable('store')], 's.store_id = ei.store_id', ''); $select->join(['sg' => $this->attributeResource->getTable('store_group')], 'sg.group_id = s.group_id', ''); $select->joinLeft(['pw' => $this->attributeResource->getTable('catalog_product_website')], 'pw.website_id = sg.website_id AND pw.product_id = e.entity_id', ''); $select->where('pw.product_id is null'); return $connection->fetchCol($select); }
/** * Return all product children ids * * @param int $productId Product Entity Id * @param string $typeId Super Product Link Type * @return array|null */ public function getProductChildIds($productId, $typeId) { $typeInstance = $this->getProductTypeInstance($typeId); $relation = $typeInstance->isComposite($this->getProductEmulator($typeId)) ? $typeInstance->getRelationInfo() : false; if ($relation && $relation->getTable() && $relation->getParentFieldName() && $relation->getChildFieldName()) { $select = $this->connection->select()->from(['main' => $this->getTable($relation->getTable())], [$relation->getChildFieldName()]); $select->join(['e' => $this->resource->getTableName('catalog_product_entity')], 'e.' . $this->metadata->getLinkField() . ' = main.' . $relation->getParentFieldName())->where('e.entity_id = ?', $productId); if ($relation->getWhere() !== null) { $select->where($relation->getWhere()); } return $this->connection->fetchCol($select); } return null; }
/** * @param EntityMetadata $metadata * @param array $data * @return array */ protected function prepareData(EntityMetadata $metadata, $data) { $output = []; foreach ($metadata->getEntityConnection()->describeTable($metadata->getEntityTable()) as $column) { if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP') { continue; } if (isset($data[strtolower($column['COLUMN_NAME'])])) { $output[strtolower($column['COLUMN_NAME'])] = $data[strtolower($column['COLUMN_NAME'])]; } elseif ($column['DEFAULT'] === null) { $output[strtolower($column['COLUMN_NAME'])] = null; } } if (empty($data[$metadata->getIdentifierField()])) { $output[$metadata->getIdentifierField()] = $metadata->generateIdentifier(); } return $output; }
public function testRemoveChild() { $this->productRepository->expects($this->any())->method('get')->will($this->returnValue($this->product)); $bundle = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Bundle', [], [], '', false); $this->bundleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($bundle)); $productSku = 'productSku'; $optionId = 1; $productId = 1; $childSku = 'childSku'; $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)); $this->getRemoveOptions(); $selection = $this->getMockBuilder('\\Magento\\Bundle\\Model\\Selection')->setMethods(['getSku', 'getOptionId', 'getSelectionId', 'getProductId', '__wakeup'])->disableOriginalConstructor()->getMock(); $selection->expects($this->any())->method('getSku')->will($this->returnValue($childSku)); $selection->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId)); $selection->expects($this->any())->method('getSelectionId')->will($this->returnValue(55)); $selection->expects($this->any())->method('getProductId')->willReturn($productId); $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$selection])); $this->metadataMock->expects($this->any())->method('getLinkField')->willReturn($this->linkField); $this->product->expects($this->any())->method('getData')->with($this->linkField)->willReturn(3); $bundle->expects($this->once())->method('dropAllUnneededSelections')->with(3, []); $bundle->expects($this->once())->method('removeProductRelations')->with(3, [$productId]); //Params come in lowercase to method $this->assertTrue($this->model->removeChild($productSku, $optionId, $childSku)); }
/** * @magentoAppArea adminhtml * @magentoDbIsolation enabled * @magentoAppIsolation enabled * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testDownloadableImport() { // import data from CSV file $pathToFile = __DIR__ . '/../../_files/import_downloadable.csv'; $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class); $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]); $errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData(); $this->assertTrue($errors->getErrorsCount() == 0); $this->model->importData(); $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class); $productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME); $this->assertTrue(is_numeric($productId)); /** @var \Magento\Catalog\Model\Product $product */ $product = $this->objectManager->create(\Magento\Catalog\Model\Product::class); $product->load($productId); $this->assertFalse($product->isObjectNew()); $this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName()); $this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId()); $downloadableProductLinks = $product->getExtensionAttributes()->getDownloadableProductLinks(); $downloadableLinks = $product->getDownloadableLinks(); $downloadableProductSamples = $product->getExtensionAttributes()->getDownloadableProductSamples(); $downloadableSamples = $product->getDownloadableSamples(); //TODO: Track Fields: id, link_id, link_file and sample_file) $expectedLinks = ['file' => ['title' => 'TEST Import Link Title File', 'sort_order' => '78', 'sample_type' => 'file', 'price' => '123.0000', 'number_of_downloads' => '123', 'is_shareable' => '0', 'link_type' => 'file'], 'url' => ['title' => 'TEST Import Link Title URL', 'sort_order' => '42', 'sample_type' => 'url', 'sample_url' => 'http://www.bing.com', 'price' => '1.0000', 'number_of_downloads' => '0', 'is_shareable' => '1', 'link_type' => 'url', 'link_url' => 'http://www.google.com']]; foreach ($downloadableProductLinks as $link) { $actualLink = $link->getData(); $this->assertArrayHasKey('link_type', $actualLink); foreach ($expectedLinks[$actualLink['link_type']] as $expectedKey => $expectedValue) { $this->assertArrayHasKey($expectedKey, $actualLink); $this->assertEquals($actualLink[$expectedKey], $expectedValue); } } foreach ($downloadableLinks as $link) { $actualLink = $link->getData(); $this->assertArrayHasKey('link_type', $actualLink); $this->assertArrayHasKey('product_id', $actualLink); $this->assertEquals($actualLink['product_id'], $product->getData($this->productMetadata->getLinkField())); foreach ($expectedLinks[$actualLink['link_type']] as $expectedKey => $expectedValue) { $this->assertArrayHasKey($expectedKey, $actualLink); $this->assertEquals($actualLink[$expectedKey], $expectedValue); } } //TODO: Track Fields: id, sample_id and sample_file) $expectedSamples = ['file' => ['title' => 'TEST Import Sample File', 'sort_order' => '178', 'sample_type' => 'file'], 'url' => ['title' => 'TEST Import Sample URL', 'sort_order' => '178', 'sample_type' => 'url', 'sample_url' => 'http://www.yahoo.com']]; foreach ($downloadableProductSamples as $sample) { $actualSample = $sample->getData(); $this->assertArrayHasKey('sample_type', $actualSample); foreach ($expectedSamples[$actualSample['sample_type']] as $expectedKey => $expectedValue) { $this->assertArrayHasKey($expectedKey, $actualSample); $this->assertEquals($actualSample[$expectedKey], $expectedValue); } } foreach ($downloadableSamples as $sample) { $actualSample = $sample->getData(); $this->assertArrayHasKey('sample_type', $actualSample); $this->assertArrayHasKey('product_id', $actualSample); $this->assertEquals($actualSample['product_id'], $product->getData($this->productMetadata->getLinkField())); foreach ($expectedSamples[$actualSample['sample_type']] as $expectedKey => $expectedValue) { $this->assertArrayHasKey($expectedKey, $actualSample); $this->assertEquals($actualSample[$expectedKey], $expectedValue); } } }
/** * Return attribute values for given entities and store of specific attribute type * * @param string $type * @param array $entityIds * @param integer $storeId * @return array */ protected function getAttributeTypeValues($type, $entityIds, $storeId) { $linkField = $this->categoryMetadata->getLinkField(); $select = $this->connection->select()->from(['def' => $this->connection->getTableName($this->getTableName('catalog_category_entity_' . $type))], [$linkField, 'attribute_id'])->joinLeft(['e' => $this->connection->getTableName($this->getTableName('catalog_category_entity'))], "def.{$linkField} = e.{$linkField}")->joinLeft(['store' => $this->connection->getTableName($this->getTableName('catalog_category_entity_' . $type))], "store.{$linkField} = def.{$linkField} AND store.attribute_id = def.attribute_id " . 'AND store.store_id = ' . $storeId, ['value' => $this->connection->getCheckSql('store.value_id > 0', $this->connection->quoteIdentifier('store.value'), $this->connection->quoteIdentifier('def.value'))])->where("e.entity_id IN (?)", $entityIds)->where('def.store_id IN (?)', [\Magento\Store\Model\Store::DEFAULT_STORE_ID, $storeId]); return $this->connection->fetchAll($select); }
public function testCheckIsEntityExists() { $entityTableName = 'entity_table'; $connectionName = 'default'; $identifierField = 'blabla_id'; $id = 1; $this->appResourceMock->expects($this->exactly(2))->method('getConnectionByName')->with($connectionName)->willReturn($this->connectionMock); $this->appResourceMock->expects($this->once())->method('getTableName')->with($entityTableName)->willReturn($entityTableName); $this->connectionMock->expects($this->once())->method('select')->willReturn($this->selectMock); $this->selectMock->expects($this->once())->method('from')->with($entityTableName, [$identifierField])->willReturnSelf(); $this->selectMock->expects($this->once())->method('where')->with($identifierField . ' = ?', $id)->willReturnSelf(); $this->selectMock->expects($this->once())->method('limit')->with(1)->willReturnSelf(); $this->connectionMock->expects($this->once())->method('fetchOne')->with($this->selectMock)->willReturn($id); $metadata = new EntityMetadata($this->appResourceMock, $entityTableName, $identifierField, null, null, $connectionName); $this->assertTrue($metadata->checkIsEntityExists($id)); }
/** * @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_attribute.php * @magentoAppArea adminhtml */ public function testConfigurableImport() { // import data from CSV file $pathToFile = __DIR__ . '/../../_files/import_configurable.csv'; $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class); $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]); $errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData(); $this->assertTrue($errors->getErrorsCount() == 0); $this->model->importData(); /** @var \Magento\Catalog\Model\ResourceModel\Product $resource */ $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class); $productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME); $this->assertTrue(is_numeric($productId)); /** @var \Magento\Catalog\Model\Product $product */ $product = $this->objectManager->get(ProductRepositoryInterface::class)->getById($productId); $this->assertFalse($product->isObjectNew()); $this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName()); $this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId()); $optionCollection = $product->getTypeInstance()->getConfigurableOptions($product); foreach ($optionCollection as $option) { foreach ($option as $optionData) { $this->assertContains($optionData['sku'], $this->optionSkuList); } } $optionIdList = $resource->getProductsIdsBySkus($this->optionSkuList); foreach ($optionIdList as $optionId) { $this->assertArrayHasKey($optionId, $product->getExtensionAttributes()->getConfigurableProductLinks()); } $configurableOptionCollection = $product->getExtensionAttributes()->getConfigurableProductOptions(); $this->assertEquals(1, count($configurableOptionCollection)); foreach ($configurableOptionCollection as $option) { $optionData = $option->getData(); $this->assertArrayHasKey('product_super_attribute_id', $optionData); $this->assertArrayHasKey('product_id', $optionData); $this->assertEquals($product->getData($this->productMetadata->getLinkField()), $optionData['product_id']); $this->assertArrayHasKey('attribute_id', $optionData); $this->assertArrayHasKey('position', $optionData); $this->assertArrayHasKey('extension_attributes', $optionData); $this->assertArrayHasKey('product_attribute', $optionData); $productAttributeData = $optionData['product_attribute']->getData(); $this->assertArrayHasKey('attribute_id', $productAttributeData); $this->assertArrayHasKey('entity_type_id', $productAttributeData); $this->assertArrayHasKey('attribute_code', $productAttributeData); $this->assertEquals('test_configurable', $productAttributeData['attribute_code']); $this->assertArrayHasKey('frontend_label', $productAttributeData); $this->assertEquals('Test Configurable', $productAttributeData['frontend_label']); $this->assertArrayHasKey('label', $optionData); $this->assertEquals('test_configurable', $optionData['label']); $this->assertArrayHasKey('use_default', $optionData); $this->assertArrayHasKey('options', $optionData); $this->assertEquals('Option 1', $optionData['options'][0]['label']); $this->assertEquals('Option 1', $optionData['options'][0]['default_label']); $this->assertEquals('Option 1', $optionData['options'][0]['store_label']); $this->assertEquals('Option 2', $optionData['options'][1]['label']); $this->assertEquals('Option 2', $optionData['options'][1]['default_label']); $this->assertEquals('Option 2', $optionData['options'][1]['store_label']); $this->assertArrayHasKey('values', $optionData); $valuesData = $optionData['values']; $this->assertEquals(2, count($valuesData)); } }