Skip to content

Commit

Permalink
Merge branch '2.3-develop-php74' of github.com:magento-commerce/magen…
Browse files Browse the repository at this point in the history
…to2ce into MC-40562
  • Loading branch information
svera committed Feb 23, 2021
2 parents f4b1567 + 09464e0 commit df19533
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 70 deletions.
7 changes: 6 additions & 1 deletion app/code/Magento/Captcha/Model/DefaultModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,12 @@ public function getWord()
private function getWords()
{
$sessionData = $this->session->getData($this->getFormIdKey(self::SESSION_WORD));
return time() < $sessionData['expires'] ? $sessionData['words'] : null;
$words = '';
if (isset($sessionData['expires'], $sessionData['words']) && time() < $sessionData['expires']) {
$words = $sessionData['words'];
}

return $words;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion app/code/Magento/Catalog/Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ public function getLayer()
*/
public function getLoadedProductCollection()
{
return $this->_getProductCollection();
$collection = $this->_getProductCollection();
$categoryId = $this->getLayer()->getCurrentCategory()->getId();
foreach ($collection as $product) {
$product->setData('category_id', $categoryId);
}

return $collection;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ public function execute()
$attributeCode = $model && $model->getId()
? $model->getAttributeCode()
: $this->getRequest()->getParam('attribute_code');
$attributeCode = $attributeCode ?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]);

if (!$attributeCode) {
$frontendLabel = $this->getRequest()->getParam('frontend_label')[0] ?? '';
$attributeCode = $this->generateCode($frontendLabel);
}

$data['attribute_code'] = $attributeCode;

//validate frontend_input
Expand Down
9 changes: 7 additions & 2 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,14 @@ public function getIdBySku($sku)
*/
public function getCategoryId()
{
if ($this->hasData('category_id')) {
return $this->getData('category_id');
}
$category = $this->_registry->registry('current_category');
if ($category && in_array($category->getId(), $this->getCategoryIds())) {
return $category->getId();
$categoryId = $category ? $category->getId() : null;
if ($categoryId && in_array($categoryId, $this->getCategoryIds())) {
$this->setData('category_id', $categoryId);
return $categoryId;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;

/**
* Controller for save creditmemo
*/
class Save extends \Magento\Backend\App\Action implements HttpPostActionInterface
{
/**
Expand Down Expand Up @@ -54,6 +57,7 @@ public function __construct(

/**
* Save creditmemo
*
* We can save only new creditmemo. Existing creditmemos are not editable
*
* @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward
Expand Down Expand Up @@ -104,7 +108,8 @@ public function execute()
\Magento\Sales\Api\CreditmemoManagementInterface::class
);
$creditmemo->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
$creditmemoManagement->refund($creditmemo, (bool)$data['do_offline']);
$doOffline = isset($data['do_offline']) ? (bool)$data['do_offline'] : false;
$creditmemoManagement->refund($creditmemo, $doOffline);

if (!empty($data['send_email'])) {
$this->creditmemoSender->send($creditmemo);
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Wishlist/Model/LocaleQuantityProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace Magento\Wishlist\Model;

/**
* Class LocaleQuantityProcessor for localized quantity to internal format
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -43,7 +45,7 @@ public function __construct(
public function process($qty)
{
$this->localFilter->setOptions(['locale' => $this->localeResolver->getLocale()]);
$qty = $this->localFilter->filter((double)$qty);
$qty = $this->localFilter->filter((string)$qty);
if ($qty < 0) {
$qty = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function dispatch($uri)
$request = $this->getRequest();
$request->setRequestUri($uri);
if ($request->isPost()
&& !array_key_exists('form_key', $request->getPost())
&& !property_exists($request->getPost(), 'form_key')
) {
/** @var FormKey $formKey */
$formKey = $this->_objectManager->get(FormKey::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ public function testGetAdditionalHtml()

public function testSetCollection()
{
$this->_block->setCollection('test');
$this->assertEquals('test', $this->_block->getLoadedProductCollection());
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\Framework\Data\Collection::class);
$this->_block->setCollection($collection);
$this->assertEquals($collection, $this->_block->getLoadedProductCollection());
}

public function testGetPriceBlockTemplate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public function testGetParentIds()
$this->assertEmpty($this->_model->getParentIds());
$this->_model->unsetData();
$this->_model->load(4);
$this->assertTrue(in_array(3, $this->_model->getParentIds()));
$this->assertFalse(in_array(4, $this->_model->getParentIds()));
$this->assertContainsEquals(3, $this->_model->getParentIds());
$this->assertNotContainsEquals(4, $this->_model->getParentIds());
}

public function testGetChildren()
Expand Down Expand Up @@ -167,9 +167,9 @@ public function testGetLevel()
public function testGetAnchorsAbove()
{
$this->_model->load(4);
$this->assertTrue(in_array(3, $this->_model->getAnchorsAbove()));
$this->assertContainsEquals(3, $this->_model->getAnchorsAbove());
$this->_model->load(5);
$this->assertTrue(in_array(4, $this->_model->getAnchorsAbove()));
$this->assertContainsEquals(4, $this->_model->getAnchorsAbove());
}

public function testGetParentCategories()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testUrlKeyHasChangedInGlobalContext()
];
$actual = $this->getActualResults($productFilter);
foreach ($expected as $row) {
$this->assertTrue(in_array($row, $actual));
$this->assertContainsEquals($row, $actual);
}

$product->setData('save_rewrites_history', true);
Expand Down Expand Up @@ -126,7 +126,7 @@ public function testUrlKeyHasChangedInGlobalContext()

$actual = $this->getActualResults($productFilter);
foreach ($expected as $row) {
$this->assertTrue(in_array($row, $actual));
$this->assertContainsEquals($row, $actual);
}
}

Expand Down Expand Up @@ -182,7 +182,7 @@ public function testUrlKeyHasChangedInStoreviewContextWithPermanentRedirection()

$actual = $this->getActualResults($productFilter);
foreach ($expected as $row) {
$this->assertTrue(in_array($row, $actual));
$this->assertContainsEquals($row, $actual);
}
}

