|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Bundle\Model\Product; |
| 8 | + |
| 9 | +/** |
| 10 | + * Test class for \Magento\Bundle\Model\Product\SaveHandler |
| 11 | + * The tested class used indirectly |
| 12 | + * |
| 13 | + * @magentoDataFixture Magento/Bundle/_files/product.php |
| 14 | + * @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php |
| 15 | + * @magentoDbIsolation disabled |
| 16 | + * @magentoAppIsolation enabled |
| 17 | + */ |
| 18 | +class SaveHandlerTest extends \PHPUnit\Framework\TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var \Magento\Framework\ObjectManagerInterface |
| 22 | + */ |
| 23 | + private $objectManager; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var \Magento\Store\Model\Store |
| 27 | + */ |
| 28 | + private $store; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var \Magento\Catalog\Api\ProductRepositoryInterface |
| 32 | + */ |
| 33 | + private $productRepository; |
| 34 | + |
| 35 | + protected function setUp() |
| 36 | + { |
| 37 | + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 38 | + $this->store = $this->objectManager->create(\Magento\Store\Model\Store::class); |
| 39 | + /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ |
| 40 | + $this->productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); |
| 41 | + } |
| 42 | + |
| 43 | + public function testOptionTitlesOnDifferentStores() |
| 44 | + { |
| 45 | + /** |
| 46 | + * @var \Magento\Bundle\Model\Product\OptionList $optionList |
| 47 | + */ |
| 48 | + $optionList = $this->objectManager->create(\Magento\Bundle\Model\Product\OptionList::class); |
| 49 | + |
| 50 | + $secondStoreId = $this->store->load('fixture_second_store')->getId(); |
| 51 | + $thirdStoreId = $this->store->load('fixture_third_store')->getId(); |
| 52 | + |
| 53 | + $product = $this->productRepository->get('bundle-product', true, $secondStoreId, true); |
| 54 | + $options = $optionList->getItems($product); |
| 55 | + $title = $options[0]->getTitle(); |
| 56 | + $newTitle = $title . ' ' . $this->store->load('fixture_second_store')->getCode(); |
| 57 | + $options[0]->setTitle($newTitle); |
| 58 | + $extension = $product->getExtensionAttributes(); |
| 59 | + $extension->setBundleProductOptions($options); |
| 60 | + $product->setExtensionAttributes($extension); |
| 61 | + $product->save(); |
| 62 | + |
| 63 | + $product = $this->productRepository->get('bundle-product', true, $thirdStoreId, true); |
| 64 | + $options = $optionList->getItems($product); |
| 65 | + $newTitle = $title . ' ' . $this->store->load('fixture_third_store')->getCode(); |
| 66 | + $options[0]->setTitle($newTitle); |
| 67 | + $extension = $product->getExtensionAttributes(); |
| 68 | + $extension->setBundleProductOptions($options); |
| 69 | + $product->setExtensionAttributes($extension); |
| 70 | + $product->save(); |
| 71 | + |
| 72 | + $product = $this->productRepository->get('bundle-product', false, $secondStoreId, true); |
| 73 | + $options = $optionList->getItems($product); |
| 74 | + $this->assertEquals(1, count($options)); |
| 75 | + $this->assertEquals( |
| 76 | + $title . ' ' . $this->store->load('fixture_second_store')->getCode(), |
| 77 | + $options[0]->getTitle() |
| 78 | + ); |
| 79 | + } |
| 80 | +} |
0 commit comments