Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-64085
Browse files Browse the repository at this point in the history
  • Loading branch information
cpartica committed Aug 25, 2017
2 parents 627019b + 4381a6b commit d88aeeb
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/code/Magento/Catalog/Model/Product/Option/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ public function save(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $opt
$originalValues = $persistedOption->getValues();
$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 @@ -267,4 +267,29 @@ public function testSave()
]);
$this->assertEquals($this->optionMock, $this->optionRepository->save($this->optionMock));
}

public function testSaveWhenOptionTypeWasChanged()
{
$productSku = 'simple_product';
$optionId = 1;
$this->optionMock->expects($this->once())->method('getProductSku')->willReturn($productSku);
$this->productRepositoryMock
->expects($this->once())
->method('get')
->with($productSku)
->willReturn($this->productMock);
$this->optionMock->expects($this->any())->method('getOptionId')->willReturn($optionId);
$this->productMock->expects($this->once())->method('getOptions')->willReturn([]);
$this->optionMock->expects($this->once())->method('getData')->with('values')->willReturn([
['option_type_id' => 4],
['option_type_id' => 5]
]);
$optionCollection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Option\Collection::class)
->disableOriginalConstructor()
->getMock();
$optionCollection->expects($this->once())->method('getProductOptions')->willReturn([$this->optionMock]);
$this->optionCollectionFactory->expects($this->once())->method('create')->willReturn($optionCollection);
$this->optionMock->expects($this->once())->method('getValues')->willReturn(null);
$this->assertEquals($this->optionMock, $this->optionRepository->save($this->optionMock));
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Newsletter/Model/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
} elseif ($isConfirmNeed) {
$status = self::STATUS_NOT_ACTIVE;
}
} elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && ($customerData->getConfirmation() === null)) {
$status = self::STATUS_SUBSCRIBED;
$sendInformationEmail = true;
} else {
$status = self::STATUS_UNSUBSCRIBED;
}
Expand Down
29 changes: 29 additions & 0 deletions app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,35 @@ public function testSubscribeCustomerById1()
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
}

public function testSubscribeCustomerByIdAfterConfirmation()
{
$customerId = 1;
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
->getMock();
$this->customerRepository->expects($this->atLeastOnce())
->method('getById')
->with($customerId)->willReturn($customerDataMock);
$this->resource->expects($this->atLeastOnce())
->method('loadByCustomerData')
->with($customerDataMock)
->willReturn(
[
'subscriber_id' => 1,
'subscriber_status' => 4
]
);
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
$this->sendEmailCheck();
$this->customerAccountManagement->expects($this->never())->method('getConfirmationStatus');
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);

$this->subscriber->updateSubscription($customerId);
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus());
}

public function testUnsubscribe()
{
$this->resource->expects($this->once())->method('save')->willReturnSelf();
Expand Down

0 comments on commit d88aeeb

Please sign in to comment.