Skip to content

Commit

Permalink
MAGETWO-57153: [Backport] - [Github] Custom options not displayed cor…
Browse files Browse the repository at this point in the history
…rectly on a store view level #2908 #5885 #5612 - for 2.1
  • Loading branch information
ameysar committed Sep 27, 2017
1 parent 183ce76 commit 63a6a54
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ public function mergeProductOptions($productOptions, $overwriteOptions)
}

/**
* Overwrite values of fields to default, if there are option id and field
* name in array overwriteOptions.
* Overwrite values of fields to default, if there are option id and field name in array overwriteOptions.
*
* @param int $optionId
* @param array $option
Expand Down Expand Up @@ -422,7 +421,7 @@ private function getProductRepository()
{
if (null === $this->productRepository) {
$this->productRepository = \Magento\Framework\App\ObjectManager::getInstance()
->get('\Magento\Catalog\Api\ProductRepositoryInterface\Proxy');
->get(\Magento\Catalog\Api\ProductRepositoryInterface\Proxy::class);
}

return $this->productRepository;
Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/Catalog/Model/Product/Option/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public function duplicate(
*/
public function save(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $option)
{
/** @var string $productSku */
$productSku = $option->getProductSku();
if (!$productSku) {
throw new CouldNotSaveException(__('ProductSku should be specified'));
Expand Down Expand Up @@ -167,7 +166,9 @@ function ($iOption) use ($option) {
/** @var array $newValues */
$newValues = $option->getData('values');
if ($newValues) {
$newValues = $this->markRemovedValues($newValues, $originalValues);
if (isset($originalValues)) {
$newValues = $this->markRemovedValues($newValues, $originalValues);
}
$option->setData('values', $newValues);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ private function assembleProductMock($links = [])

/**
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper::initialize
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testInitialize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class SelectTest extends \PHPUnit_Framework_TestCase
protected $validator;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Catalog\Model\Product\Option|\PHPUnit_Framework_MockObject_MockObject
*/
protected $valueMock;

protected function setUp()
{
$configMock = $this->getMock('Magento\Catalog\Model\ProductOptions\ConfigInterface');
$configMock = $this->getMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
$priceConfigMock = new \Magento\Catalog\Model\Config\Source\Product\Options\Price();
$config = [
[
Expand All @@ -46,7 +46,7 @@ protected function setUp()
];
$configMock->expects($this->once())->method('getAll')->will($this->returnValue($config));
$methods = ['getTitle', 'getType', 'getPriceType', 'getPrice', '__wakeup', 'getData'];
$this->valueMock = $this->getMock('Magento\Catalog\Model\Product\Option', $methods, [], '', false);
$this->valueMock = $this->getMock(\Magento\Catalog\Model\Product\Option::class, $methods, [], '', false);
$this->validator = new \Magento\Catalog\Model\Product\Option\Validator\Select(
$configMock,
$priceConfigMock
Expand All @@ -73,6 +73,9 @@ public function testIsValidSuccess($value)
$this->assertEmpty($this->validator->getMessages());
}

/**
* @return array
*/
public function isValidSuccessDataProvider()
{
$value = [
Expand All @@ -87,7 +90,7 @@ public function isValidSuccessDataProvider()

return [
'all_data' => [$value],
'not_all_data' => [$valueWithoutAllData]
'not_all_data' => [$valueWithoutAllData],
];
}

Expand Down Expand Up @@ -127,6 +130,7 @@ public function testIsValidateWithEmptyValues()
* @param string $priceType
* @param int $price
* @param string|null $title
* @return void
* @dataProvider isValidateWithInvalidDataDataProvider
*/
public function testIsValidateWithInvalidData($priceType, $price, $title)
Expand All @@ -148,12 +152,69 @@ public function testIsValidateWithInvalidData($priceType, $price, $title)
$this->assertEquals($messages, $this->validator->getMessages());
}

/**
* @return array
*/
public function isValidateWithInvalidDataDataProvider()
{
return [
'invalid_price' => ['fixed', -10, 'Title'],
'invalid_price_type' => ['some_value', '10', 'Title'],
'empty_title' => ['fixed', 10, null]
'empty_title' => ['fixed', 10, null],
];
}

/**
* @param array $value
* @param bool $isValid
* @return void
* @dataProvider validateDeletedOptionValueDataProvider
*/
public function testValidateWithDeletedOptionValue(array $value, $isValid)
{
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
$this->valueMock->expects($this->never())->method('getPriceType');
$this->valueMock->expects($this->never())->method('getPrice');
$this->valueMock->expects($this->any())->method('getData')->with('values')->will($this->returnValue($value));

$this->assertEquals($isValid, $this->validator->isValid($this->valueMock));
}

/**
* @return array
*/
public function validateDeletedOptionValueDataProvider()
{
return [
'All option values deleted' => [
[
[
'price_type' => 'fixed',
'price' => 10,
'title' => 'Title',
'is_delete' => 1,
],
],
false,
],
'Single option value deleted' => [
[
[
'price_type' => 'fixed',
'price' => 10,
'title' => 'Title 1',
'is_delete' => 0
],
[
'price_type' => 'fixed',
'price' => 11,
'title' => 'Title 2',
'is_delete' => 1,
],
],
true,
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ public function testSaveProduct()
->setData('option_type_id', -1)
->setDataChanges(false)
->isDeleted(false);
$this->assertInstanceOf('\Magento\Catalog\Model\Product\Option\Value', $this->model->saveValues());

$this->assertInstanceOf(\Magento\Catalog\Model\Product\Option\Value::class, $this->model->saveValues());
$this->assertArrayHasKey('option_type_id', $this->model->getData());
$this->assertEquals(-1, $this->model->getData('option_type_id'));

$this->model->setData('is_delete', 1)
->setData('option_type_id', 1)
->setValues([100]);
$this->assertInstanceOf('\Magento\Catalog\Model\Product\Option\Value', $this->model->saveValues());

$this->assertInstanceOf(\Magento\Catalog\Model\Product\Option\Value::class, $this->model->saveValues());
$this->assertArrayHasKey('option_type_id', $this->model->getData());
$this->assertEquals(1, $this->model->getData('option_type_id'));
}

public function testGetPrice()
Expand All @@ -45,37 +51,37 @@ public function testGetPrice()
public function testGetValuesCollection()
{
$this->assertInstanceOf(
'\Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection',
\Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection::class,
$this->model->getValuesCollection($this->getMockedOption())
);
}

public function testGetValuesByOption()
{
$this->assertInstanceOf(
'\Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection',
\Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection::class,
$this->model->getValuesByOption([1], 1, 1)
);
}

public function testGetProduct()
{
$this->assertInstanceOf('\Magento\Catalog\Model\Product', $this->model->getProduct());
$this->assertInstanceOf(\Magento\Catalog\Model\Product::class, $this->model->getProduct());
}

public function testDuplicate()
{
$this->assertInstanceOf('\Magento\Catalog\Model\Product\Option\Value', $this->model->duplicate(1, 1));
$this->assertInstanceOf(\Magento\Catalog\Model\Product\Option\Value::class, $this->model->duplicate(1, 1));
}

public function testDeleteValues()
{
$this->assertInstanceOf('\Magento\Catalog\Model\Product\Option\Value', $this->model->deleteValues(1));
$this->assertInstanceOf(\Magento\Catalog\Model\Product\Option\Value::class, $this->model->deleteValues(1));
}

public function testDeleteValue()
{
$this->assertInstanceOf('\Magento\Catalog\Model\Product\Option\Value', $this->model->deleteValue(1));
$this->assertInstanceOf(\Magento\Catalog\Model\Product\Option\Value::class, $this->model->deleteValue(1));
}

protected function setUp()
Expand All @@ -85,7 +91,7 @@ protected function setUp()
$mockedContext = $this->getMockedContext();
$helper = new ObjectManager($this);
$this->model = $helper->getObject(
'\Magento\Catalog\Model\Product\Option\Value',
\Magento\Catalog\Model\Product\Option\Value::class,
[
'resource' => $mockedResource,
'valueCollectionFactory' => $mockedCollectionFactory,
Expand All @@ -103,7 +109,7 @@ private function getMockedValueCollectionFactory()
$mockedCollection = $this->getMockedValueCollection();

$mockBuilder =
$this->getMockBuilder('\Magento\Catalog\Model\ResourceModel\Product\Option\Value\CollectionFactory')
$this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Option\Value\CollectionFactory::class)
->setMethods(['create'])
->disableOriginalConstructor();
$mock = $mockBuilder->getMock();
Expand All @@ -120,9 +126,9 @@ private function getMockedValueCollectionFactory()
*/
private function getMockedValueCollection()
{
$mockBuilder = $this->getMockBuilder('\Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection')
->setMethods(['addFieldToFilter', 'getValuesByOption', 'getValues'])
->disableOriginalConstructor();
$mockBuilder = $this->getMockBuilder(
\Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection::class
)->setMethods(['addFieldToFilter', 'getValuesByOption', 'getValues'])->disableOriginalConstructor();
$mock = $mockBuilder->getMock();

$mock->expects($this->any())
Expand All @@ -147,7 +153,7 @@ private function getMockedOption()
{
$mockedProduct = $this->getMockedProduct();

$mockBuilder = $this->getMockBuilder('\Magento\Catalog\Model\Product\Option')
$mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class)
->disableOriginalConstructor();
$mock = $mockBuilder->getMock();

Expand All @@ -163,7 +169,7 @@ private function getMockedOption()
*/
private function getMockedProduct()
{
$mockBuilder = $this->getMockBuilder('\Magento\Catalog\Model\Product')
$mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->setMethods(['getFinalPrice', '__wakeup'])
->disableOriginalConstructor();
$mock = $mockBuilder->getMock();
Expand All @@ -180,7 +186,7 @@ private function getMockedProduct()
*/
private function getMockedResource()
{
$mockBuilder = $this->getMockBuilder('\Magento\Catalog\Model\ResourceModel\Product\Option\Value')
$mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Option\Value::class)
->setMethods(
[
'duplicate',
Expand Down Expand Up @@ -238,7 +244,7 @@ private function getMockedContext()
$mockedRemoveAction = $this->getMockedRemoveAction();
$mockEventManager = $this->getMockedEventManager();

$mockBuilder = $this->getMockBuilder('\Magento\Framework\Model\Context')
$mockBuilder = $this->getMockBuilder(\Magento\Framework\Model\Context::class)
->setMethods(['getActionValidator', 'getEventDispatcher'])
->disableOriginalConstructor();
$mock = $mockBuilder->getMock();
Expand All @@ -259,7 +265,7 @@ private function getMockedContext()
*/
private function getMockedRemoveAction()
{
$mockBuilder = $this->getMockBuilder('\Magento\Framework\Model\Context')
$mockBuilder = $this->getMockBuilder(\Magento\Framework\Model\Context::class)
->setMethods(['isAllowed'])
->disableOriginalConstructor();
$mock = $mockBuilder->getMock();
Expand All @@ -276,7 +282,7 @@ private function getMockedRemoveAction()
*/
private function getMockedEventManager()
{
$mockBuilder = $this->getMockBuilder('\Magento\Framework\Event\ManagerInterface')
$mockBuilder = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
->setMethods(['dispatch'])
->disableOriginalConstructor();
$mock = $mockBuilder->getMockForAbstractClass();
Expand Down
Loading

0 comments on commit 63a6a54

Please sign in to comment.