Expand Down Expand Up @@ -231,7 +231,7 @@ public function testUrlKeyHasChangedInStoreviewContextWithoutPermanentRedirectio

$actual = $this->getActualResults($productFilter);
foreach ($expected as $row) {
$this->assertTrue(in_array($row, $actual));
$this->assertContainsEquals($row, $actual);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ public function testAddProductFromUnavailableWebsite(): void
public function testAddProductWithUnavailableQty(): void
{
$product = $this->productRepository->get('simple-1');
$postData = ['product' => $product->getId(), 'qty' => 1000];
$postData = ['product' => $product->getId(), 'qty' => '1000'];
$this->dispatchAddToCartRequest($postData);
$this->assertRedirect($this->stringContains($product->getProductUrl()));
$message = (string)__('The requested qty is not available');
$this->assertSessionMessages($this->containsEqual($message), MessageInterface::TYPE_ERROR);
$this->assertRedirect($this->stringContains($product->getProductUrl()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,7 @@ public function testCreateCustomerErrors(array $postData, array $expectedData, a
);
$customerFormData = $this->session->getCustomerFormData();
unset($customerFormData['form_key']);
if (!empty($expectedData) && !empty($customerFormData)) {
$expectedData = array_shift($expectedData);
$customerFormData = array_shift($customerFormData);
}
$this->assertEmpty(array_diff_assoc($expectedData, $customerFormData));
$this->assertEquals($expectedData, $customerFormData);
$this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'new/key/'));
}

Expand Down Expand Up @@ -389,12 +385,9 @@ public function testCreateSameEmailFormatDateError(): void
$customerFormData = $this->session->getCustomerFormData();
$this->assertNotEmpty($customerFormData);
unset($customerFormData['form_key']);
if (!empty($customerFormData)) {
$customerFormData = array_shift($customerFormData);
$postFormatted = array_shift($postFormatted);
}
$this->assertEmpty(
array_diff_assoc($postFormatted, $customerFormData),
$this->assertEquals(
$postFormatted,
$customerFormData,
'Customer form data should be formatted'
);
$this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'new/key/'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,6 @@ protected function setUp(): void
);
}

/**
* Test constructor
*
* @magentoDataFixture Magento/Customer/_files/import_export/customer_with_addresses.php
*/
public function testConstruct()
{
$this->assertObjectHasAttribute('_entityTable', $this->_entityAdapter, 'Entity table must not be empty');
$this->assertObjectHasAttribute('errorMessageTemplates', $this->_entityAdapter, 'Templates must not be empty');
$this->assertObjectHasAttribute('_attributes', $this->_entityAdapter, 'Attributes must not be empty');
$this->assertObjectHasAttribute('_countryRegions', $this->_entityAdapter, 'Country regions must not be empty');
$this->assertObjectHasAttribute('_regions', $this->_entityAdapter, 'Regions must not be empty');
}

