Skip to content

Commit

Permalink
Merge pull request #77 from magento-epam/2.3-develop
Browse files Browse the repository at this point in the history
Merge 2.3-develop to EPAM-PR-2
  • Loading branch information
nikshostko authored Aug 19, 2018
2 parents d6594b0 + 6d3dab2 commit cc5d074
Show file tree
Hide file tree
Showing 40 changed files with 652 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ protected function isValidOptionTitle($title, $storeId)
if ($storeId > \Magento\Store\Model\Store::DEFAULT_STORE_ID && $title === null) {
return true;
}
if ($this->isEmpty($title)) {

// checking whether title is null and is empty string
if ($title === null || $title === '') {
return false;
}

Expand All @@ -132,7 +134,7 @@ protected function validateOptionType(Option $option)
*/
protected function validateOptionValue(Option $option)
{
return $this->isInRange($option->getPriceType(), $this->priceTypes) && !$this->isNegative($option->getPrice());
return $this->isInRange($option->getPriceType(), $this->priceTypes);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function isValidOptionPrice($priceType, $price, $storeId)
if (!$priceType && !$price) {
return true;
}
if (!$this->isInRange($priceType, $this->priceTypes) || $this->isNegative($price)) {
if (!$this->isInRange($priceType, $this->priceTypes)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ protected function _saveValueTitles(AbstractModel $object)
$object->unsetData('title');
}

if ($object->getTitle()) {
/*** Checking whether title is not null ***/
if ($object->getTitle()!= null) {
if ($existInCurrentStore) {
if ($storeId == $object->getStoreId()) {
$where = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class DefaultValidatorTest extends \PHPUnit\Framework\TestCase
*/
protected $valueMock;

/**
* @inheritdoc
*/
protected function setUp()
{
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
Expand Down Expand Up @@ -60,31 +63,30 @@ public function isValidTitleDataProvider()
{
$mess = ['option required fields' => 'Missed values for option required fields'];
return [
['option_title', 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
['option_title', 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 0]), [], true],
[null, 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
[null, 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 0]), $mess, false],
['option_title', 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
['option_title', 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 0]), [], true],
[null, 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
[null, 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 0]), $mess, false],
];
}

/**
* @param $title
* @param $type
* @param $priceType
* @param $price
* @param $product
* @param $messages
* @param $result
* @param string $title
* @param string $type
* @param string $priceType
* @param \Magento\Framework\DataObject $product
* @param array $messages
* @param bool $result
* @dataProvider isValidTitleDataProvider
*/
public function testIsValidTitle($title, $type, $priceType, $price, $product, $messages, $result)
public function testIsValidTitle($title, $type, $priceType, $product, $messages, $result)
{
$methods = ['getTitle', 'getType', 'getPriceType', 'getPrice', '__wakeup', 'getProduct'];
$methods = ['getTitle', 'getType', 'getPriceType', '__wakeup', 'getProduct'];
$valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods);
$valueMock->expects($this->once())->method('getTitle')->will($this->returnValue($title));
$valueMock->expects($this->any())->method('getType')->will($this->returnValue($type));
$valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue($priceType));
$valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
// $valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
$valueMock->expects($this->once())->method('getProduct')->will($this->returnValue($product));
$this->assertEquals($result, $this->validator->isValid($valueMock));
$this->assertEquals($messages, $this->validator->getMessages());
Expand All @@ -104,7 +106,7 @@ public function isValidFailDataProvider()
}

/**
* @param $product
* @param \Magento\Framework\DataObject $product
* @dataProvider isValidFailDataProvider
*/
public function testIsValidFail($product)
Expand All @@ -124,41 +126,4 @@ public function testIsValidFail($product)
$this->assertFalse($this->validator->isValid($valueMock));
$this->assertEquals($messages, $this->validator->getMessages());
}

/**
* Data provider for testValidationNegativePrice
* @return array
*/
public function validationNegativePriceDataProvider()
{
return [
['option_title', 'name 1.1', 'fixed', -12, new \Magento\Framework\DataObject(['store_id' => 1])],
['option_title', 'name 1.1', 'fixed', -12, new \Magento\Framework\DataObject(['store_id' => 0])],
];
}

/**
* @param $title
* @param $type
* @param $priceType
* @param $price
* @param $product
* @dataProvider validationNegativePriceDataProvider
*/
public function testValidationNegativePrice($title, $type, $priceType, $price, $product)
{
$methods = ['getTitle', 'getType', 'getPriceType', 'getPrice', '__wakeup', 'getProduct'];
$valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods);
$valueMock->expects($this->once())->method('getTitle')->will($this->returnValue($title));
$valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue($type));
$valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue($priceType));
$valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
$valueMock->expects($this->once())->method('getProduct')->will($this->returnValue($product));

$messages = [
'option values' => 'Invalid option value',
];
$this->assertFalse($this->validator->isValid($valueMock));
$this->assertEquals($messages, $this->validator->getMessages());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class FileTest extends \PHPUnit\Framework\TestCase
*/
protected $valueMock;

/**
* @inheritdoc
*/
protected function setUp()
{
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
Expand Down Expand Up @@ -54,24 +57,34 @@ protected function setUp()
);
}

