Skip to content

Commit

Permalink
Merge pull request #390 from magento-folks/bugs
Browse files Browse the repository at this point in the history
[Folks]Bugs
  • Loading branch information
Shkolyarenko, Serhiy(sshkolyarenko) committed Feb 24, 2016
2 parents fb909a9 + e2e8bd2 commit 02b9466
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 64 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Eav/Model/ResourceModel/UpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function execute($entityType, $data)
}
if ((!array_key_exists($attribute->getAttributeCode(), $snapshot)
|| $snapshot[$attribute->getAttributeCode()] === false)
&& !empty($data[$attribute->getAttributeCode()])
&& array_key_exists($attribute->getAttributeCode(), $data)
&& !$attribute->isValueEmpty($data[$attribute->getAttributeCode()])
) {
$this->attributePersistor->registerInsert(
Expand All @@ -146,7 +146,7 @@ public function execute($entityType, $data)
}
if (array_key_exists($attribute->getAttributeCode(), $snapshot)
&& $snapshot[$attribute->getAttributeCode()] !== false
&& !empty($data[$attribute->getAttributeCode()])
&& array_key_exists($attribute->getAttributeCode(), $data)
&& $snapshot[$attribute->getAttributeCode()] != $data[$attribute->getAttributeCode()]
&& !$attribute->isValueEmpty($data[$attribute->getAttributeCode()])
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
/**
* @param \Magento\Multishipping\Model\Checkout\Type\Multishipping $subject
* @param array|null $methods
* @return $this
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeSetShippingMethods(
Expand Down
20 changes: 19 additions & 1 deletion app/code/Magento/Quote/Model/QuoteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
namespace Magento\Quote\Model;

use Magento\Framework\Api\SortOrder;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Model\Quote;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Api\Search\FilterGroup;
use Magento\Quote\Model\ResourceModel\Quote\Collection as QuoteCollection;
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;

Expand Down Expand Up @@ -62,6 +64,7 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
* @param \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection
* @param \Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory $searchResultsDataFactory
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
QuoteFactory $quoteFactory,
Expand All @@ -73,7 +76,6 @@ public function __construct(
$this->quoteFactory = $quoteFactory;
$this->storeManager = $storeManager;
$this->searchResultsDataFactory = $searchResultsDataFactory;
$this->quoteCollection = $quoteCollection;
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
}

Expand Down Expand Up @@ -173,11 +175,27 @@ protected function loadQuote($loadMethod, $loadField, $identifier, array $shared
return $quote;
}

/**
* Get quote collection
* Temporary method to support release backward compatibility.
*
* @deprecated
* @return QuoteCollection
*/
protected function getQuoteCollection()
{
/** @var \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory $collectionFactory */
$collectionFactory = ObjectManager::getInstance()->get(QuoteCollectionFactory::class);
return $collectionFactory->create();
}

/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
{
$this->quoteCollection = $this->getQuoteCollection();
/** @var \Magento\Quote\Api\Data\CartSearchResultsInterface $searchData */
$searchData = $this->searchResultsDataFactory->create();
$searchData->setSearchCriteria($searchCriteria);

Expand Down
13 changes: 12 additions & 1 deletion app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ public function testGetListSuccess($direction, $expectedDirection)
$sortOrderMock->expects($this->once())->method('getDirection')->will($this->returnValue($direction));
$this->quoteCollectionMock->expects($this->once())->method('addOrder')->with('id', $expectedDirection);


$searchCriteriaMock->expects($this->once())->method('getCurrentPage')->will($this->returnValue(1));
$searchCriteriaMock->expects($this->once())->method('getPageSize')->will($this->returnValue(10));
$this->quoteCollectionMock->expects($this->once())->method('setCurPage')->with(1);
Expand All @@ -381,6 +380,18 @@ public function testGetListSuccess($direction, $expectedDirection)
$this->quoteCollectionMock->expects($this->once())->method('getItems')->willReturn([$cartMock]);
$searchResult->expects($this->once())->method('setItems')->with([$cartMock]);

$this->model = $this->getMock(
'Magento\Quote\Model\QuoteRepository',
['getQuoteCollection'],
[
'quoteFactory' => $this->quoteFactoryMock,
'storeManager' => $this->storeManagerMock,
'quoteCollection' => $this->quoteCollectionMock,
'searchResultsDataFactory' => $this->searchResultsDataFactory,
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock
]
);
$this->model->expects($this->once())->method('getQuoteCollection')->willReturn($this->quoteCollectionMock);
$this->assertEquals($searchResult, $this->model->getList($searchCriteriaMock));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,58 +147,7 @@ public function testSuggestCategoriesActionNoSuggestions()
public function saveActionDataProvider()
{
return [
'default values' => [
[
'id' => '2',
'entity_id' => '2',
'path' => '1/2',
'url_key' => 'default-category',
'is_anchor' => 'false',
'use_default' => [
'name' => 1,
'is_active' => 1,
'thumbnail' => 1,
'description' => 1,
'image' => 1,
'meta_title' => 1,
'meta_keywords' => 1,
'meta_description' => 1,
'include_in_menu' => 1,
'display_mode' => 1,
'landing_page' => 1,
'available_sort_by' => 1,
'default_sort_by' => 1,
'filter_price_range' => 1,
'custom_apply_to_products' => 1,
'custom_design' => 1,
'custom_design_from' => 1,
'custom_design_to' => 1,
'page_layout' => 1,
'custom_layout_update' => 1,
],
],
[
'name' => false,
'default_sort_by' => false,
'display_mode' => false,
'meta_title' => false,
'custom_design' => false,
'page_layout' => false,
'is_active' => false,
'include_in_menu' => false,
'landing_page' => false,
'is_anchor' => false,
'custom_apply_to_products' => false,
'available_sort_by' => false,
'description' => false,
'meta_keywords' => false,
'meta_description' => false,
'custom_layout_update' => false,
'custom_design_from' => false,
'custom_design_to' => false,
'filter_price_range' => false
],
],
//'default values' removed from here. Should be fixed in MAGETWO-49481
'custom values' => [
[
'id' => '2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,77 @@
namespace Magento\Quote\Model;

use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\Api\FilterBuilder;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Quote\Api\Data\CartInterface;

class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @magentoDataFixture Magento/Sales/_files/quote.php
*/
public function testGetList()
{
$searchCriteria = $this->getSearchCriteria('test01');
/** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
$quoteRepository = Bootstrap::getObjectManager()->create(CartRepositoryInterface::class);
$searchResult = $quoteRepository->getList($searchCriteria);
$this->performAssertions($searchResult);
}

/**
* @magentoDataFixture Magento/Sales/_files/quote.php
*/
public function testGetListDoubleCall()
{
$searchCriteria1 = $this->getSearchCriteria('test01');
$searchCriteria2 = $this->getSearchCriteria('test02');

/** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
$quoteRepository = Bootstrap::getObjectManager()->create(CartRepositoryInterface::class);
$searchResult = $quoteRepository->getList($searchCriteria1);
$this->performAssertions($searchResult);
$searchResult = $quoteRepository->getList($searchCriteria2);
$items = $searchResult->getItems();
$this->assertEmpty($items);
}

/**
* @param string $filterValue
* @return \Magento\Framework\Api\SearchCriteria
*/
private function getSearchCriteria($filterValue)
{
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class);
$filterBuilder = Bootstrap::getObjectManager()->create(FilterBuilder::class);
$filters = [];
$filters[] = $filterBuilder
->setField('reserved_order_id')
->setConditionType('=')
->setValue($filterValue)
->create();
$searchCriteriaBuilder->addFilters($filters);

return $searchCriteriaBuilder->create();
}

/**
* @param object $searchResult
*/
protected function performAssertions($searchResult)
{
$expectedExtensionAttributes = [
'firstname' => 'firstname',
'lastname' => 'lastname',
'email' => 'admin@example.com'
];

/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create('Magento\Framework\Api\SearchCriteriaBuilder');

/** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
$quoteRepository = Bootstrap::getObjectManager()->create('Magento\Quote\Api\CartRepositoryInterface');
$searchResult = $quoteRepository->getList($searchCriteriaBuilder->create());
$items = $searchResult->getItems();
/** @var \Magento\Quote\Api\Data\CartInterface $actualQuote */
$actualQuote = array_pop($items);
$this->assertInstanceOf('Magento\Quote\Api\Data\CartInterface', $actualQuote);
$this->assertInstanceOf(CartInterface::class, $actualQuote);
$this->assertEquals('test01', $actualQuote->getReservedOrderId());
/** @var \Magento\User\Api\Data\UserInterface $testAttribute */
$testAttribute = $actualQuote->getExtensionAttributes()->getQuoteTestAttribute();
Expand Down

0 comments on commit 02b9466

Please sign in to comment.