/**
* Test _saveAddressEntity
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testAddNewOptions()
$optionsAfter = $this->getAttributeOptions(false);
$this->assertEquals(count($optionsBefore) + 2, count($optionsAfter));
foreach ($optionsBefore as $option) {
$this->assertTrue(in_array($option, $optionsAfter));
$this->assertContainsEquals($option, $optionsAfter);
}
}

Expand All @@ -119,7 +119,7 @@ public function testAddExistingOptionsWithTheSameSortOrder()
$optionsAfter = $this->getAttributeOptions();
$this->assertEquals(count($optionsBefore), count($optionsAfter));
foreach ($optionsBefore as $option) {
$this->assertTrue(in_array($option, $optionsAfter));
$this->assertContainsEquals($option, $optionsAfter);
}
}

Expand Down Expand Up @@ -202,7 +202,7 @@ public function testDeleteOption()
);
$updatedOptions = $this->getAttributeOptions();
foreach ($updatedOptions as $option) {
$this->assertTrue(in_array($option, $optionsBefore));
$this->assertContainsEquals($option, $optionsBefore);
}
$this->assertEquals(count($updatedOptions), count($optionsBefore) - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\Newsletter\Model;

use Laminas\Mail\Headers;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
use Magento\Customer\Api\AccountManagementInterface;
Expand Down Expand Up @@ -120,12 +121,27 @@ public function testUnsubscribeSubscribe(): void
$subscriber = $this->subscriberFactory->create();
$this->assertSame($subscriber, $subscriber->loadByCustomerId(1));
$this->assertEquals($subscriber, $subscriber->unsubscribe());
$this->assertStringContainsString('You have been unsubscribed from the newsletter.', $this->transportBuilder->getSentMessage()->getRawMessage());
$this->assertStringContainsString(
'You have been unsubscribed from the newsletter.',
$this->getFilteredRawMessage($this->transportBuilder)
);
$this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $subscriber->getSubscriberStatus());
// Subscribe and verify
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $subscriber->subscribe('customer@example.com'));
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $subscriber->getSubscriberStatus());
$this->assertStringContainsString('You have been successfully subscribed to our newsletter.', $this->transportBuilder->getSentMessage()->getRawMessage());
$this->assertStringContainsString(
'You have been successfully subscribed to our newsletter.',
$this->getFilteredRawMessage($this->transportBuilder)
);
}

/**
* @param TransportBuilderMock $transportBuilderMock
* @return string
*/
private function getFilteredRawMessage(TransportBuilderMock $transportBuilderMock): string
{
return str_replace('=' . Headers::EOL, '', $transportBuilderMock->getSentMessage()->getRawMessage());
}

/**
Expand All @@ -141,11 +157,17 @@ public function testUnsubscribeSubscribeByCustomerId(): void
// Unsubscribe and verify
$this->assertSame($subscriber, $subscriber->unsubscribeCustomerById(1));
$this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $subscriber->getSubscriberStatus());
$this->assertStringContainsString('You have been unsubscribed from the newsletter.', $this->transportBuilder->getSentMessage()->getRawMessage());
$this->assertStringContainsString(
'You have been unsubscribed from the newsletter.',
$this->getFilteredRawMessage($this->transportBuilder)
);
// Subscribe and verify
$this->assertSame($subscriber, $subscriber->subscribeCustomerById(1));
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $subscriber->getSubscriberStatus());
$this->assertStringContainsString('You have been successfully subscribed to our newsletter.', $this->transportBuilder->getSentMessage()->getRawMessage());
$this->assertStringContainsString(
'You have been successfully subscribed to our newsletter.',
$this->getFilteredRawMessage($this->transportBuilder)
);
}

/**
Expand All @@ -162,7 +184,10 @@ public function testConfirm(): void
$subscriber->subscribe($customerEmail);
$subscriber->loadByEmail($customerEmail);
$subscriber->confirm($subscriber->getSubscriberConfirmCode());
$this->assertStringContainsString('You have been successfully subscribed to our newsletter.', $this->transportBuilder->getSentMessage()->getRawMessage());
$this->assertStringContainsString(
'You have been successfully subscribed to our newsletter.',
$this->getFilteredRawMessage($this->transportBuilder)
);
}

/**
Expand All @@ -184,6 +209,8 @@ public function testSubscribeUnconfirmedCustomerWithSubscription(): void
* @magentoDataFixture Magento/Customer/_files/unconfirmed_customer.php
*
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function testSubscribeUnconfirmedCustomerWithoutSubscription(): void
{
Expand Down
Loading

0 comments on commit df19533

Please sign in to comment.