/**
* @return void
*/
public function testIsValidSuccess()
{
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
$this->valueMock->method('getPriceType')
->willReturn('fixed');
$this->valueMock->method('getPrice')
->willReturn(10);
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(10));
$this->valueMock->expects($this->once())->method('getImageSizeY')->will($this->returnValue(15));
$this->assertEmpty($this->validator->getMessages());
$this->assertTrue($this->validator->isValid($this->valueMock));
}

/**
* @return void
*/
public function testIsValidWithNegativeImageSize()
{
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
$this->valueMock->method('getPriceType')
->willReturn('fixed');
$this->valueMock->method('getPrice')
->willReturn(10);
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(-10));
$this->valueMock->expects($this->never())->method('getImageSizeY');
$messages = [
Expand All @@ -81,12 +94,17 @@ public function testIsValidWithNegativeImageSize()
$this->assertEquals($messages, $this->validator->getMessages());
}

/**
* @return void
*/
public function testIsValidWithNegativeImageSizeY()
{
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
$this->valueMock->method('getPriceType')
->willReturn('fixed');
$this->valueMock->method('getPrice')
->willReturn(10);
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(10));
$this->valueMock->expects($this->once())->method('getImageSizeY')->will($this->returnValue(-10));
$messages = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class SelectTest extends \PHPUnit\Framework\TestCase
*/
protected $valueMock;

/**
* @inheritdoc
*/
protected function setUp()
{
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
Expand Down Expand Up @@ -90,7 +93,7 @@ public function isValidSuccessDataProvider()
]
],
[
false,
true,
[
'title' => 'Some Title',
'price_type' => 'fixed',
Expand All @@ -100,6 +103,9 @@ public function isValidSuccessDataProvider()
];
}

/**
* @return void
*/
public function testIsValidateWithInvalidOptionValues()
{
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
Expand All @@ -118,6 +124,9 @@ public function testIsValidateWithInvalidOptionValues()
$this->assertEquals($messages, $this->validator->getMessages());
}

/**
* @return void
*/
public function testIsValidateWithEmptyValues()
{
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
Expand Down Expand Up @@ -163,7 +172,6 @@ public function testIsValidateWithInvalidData($priceType, $price, $title)
public function isValidateWithInvalidDataDataProvider()
{
return [
'invalid_price' => ['fixed', -10, 'Title'],
'invalid_price_type' => ['some_value', '10', 'Title'],
'empty_title' => ['fixed', 10, null]
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class TextTest extends \PHPUnit\Framework\TestCase
*/
protected $valueMock;

/**
* @inheritdoc
*/
protected function setUp()
{
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
Expand Down Expand Up @@ -54,23 +57,33 @@ protected function setUp()
);
}

/**
* @return void
*/
public function testIsValidSuccess()
{
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
$this->valueMock->method('getPriceType')
->willReturn('fixed');
$this->valueMock->method('getPrice')
->willReturn(10);
$this->valueMock->expects($this->once())->method('getMaxCharacters')->will($this->returnValue(10));
$this->assertTrue($this->validator->isValid($this->valueMock));
$this->assertEmpty($this->validator->getMessages());
}

/**
* @return void
*/
public function testIsValidWithNegativeMaxCharacters()
{
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
$this->valueMock->method('getPriceType')
->willReturn('fixed');
$this->valueMock->method('getPrice')
->willReturn(10);
$this->valueMock->expects($this->once())->method('getMaxCharacters')->will($this->returnValue(-10));
$messages = [
'option values' => 'Invalid option value',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
* @since 101.0.0
*/
public function modifyData(array $data)
Expand Down Expand Up @@ -226,7 +226,7 @@ protected function formatPriceByPath($path, array $data)
}

/**
* {@inheritdoc}
* @inheritdoc
* @since 101.0.0
*/
public function modifyMeta(array $meta)
Expand Down Expand Up @@ -923,7 +923,7 @@ protected function getPriceFieldConfig($sortOrder)
'addbeforePool' => $this->productOptionsPrice->prefixesToOptionArray(),
'sortOrder' => $sortOrder,
'validation' => [
'validate-zero-or-greater' => true
'validate-number' => true
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ
}

if (!$this->checkQty($stockItem, $summaryQty) || !$this->checkQty($stockItem, $qty)) {
$message = __('We don\'t have as many "%1" as you requested.', $stockItem->getProductName());
$message = __('The requested qty is not available');
$result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qty');
return $result;
} else {
Expand Down Expand Up @@ -212,7 +212,7 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ
}
} elseif ($stockItem->getShowDefaultNotificationMessage()) {
$result->setMessage(
__('We don\'t have as many "%1" as you requested.', $stockItem->getProductName())
__('The requested qty is not available')
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Checkout/view/frontend/web/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,23 @@ define([
};
events['click ' + this.options.button.checkout] = $.proxy(function () {
var cart = customerData.get('cart'),
customer = customerData.get('customer');
customer = customerData.get('customer'),
element = $(this.options.button.checkout);

if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
// set URL for redirect on successful login/registration. It's postprocessed on backend.
$.cookie('login_redirect', this.options.url.checkout);

if (this.options.url.isRedirectRequired) {
element.prop('disabled', true);
location.href = this.options.url.loginUrl;
} else {
authenticationPopup.showModal();
}

return false;
}
element.prop('disabled', true);
location.href = this.options.url.checkout;
}, this);

Expand Down
Loading

0 comments on commit cc5d074

Please sign in to comment.