Skip to content

Commit

Permalink
Merge pull request #125 from magento-goinc/MAGETWO-31159
Browse files Browse the repository at this point in the history
[GoInc] HHVM Compatibility, Varnish coverage increase, Bug Fixes
  • Loading branch information
orlangur committed Mar 15, 2015
2 parents 689db78 + 9cd7866 commit 10d1600
Show file tree
Hide file tree
Showing 140 changed files with 1,214 additions and 995 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class IteratorTest extends \PHPUnit_Framework_TestCase
*/
protected $_menuModel;

/**
* @var \Magento\Backend\Model\Menu\Filter\Iterator
*/
protected $_filterIteratorModel;

/**
* @var \Magento\Backend\Model\Menu\Item[]
*/
Expand All @@ -42,9 +37,6 @@ protected function setUp()
$loggerMock = $this->getMock('Psr\Log\LoggerInterface');

$this->_menuModel = new \Magento\Backend\Model\Menu($loggerMock);
$this->_filterIteratorModel = new \Magento\Backend\Model\Menu\Filter\Iterator(
$this->_menuModel->getIterator()
);
}

public function testLoopWithAllItemsDisabledDoesntIterate()
Expand All @@ -54,8 +46,12 @@ public function testLoopWithAllItemsDisabledDoesntIterate()
$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$filterIteratorModel = new \Magento\Backend\Model\Menu\Filter\Iterator(
$this->_menuModel->getIterator()
);

