Skip to content

Commit

Permalink
Merge pull request #293 from magento-dragons/S67
Browse files Browse the repository at this point in the history
[DRAGONS] - S67
  • Loading branch information
Kasian,Andrii(akasian) committed May 15, 2015
2 parents a0ca082 + fc597c7 commit 7ae9152
Show file tree
Hide file tree
Showing 51 changed files with 1,186 additions and 424 deletions.
4 changes: 4 additions & 0 deletions app/code/Magento/Bundle/Api/Data/LinkInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

namespace Magento\Bundle\Api\Data;

/**
* Interface LinkInterface
* @api
*/
interface LinkInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
const PRICE_TYPE_FIXED = 0;
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Bundle/Api/Data/OptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

namespace Magento\Bundle\Api\Data;

/**
* Interface OptionInterface
* @api
*/
interface OptionInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
/**
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Bundle/Api/Data/OptionTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
namespace Magento\Bundle\Api\Data;

/**
* Interface OptionTypeInterface
* @api
*/
interface OptionTypeInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
namespace Magento\Bundle\Api;

/**
* Interface for Management of ProductLink
* @api
*/
interface ProductLinkManagementInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
namespace Magento\Bundle\Api;

/**
* Interface ProductOptionRepositoryInterface
* @api
*/
interface ProductOptionRepositoryInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
namespace Magento\Bundle\Api;

/**
* Interface ProductOptionTypeListInterface
* @api
*/
interface ProductOptionTypeListInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ public function getOptions()
*/
public function isDisabledField()
{
return $this->getProduct()->getId() &&
$this->getAttribute()->getAttributeCode() === 'price' ||
$this->getElement()->getReadonly();
return $this->_getData('is_disabled_field')
|| ($this->getProduct()->getId()
&& $this->getAttribute()->getAttributeCode() === 'price'
)
|| $this->getElement()->getReadonly();

}

/**
Expand Down Expand Up @@ -142,7 +145,9 @@ public function getExtendedElement($switchAttributeCode)
'values' => $this->getOptions(),
'value' => $switchAttributeCode,
'class' => 'required-entry next-toinput',
'disabled' => $this->isDisabledField()
'no_span' => true,
'disabled' => $this->isDisabledField(),
'value' => $this->getProduct()->getData($switchAttributeCode),
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* Option price interface
* @api
*/
interface BundleOptionPriceInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* Interface DiscountProviderInterface
* @api
*/
interface DiscountProviderInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* Interface FinalPriceInterface
* @api
*/
interface FinalPriceInterface extends \Magento\Catalog\Pricing\Price\FinalPriceInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* Regular price interface
* @api
*/
interface RegularPriceInterface extends \Magento\Framework\Pricing\Price\BasePriceProviderInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Test\Unit\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes;

use Magento\Catalog\Model\Product;

class ExtendTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject */
protected $registry;

/** @var \Magento\Framework\Data\FormFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $formFactory;

/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
protected $objectManagerHelper;

/** @var \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes\Extend */
protected $object;

