Skip to content

Commit

Permalink
Merge pull request #464 from magento-folks/bugs
Browse files Browse the repository at this point in the history
Fixed issues:
- MAGETWO-56938: CLONE - [Github] API salesOrderRepositoryV1 can't create shipping address #5544
- MAGETWO-55342: [GITHUB] Free shiping coupon usage is not tracked #3506
- MAGETWO-59137: It's impossible to create a catalog price rule
- MAGETWO-59090: [Github] Admin can't reset password for more than one customer #5260
- MAGETWO-58182: [Github] Minicart item count is not updated if switch from https to http #6487
  • Loading branch information
MomotenkoNatalia authored Oct 5, 2016
2 parents eb50977 + a065ef5 commit 2cacd80
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
<item name="source" xsi:type="string">catalog_rule</item>
<item name="dataScope" xsi:type="string">customer_group_ids</item>
</item>
<item name="options" xsi:type="object">\Magento\Customer\Model\Customer\Source\GroupSourceInterface</item>
<item name="options" xsi:type="object">\Magento\CatalogRule\Model\Rule\CustomerGroupsOptionsProvider</item>
</argument>
</field>
<field name="from_date">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Customer\Controller\Adminhtml\Index;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\SecurityViolationException;

class ResetPassword extends \Magento\Customer\Controller\Adminhtml\Index
{
Expand Down Expand Up @@ -40,6 +41,8 @@ public function execute()
$messages = $exception->getMessage();
}
$this->_addSessionErrorMessages($messages);
} catch (SecurityViolationException $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
} catch (\Exception $exception) {
$this->messageManager->addException(
$exception,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function setUp()
$this->messageManager = $this->getMockBuilder(
\Magento\Framework\Message\Manager::class
)->disableOriginalConstructor()->setMethods(
['addSuccess', 'addMessage', 'addException']
['addSuccess', 'addMessage', 'addException', 'addErrorMessage']
)->getMock();

$this->resultRedirectFactoryMock = $this->getMockBuilder(
Expand Down Expand Up @@ -332,6 +332,56 @@ public function testResetPasswordActionCoreException()
$this->_testedObject->execute();
}

public function testResetPasswordActionSecurityException()
{
$securityText = 'Security violation.';
$exception = new \Magento\Framework\Exception\SecurityViolationException(__($securityText));
$customerId = 1;
$email = 'some@example.com';
$websiteId = 1;

$this->_request->expects(
$this->once()
)->method(
'getParam'
)->with(
$this->equalTo('customer_id'),
$this->equalTo(0)
)->will(
$this->returnValue($customerId)
);
$customer = $this->getMockForAbstractClass(
\Magento\Customer\Api\Data\CustomerInterface::class,
['getId', 'getEmail', 'getWebsiteId']
);
$customer->expects($this->once())->method('getEmail')->will($this->returnValue($email));
$customer->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
$this->_customerRepositoryMock->expects(
$this->once()
)->method(
'getById'
)->with(
$customerId
)->will(
$this->returnValue($customer)
);
$this->_customerAccountManagementMock->expects(
$this->once()
)->method(
'initiatePasswordReset'
)->willThrowException($exception);

$this->messageManager->expects(
$this->once()
)->method(
'addErrorMessage'
)->with(
$this->equalTo($exception->getMessage())
);

$this->_testedObject->execute();
}

public function testResetPasswordActionCoreExceptionWarn()
{
$warningText = 'Warning';
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Sales/Model/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ public function deleteById($id)
*/
public function save(\Magento\Sales\Api\Data\OrderInterface $entity)
{
/** @var \Magento\Sales\Api\Data\OrderExtensionInterface $extensionAttributes */
$extensionAttributes = $entity->getExtensionAttributes();
if ($entity->getIsNotVirtual() && $extensionAttributes && $extensionAttributes->getShippingAssignments()) {
$shippingAssignments = $extensionAttributes->getShippingAssignments();
if (!empty($shippingAssignments)) {
$shipping = array_shift($shippingAssignments)->getShipping();
$entity->setShippingAddress($shipping->getAddress());
$entity->setShippingMethod($shipping->getMethod());
}
}
$this->metadata->getMapper()->save($entity);
$this->registry[$entity->getEntityId()] = $entity;
return $this->registry[$entity->getEntityId()];
Expand Down
36 changes: 36 additions & 0 deletions app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,40 @@ public function testGetList()

$this->assertEquals($collectionMock, $this->model->getList($searchCriteriaMock));
}

public function testSave()
{
$mapperMock = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order::class)
->disableOriginalConstructor()
->getMock();
$orderEntity = $this->getMock(\Magento\Sales\Model\Order::class, [], [], '', false);
$extensionAttributes = $this->getMock(
\Magento\Sales\Api\Data\OrderExtension::class,
['getShippingAssignments'],
[],
'',
false
);
$shippingAssignment = $this->getMockBuilder(\Magento\Sales\Model\Order\ShippingAssignment::class)
->disableOriginalConstructor()
->setMethods(['getShipping'])
->getMock();
$shippingMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Shipping::class)
->disableOriginalConstructor()
->setMethods(['getAddress', 'getMethod'])
->getMock();
$orderEntity->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes);
$orderEntity->expects($this->once())->method('getIsNotVirtual')->willReturn(true);
$extensionAttributes
->expects($this->any())
->method('getShippingAssignments')
->willReturn([$shippingAssignment]);
$shippingAssignment->expects($this->once())->method('getShipping')->willReturn($shippingMock);
$shippingMock->expects($this->once())->method('getAddress');
$shippingMock->expects($this->once())->method('getMethod');
$this->metadata->expects($this->once())->method('getMapper')->willReturn($mapperMock);
$mapperMock->expects($this->once())->method('save');
$orderEntity->expects($this->any())->method('getEntityId')->willReturn(1);
$this->model->save($orderEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function execute(EventObserver $observer)
{
$order = $observer->getEvent()->getOrder();

if (!$order || $order->getDiscountAmount() == 0) {
if (!$order || !$order->getAppliedRuleIds()) {
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public function testSalesOrderAfterPlaceWithoutRuleId()
{
$observer = $this->getMock(\Magento\Framework\Event\Observer::class, [], [], '', false);
$order = $this->initOrderFromEvent($observer);
$discountAmount = 10;
$ruleIds = null;
$order->expects($this->once())
->method('getDiscountAmount')
->will($this->returnValue($discountAmount));
->method('getAppliedRuleIds')
->will($this->returnValue($ruleIds));

$this->ruleFactory->expects($this->never())
->method('create');
Expand Down Expand Up @@ -158,14 +158,10 @@ public function testSalesOrderAfterPlace($ruleCustomerId)
$ruleId = 1;
$couponId = 1;
$customerId = 1;
$discountAmount = 10;

$order->expects($this->once())
$order->expects($this->exactly(2))
->method('getAppliedRuleIds')
->will($this->returnValue($ruleId));
$order->expects($this->once())
->method('getDiscountAmount')
->will($this->returnValue($discountAmount));
$order->expects($this->once())
->method('getCustomerId')
->will($this->returnValue($customerId));
Expand Down
12 changes: 10 additions & 2 deletions app/code/Magento/Security/Model/Plugin/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,26 @@ class AccountManagement
*/
protected $securityManager;

/**
* @var int
*/
protected $passwordRequestEvent;

/**
* AccountManagement constructor.
*
* @param \Magento\Framework\App\RequestInterface $request
* @param SecurityManager $securityManager
* @param int $passwordRequestEvent
*/
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Security\Model\SecurityManager $securityManager
\Magento\Security\Model\SecurityManager $securityManager,
$passwordRequestEvent = PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST
) {
$this->request = $request;
$this->securityManager = $securityManager;
$this->passwordRequestEvent = $passwordRequestEvent;
}

/**
Expand All @@ -56,7 +64,7 @@ public function beforeInitiatePasswordReset(
$websiteId = null
) {
$this->securityManager->performSecurityCheck(
PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST,
$this->passwordRequestEvent,
$email
);
return [$email, $template, $websiteId];
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Security/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<type name="Magento\Backend\Controller\Adminhtml\Auth\Login">
<plugin name="security_login_form" type="Magento\Security\Model\Plugin\LoginController" />
</type>
<type name="Magento\Security\Model\Plugin\AccountManagement">
<arguments>
<argument name="passwordRequestEvent" xsi:type="const">Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST</argument>
</arguments>
</type>
<type name="Magento\Security\Model\SecurityManager">
<arguments>
<argument name="securityCheckers" xsi:type="array">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ define([
customerData.set('messages', {});
}

$.cookieStorage.setConf({path: '/', expires: -1}).set('mage-messages', null);
$.cookieStorage.set('mage-messages', '');
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ protected function setUp()
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function prepareOrder()
{
/** @var \Magento\Sales\Model\Order $orderBuilder */
Expand All @@ -41,6 +44,8 @@ protected function prepareOrder()
$orderPaymentFactory = $this->objectManager->get(\Magento\Sales\Model\Order\PaymentFactory::class);
/** @var \Magento\Sales\Model\Order\AddressRepository $orderAddressRepository */
$orderAddressRepository = $this->objectManager->get(\Magento\Sales\Model\Order\AddressRepository::class);
/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
$storeManager = $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);

$order = $orderFactory->create(
['data' => $this->getDataStructure(\Magento\Sales\Api\Data\OrderInterface::class)]
Expand Down Expand Up @@ -68,6 +73,32 @@ protected function prepareOrder()
$order->setCustomerEmail($email);
$order->setBaseGrandTotal(100);
$order->setGrandTotal(100);
$order->setShippingDescription('Flat Rate - Fixed');
$order->setIsVirtual(0);
$order->setStoreId($storeManager->getDefaultStoreView()->getId());
$order->setBaseDiscountAmount(0);
$order->setBaseShippingAmount(5);
$order->setBaseShippingTaxAmount(0);
$order->setBaseSubtotal(100);
$order->setBaseTaxAmount(0);
$order->setBaseToGlobalRate(1);
$order->setBaseToOrderRate(1);
$order->setDiscountAmount(0);
$order->setShippingAmount(0);
$order->setShippingTaxAmount(0);
$order->setStoreToOrderRate(0);
$order->setBaseToOrderRate(0);
$order->setSubtotal(100);
$order->setTaxAmount(0);
$order->setTotalQtyOrdered(1);
$order->setCustomerIsGuest(1);
$order->setCustomerNoteNotify(0);
$order->setCustomerGroupId(0);
$order->setBaseSubtotalInclTax(100);
$order->setWeight(1);
$order->setBaseCurrencyCode('USD');
$order->setShippingInclTax(5);
$order->setBaseShippingInclTax(5);

$this->addProductOption($orderItem);

Expand All @@ -82,12 +113,39 @@ protected function prepareOrder()
$orderAddressBilling->setFirstname('First Name');
$orderAddressBilling->setTelephone('+00(000)-123-45-57');
$orderAddressBilling->setStreet(['Street']);
$orderAddressBilling->setCountryId(1);
$orderAddressBilling->setCountryId('US');
$orderAddressBilling->setRegion('California');
$orderAddressBilling->setAddressType('billing');
$orderAddressBilling->setRegionId(12);

$orderAddressShipping = $orderAddressRepository->create();
$orderAddressShipping->setCity('City2');
$orderAddressShipping->setPostcode('12345');
$orderAddressShipping->setLastname('Last Name2');
$orderAddressShipping->setFirstname('First Name2');
$orderAddressShipping->setTelephone('+00(000)-123-45-57');
$orderAddressShipping->setStreet(['Street']);
$orderAddressShipping->setCountryId('US');
$orderAddressShipping->setRegion('California');
$orderAddressShipping->setAddressType('shipping');
$orderAddressShipping->setRegionId(12);

$orderData = $order->getData();
$orderData['billing_address'] = $orderAddressBilling->getData();
$orderData['billing_address']['street'] = ['Street'];
$address = $orderAddressShipping->getData();
$address['street'] = ['Street'];
$orderData['extension_attributes']['shipping_assignments'] =
[
[
'shipping' => [
'address' => $address,
'method' => 'Flat Rate - Fixed'
],
'items' => [$orderItem->getData()],
'stock_id' => null,
]
];
return $orderData;
}

Expand Down Expand Up @@ -172,5 +230,8 @@ public function testOrderCreate()
$this->assertTrue((bool)$model->getId());
$this->assertEquals($order['base_grand_total'], $model->getBaseGrandTotal());
$this->assertEquals($order['grand_total'], $model->getGrandTotal());
$this->assertNotNull($model->getShippingAddress());
$this->assertTrue((bool)$model->getShippingAddress()->getId());
$this->assertEquals('Flat Rate - Fixed', $model->getShippingMethod());
}
}
Loading

0 comments on commit 2cacd80

Please sign in to comment.