Skip to content

Commit

Permalink
MC-20670: Delete custom options of simple product
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanPletnyov committed Nov 6, 2019
1 parent 3b8c827 commit 18b2db6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory;
use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product\Option;
use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\Message\MessageInterface;
use Magento\TestFramework\TestCase\AbstractBackendController;

/**
Expand Down Expand Up @@ -64,13 +64,17 @@ protected function setUp()
public function testDeleteCustomOptionWithTypeField(array $optionData): void
{
$product = $this->productRepository->get('simple');
/** @var ProductCustomOptionInterface|Option $option */
/** @var ProductCustomOptionInterface $option */
$option = $this->optionRepositoryFactory->create(['data' => $optionData]);
$option->setProductSku($product->getSku());
$product->setOptions([$option]);
$this->productRepository->save($product);
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->dispatch('backend/catalog/product/save/id/' . $product->getEntityId());
$this->assertSessionMessages(
$this->equalTo([(string)__('You saved the product.')]),
MessageInterface::TYPE_SUCCESS
);
$this->assertCount(0, $this->optionRepository->getProductOptions($product));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ private function deleteAndAssertNotSelectCustomOptions(array $optionData): void
$createdOption->setProductSku($product->getSku());
$product->setOptions([$createdOption]);
$this->productRepository->save($product);
$this->assertCount(1, $this->optionRepository->getProductOptions($product));
$product->setOptions([]);
$this->productRepository->save($product);
$this->assertCount(0, $this->optionRepository->getProductOptions($product));
Expand Down

0 comments on commit 18b2db6

Please sign in to comment.