public function setUp()
{
$this->registry = $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->getMock(
);
$this->formFactory = $this->getMockBuilder('Magento\\Framework\\Data\\FormFactory')->disableOriginalConstructor(
)->getMock();
$this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->object = $this->objectManagerHelper->getObject(
'Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Attributes\\Extend',
['registry' => $this->registry, 'formFactory' => $this->formFactory]
);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function getProduct()
{
$product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->getMock();
$this->registry->expects($this->once())
->method('registry')
->with('product')
->will(
$this->returnValue($product)
);
return $product;
}

public function testGetExtendedElement()
{
$switchAttributeCode = 'test_code';
$form = $this->getMockBuilder(\Magento\Framework\Data\Form::class)->disableOriginalConstructor()->getMock();
$and = new \PHPUnit_Framework_Constraint_And();
$and->setConstraints(
[
new \PHPUnit_Framework_Constraint_ArrayHasKey('value')
]
);
$form->expects($this->once())->method('addField')->with(
$switchAttributeCode,
'select',
$and
);

$this->formFactory->expects($this->once())->method('create')->with()->will($this->returnValue($form));
$product = $this->getProduct();
$product->expects($this->once())->method('getData')->with($switchAttributeCode)->will(
$this->returnValue(123)
);
$this->object->setIsDisabledField(true);
$this->object->getExtendedElement($switchAttributeCode);
}
}
85 changes: 80 additions & 5 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
*/
class TypeTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Bundle\Model\Resource\BundleFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $bundleFactory;
/**
* @var \Magento\Bundle\Model\SelectionFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $bundleModelSelection;
/**
* @var \Magento\Bundle\Model\Product\Type
*/
Expand Down Expand Up @@ -96,19 +104,18 @@ protected function setUp()
->setMethods(['convert'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$bundleModelSelection = $this->getMockBuilder('\Magento\Bundle\Model\SelectionFactory')
$this->bundleModelSelection = $this->getMockBuilder('Magento\Bundle\Model\SelectionFactory')
->disableOriginalConstructor()
->getMock();
$bundleFactory = $this->getMockBuilder('\Magento\Bundle\Model\Resource\BundleFactory')
$this->bundleFactory = $this->getMockBuilder('\Magento\Bundle\Model\Resource\BundleFactory')
->disableOriginalConstructor()
->getMock();

$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->model = $objectHelper->getObject(
'Magento\Bundle\Model\Product\Type',
[
'bundleModelSelection' => $bundleModelSelection,
'bundleFactory' => $bundleFactory,
'bundleModelSelection' => $this->bundleModelSelection,
'bundleFactory' => $this->bundleFactory,
'bundleCollection' => $this->bundleCollection,
'bundleOption' => $this->bundleOptionFactory,
'catalogData' => $this->catalogData,
Expand Down Expand Up @@ -2427,4 +2434,72 @@ protected function parentClass($group, $option, $buyRequest, $product)
->method('getSkipSaleableCheck')
->willReturn(false);
}

public function testSave()
{
$options = [
'some_option' => ['option_id' => '', 'delete' => false],
];
$selections = [
'some_option' => [
123 => ['selection_id' => '', 'delete' => false],
]
];

$resource = $this->getMockBuilder('Magento\Bundle\Model\Resource\Bundle')
->disableOriginalConstructor()
->getMock();
$this->bundleFactory->expects($this->once())
->method('create')
->willReturn($resource);

$product = $this->getMockBuilder('Magento\Catalog\Model\Product')
->setMethods(
[
'getStoreId',
'getOrigData',
'getData',
'getBundleOptionsData',
'getBundleSelectionsData'
]
)
->disableOriginalConstructor()
->getMock();
$product->expects($this->once())
->method('getBundleOptionsData')
->willReturn($options);
$product->expects($this->once())
->method('getBundleSelectionsData')
->willReturn($selections);
$option = $this->getMockBuilder('Magento\Bundle\Model\Resource\Option\Collection')
->setMethods(['setData', 'setParentId', 'setStoreId', 'isDeleted', 'save', 'getOptionId'])
->disableOriginalConstructor()
->getMock();
$option->expects($this->once())->method('setData')->willReturnSelf();
$option->expects($this->once())->method('setParentId')->willReturnSelf();
$option->expects($this->once())->method('setStoreId')->willReturnSelf();
$this->bundleOptionFactory->expects($this->once())->method('create')->will($this->returnValue($option));

$selection = $this->getMockBuilder('Magento\Bundle\Model\Selection')
->setMethods(['setData', 'setOptionId', 'setParentProductId', 'setWebsiteId', 'save'])
->disableOriginalConstructor()
->getMock();
$selection->expects($this->once())->method('setData')->willReturnSelf();
$selection->expects($this->once())->method('setOptionId')->willReturnSelf();
$selection->expects($this->once())->method('setParentProductId')->willReturnSelf();
$selection->expects($this->once())->method('setWebsiteId')->willReturnSelf();
$selection->expects($this->once())->method('setParentProductId')->willReturnSelf();
$this->bundleModelSelection->expects($this->once())->method('create')->willReturn($selection);
$store = $this->getMockBuilder('Magento\Store\Model\Store')
->setMethods(['getWebsiteId', '__wakeup'])
->disableOriginalConstructor()
->getMock();
$this->storeManager->expects($this->once())
->method('getStore')
->will($this->returnValue($store));
$store->expects($this->once())
->method('getWebsiteId')
->will($this->returnValue(10));
$this->model->save($product);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
*/
namespace Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab;

use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Form;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Config\Model\Config\Source\Yesno;
use Magento\Catalog\Model\Entity\Attribute;
use Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Registry;

class Front extends Generic
{
Expand All @@ -24,28 +28,28 @@ class Front extends Generic
protected $_yesNo;

/**
* @var array
* @var PropertyLocker
*/
private $disableSearchable;
private $propertyLocker;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param Yesno $yesNo
* @param PropertyLocker $propertyLocker
* @param array $data
* @param array $disableSearchable
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
Context $context,
Registry $registry,
FormFactory $formFactory,
Yesno $yesNo,
array $data = [],
array $disableSearchable = []
PropertyLocker $propertyLocker,
array $data = []
) {
$this->_yesNo = $yesNo;
$this->disableSearchable = $disableSearchable;
$this->propertyLocker = $propertyLocker;
parent::__construct($context, $registry, $formFactory, $data);
}

Expand All @@ -71,7 +75,6 @@ protected function _prepareForm()
['legend' => __('Frontend Properties'), 'collapsable' => $this->getRequest()->has('popup')]
);

$attrCode = $attributeObject->getAttributeCode();
$fieldset->addField(
'is_searchable',
'select',
Expand All @@ -80,7 +83,6 @@ protected function _prepareForm()
'label' => __('Use in Search'),
'title' => __('Use in Search'),
'values' => $yesnoSource,
'disabled' => isset($this->disableSearchable[$attrCode]) && $this->disableSearchable[$attrCode] ? 1 : 0
]
);

Expand Down Expand Up @@ -223,6 +225,7 @@ protected function _prepareForm()
);

$form->setValues($attributeObject->getData());
$this->propertyLocker->lock($form);
$this->setForm($form);
return parent::_prepareForm();
}
Expand Down
Loading

0 comments on commit 7ae9152

Please sign in to comment.