$items = [];
foreach ($this->_filterIteratorModel as $item) {
foreach ($filterIteratorModel as $item) {
$items[] = $item;
}
$this->assertCount(0, $items);
Expand All @@ -70,9 +66,12 @@ public function testLoopIteratesOnlyValidItems()

$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$filterIteratorModel = new \Magento\Backend\Model\Menu\Filter\Iterator(
$this->_menuModel->getIterator()
);

$items = [];
foreach ($this->_filterIteratorModel as $item) {
foreach ($filterIteratorModel as $item) {
$items[] = $item;
}
$this->assertCount(1, $items);
Expand All @@ -88,9 +87,12 @@ public function testLoopIteratesDosntIterateDisabledItems()

$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$filterIteratorModel = new \Magento\Backend\Model\Menu\Filter\Iterator(
$this->_menuModel->getIterator()
);

$items = [];
foreach ($this->_filterIteratorModel as $item) {
foreach ($filterIteratorModel as $item) {
$items[] = $item;
}
$this->assertCount(1, $items);
Expand All @@ -106,9 +108,12 @@ public function testLoopIteratesDosntIterateNotAllowedItems()

$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$filterIteratorModel = new \Magento\Backend\Model\Menu\Filter\Iterator(
$this->_menuModel->getIterator()
);

$items = [];
foreach ($this->_filterIteratorModel as $item) {
foreach ($filterIteratorModel as $item) {
$items[] = $item;
}
$this->assertCount(1, $items);
Expand All @@ -125,9 +130,12 @@ public function testLoopIteratesMixedItems()

$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$this->_menuModel->add($this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false));
$filterIteratorModel = new \Magento\Backend\Model\Menu\Filter\Iterator(
$this->_menuModel->getIterator()
);

$items = [];
foreach ($this->_filterIteratorModel as $item) {
foreach ($filterIteratorModel as $item) {
$items[] = $item;
}
$this->assertCount(1, $items);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
interface CategoryAttributeInterface extends \Magento\Catalog\Api\Data\EavAttributeInterface
{
const ENTITY_TYPE_CODE = 'catalog_category';

const DEFAULT_ATTRIBUTE_SET_ID = 3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
interface ProductAttributeInterface extends \Magento\Catalog\Api\Data\EavAttributeInterface
{
const ENTITY_TYPE_CODE = 'catalog_product';

const DEFAULT_ATTRIBUTE_SET_ID = 4;
}
17 changes: 14 additions & 3 deletions app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
use Magento\Backend\App\Action;
use Magento\Catalog\Controller\Adminhtml\Product;

/**
* Product validate
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Validate extends \Magento\Catalog\Controller\Adminhtml\Product
{
/**
Expand All @@ -31,27 +36,33 @@ class Validate extends \Magento\Catalog\Controller\Adminhtml\Product
*/
protected $layoutFactory;

/** @var \Magento\Catalog\Model\ProductFactory */
protected $productFactory;

/**
* @param Action\Context $context
* @param Builder $productBuilder
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
* @param \Magento\Catalog\Model\Product\Validator $productValidator
* @param \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
* @param \Magento\Catalog\Model\ProductFactory $productFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
Product\Builder $productBuilder,
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
\Magento\Catalog\Model\Product\Validator $productValidator,
\Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory,
\Magento\Framework\View\LayoutFactory $layoutFactory
\Magento\Framework\View\LayoutFactory $layoutFactory,
\Magento\Catalog\Model\ProductFactory $productFactory
) {
$this->_dateFilter = $dateFilter;
$this->productValidator = $productValidator;
parent::__construct($context, $productBuilder);
$this->resultJsonFactory = $resultJsonFactory;
$this->layoutFactory = $layoutFactory;
$this->productFactory = $productFactory;
}

/**
Expand All @@ -73,13 +84,13 @@ public function execute()
$productData['stock_data']['use_config_manage_stock'] = 0;
}
/* @var $product \Magento\Catalog\Model\Product */
$product = $this->_objectManager->create('Magento\Catalog\Model\Product');
$product = $this->productFactory->create();
$product->setData('_edit_mode', true);
$storeId = $this->getRequest()->getParam('store');
if ($storeId) {
$product->setStoreId($storeId);
}
$setId = $this->getRequest()->getParam('set');
$setId = $this->getRequest()->getPost('set');
if ($setId) {
$product->setAttributeSetId($setId);
}
Expand Down
15 changes: 13 additions & 2 deletions app/code/Magento/Catalog/Model/Category/AttributeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,30 @@ class AttributeRepository implements CategoryAttributeRepositoryInterface
*/
protected $eavAttributeRepository;

/**
* @var \Magento\Eav\Model\Config
*/
protected $eavConfig;

/**
* @param \Magento\Framework\Api\Config\MetadataConfig $metadataConfig
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
* @param \Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository
* @param \Magento\Eav\Model\Config $eavConfig
*/
public function __construct(
\Magento\Framework\Api\Config\MetadataConfig $metadataConfig,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
\Magento\Framework\Api\FilterBuilder $filterBuilder,
\Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository
\Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository,
\Magento\Eav\Model\Config $eavConfig
) {
$this->metadataConfig = $metadataConfig;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->filterBuilder = $filterBuilder;
$this->eavAttributeRepository = $eavAttributeRepository;
$this->eavConfig = $eavConfig;
}

/**
Expand Down Expand Up @@ -69,11 +77,14 @@ public function get($attributeCode)
*/
public function getCustomAttributesMetadata($dataObjectClassName = null)
{
$defaultAttributeSetId = $this->eavConfig
->getEntityType(\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE)
->getDefaultAttributeSetId();
$searchCriteria = $this->searchCriteriaBuilder->addFilter(
[
$this->filterBuilder
->setField('attribute_set_id')
->setValue(\Magento\Catalog\Api\Data\CategoryAttributeInterface::DEFAULT_ATTRIBUTE_SET_ID)
->setValue($defaultAttributeSetId)
->create(),
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,14 @@ public function deleteById($attributeCode)
*/
public function getCustomAttributesMetadata($dataObjectClassName = null)
{
$defaultAttributeSetId = $this->eavConfig
->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)
->getDefaultAttributeSetId();
$searchCriteria = $this->searchCriteriaBuilder->addFilter(
[
$this->filterBuilder
->setField('attribute_set_id')
->setValue(\Magento\Catalog\Api\Data\ProductAttributeInterface::DEFAULT_ATTRIBUTE_SET_ID)
->setValue($defaultAttributeSetId)
->create(),
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public function validate($processingParams, $option)

$upload->addFilter(new \Zend_Filter_File_Rename(['target' => $fileFullPath, 'overwrite' => true]));

// TODO: I don't know how change this
if (!is_null($this->product)) {
$this->product->getTypeInstance()->addFileQueue(
[
Expand Down
17 changes: 14 additions & 3 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
*/
protected $metadataService;

/**
* @var \Magento\Eav\Model\Config
*/
protected $eavConfig;

/**
* @param ProductFactory $productFactory
* @param \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $initializationHelper
Expand All @@ -81,6 +86,8 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
* @param Resource\Product $resourceModel
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $metadataServiceInterface
* @param \Magento\Eav\Model\Config $eavConfig
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
ProductFactory $productFactory,
Expand All @@ -91,7 +98,8 @@ public function __construct(
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository,
\Magento\Catalog\Model\Resource\Product $resourceModel,
\Magento\Framework\Api\FilterBuilder $filterBuilder,
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $metadataServiceInterface
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $metadataServiceInterface,
\Magento\Eav\Model\Config $eavConfig
) {
$this->productFactory = $productFactory;
$this->collectionFactory = $collectionFactory;
Expand All @@ -102,6 +110,7 @@ public function __construct(
$this->attributeRepository = $attributeRepository;
$this->filterBuilder = $filterBuilder;
$this->metadataService = $metadataServiceInterface;
$this->eavConfig = $eavConfig;
}

/**
Expand Down Expand Up @@ -261,12 +270,14 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
{
/** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */
$collection = $this->collectionFactory->create();

$defaultAttributeSetId = $this->eavConfig
->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)
->getDefaultAttributeSetId();
$extendedSearchCriteria = $this->searchCriteriaBuilder->addFilter(
[
$this->filterBuilder
->setField('attribute_set_id')
->setValue(\Magento\Catalog\Api\Data\ProductAttributeInterface::DEFAULT_ATTRIBUTE_SET_ID)
->setValue($defaultAttributeSetId)
->create(),
]
);
Expand Down
Loading

0 comments on commit 10d1600

Please sign in to comment.