Skip to content

Commit

Permalink
Merge branch 'magento-commerce:2.4-develop' into eav-graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
eliseacornejo authored Jun 26, 2023
2 parents 3ae9e5b + 35e8e43 commit 5b556f6
Show file tree
Hide file tree
Showing 11 changed files with 509 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,62 @@
*/
namespace Magento\Catalog\Model\Product\Attribute\Source;

use Magento\Directory\Model\CountryFactory;
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
use Magento\Framework\App\Cache\Type\Config;
use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Store\Model\StoreManagerInterface;

class Countryofmanufacture extends AbstractSource implements OptionSourceInterface
{
/**
* @var \Magento\Framework\App\Cache\Type\Config
* @var Config
*/
protected $_configCacheType;

/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
* @var StoreManagerInterface
*/
protected $_storeManager;

/**
* Country factory
*
* @var \Magento\Directory\Model\CountryFactory
* @var CountryFactory
*/
protected $_countryFactory;

/**
* @var \Magento\Framework\Serialize\SerializerInterface
* @var SerializerInterface
*/
private $serializer;

/**
* @var ResolverInterface
*/
private $localeResolver;

/**
* Construct
*
* @param \Magento\Directory\Model\CountryFactory $countryFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\Cache\Type\Config $configCacheType
* @param CountryFactory $countryFactory
* @param StoreManagerInterface $storeManager
* @param Config $configCacheType
* @param ResolverInterface $localeResolver
* @param SerializerInterface $serializer
*/
public function __construct(
\Magento\Directory\Model\CountryFactory $countryFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\Cache\Type\Config $configCacheType
CountryFactory $countryFactory,
StoreManagerInterface $storeManager,
Config $configCacheType,
ResolverInterface $localeResolver,
SerializerInterface $serializer
) {
$this->_countryFactory = $countryFactory;
$this->_storeManager = $storeManager;
$this->_configCacheType = $configCacheType;
$this->localeResolver = $localeResolver;
$this->serializer = $serializer;
}

/**
Expand All @@ -64,32 +76,20 @@ public function __construct(
*/
public function getAllOptions()
{
$cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $this->_storeManager->getStore()->getCode();
$storeCode = $this->_storeManager->getStore()->getCode();
$locale = $this->localeResolver->getLocale();

$cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $storeCode . '_LOCALE_' . $locale;
if ($cache = $this->_configCacheType->load($cacheKey)) {
$options = $this->getSerializer()->unserialize($cache);
$options = $this->serializer->unserialize($cache);
} else {
/** @var \Magento\Directory\Model\Country $country */
$country = $this->_countryFactory->create();
/** @var \Magento\Directory\Model\ResourceModel\Country\Collection $collection */
$collection = $country->getResourceCollection();
$options = $collection->load()->toOptionArray();
$this->_configCacheType->save($this->getSerializer()->serialize($options), $cacheKey);
$this->_configCacheType->save($this->serializer->serialize($options), $cacheKey);
}
return $options;
}

/**
* Get serializer
*
* @return \Magento\Framework\Serialize\SerializerInterface
* @deprecated 102.0.0
*/
private function getSerializer()
{
if ($this->serializer === null) {
$this->serializer = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\SerializerInterface::class);
}
return $this->serializer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Catalog\Model\Product\Attribute\Source\Countryofmanufacture;
use Magento\Framework\App\Cache\Type\Config;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Store\Model\Store;
Expand Down Expand Up @@ -46,17 +47,24 @@ class CountryofmanufactureTest extends TestCase
*/
private $serializerMock;

/**
* @var ResolverInterface
*/
private $localeResolverMock;

protected function setUp(): void
{
$this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class);
$this->storeMock = $this->createMock(Store::class);
$this->cacheConfig = $this->createMock(Config::class);
$this->localeResolverMock = $this->getMockForAbstractClass(ResolverInterface::class);
$this->objectManagerHelper = new ObjectManager($this);
$this->countryOfManufacture = $this->objectManagerHelper->getObject(
Countryofmanufacture::class,
[
'storeManager' => $this->storeManagerMock,
'configCacheType' => $this->cacheConfig,
'localeResolver' => $this->localeResolverMock,
]
);

Expand All @@ -80,9 +88,10 @@ public function testGetAllOptions($cachedDataSrl, $cachedDataUnsrl)
{
$this->storeMock->expects($this->once())->method('getCode')->willReturn('store_code');
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
$this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn('en_US');
$this->cacheConfig->expects($this->once())
->method('load')
->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code'))
->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code_LOCALE_en_US'))
->willReturn($cachedDataSrl);
$this->serializerMock->expects($this->once())
->method('unserialize')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,8 @@ define([
if (productId && !images.file) {
images = product.images;
}
productDataFromGrid = _.pick(
productDataFromGrid,
'sku',
'name',
'weight',
'status',
'price',
'qty'
);
productDataFromGrid = this.prepareProductDataFromGrid(productDataFromGrid);

if (productDataFromGrid.hasOwnProperty('qty')) {
productDataFromGrid[this.quantityFieldName] = productDataFromGrid.qty;
}
delete productDataFromGrid.qty;
product = _.pick(
product || {},
'sku',
Expand Down Expand Up @@ -288,6 +276,32 @@ define([
* Back.
*/
back: function () {
},

/**
* Prepare product data from grid to have all the current fields values
*
* @param {Object} productDataFromGrid
* @return {Object}
*/
prepareProductDataFromGrid: function (productDataFromGrid) {
productDataFromGrid = _.pick(
productDataFromGrid,
'sku',
'name',
'weight',
'status',
'price',
'qty'
);

if (productDataFromGrid.hasOwnProperty('qty')) {
productDataFromGrid[this.quantityFieldName] = productDataFromGrid.qty;
}

delete productDataFromGrid.qty;

return productDataFromGrid;
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<element name="password" type="input" selector="#pass"/>
<element name="signIn" type="button" selector="(//button[@id='send2'][contains(@class, 'login')])[1]" timeout="30"/>
<element name="forgotYourPassword" type="button" selector="//a[@class='action']//span[contains(text(),'Forgot Your Password?')]" timeout="30"/>
<element name="createAnAccount" type="button" selector="//div[contains(@class,'actions-toolbar')]//a[contains(.,'Create an Account')]" timeout="30"/>
<element name="createAnAccount" type="button" selector="(//div[contains(@class,'actions-toolbar')]//a[contains(.,'Create an Account')])[last()]" timeout="30"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<h2 class="page-sub-title"><?= $block->escapeHtml(__('Partner search')) ?></h2>
<p>
<?= $block->escapeHtml(__(
'Magento has a thriving ecosystem of technology partners to help merchants and brands deliver ' .
'the best possible customer experiences. They are recognized as experts in eCommerce, ' .
'Magento has a thriving ecosystem of technology partners to help merchants and brands deliver '
. 'the best possible customer experiences. They are recognized as experts in eCommerce, ' .
'search, email marketing, payments, tax, fraud, optimization and analytics, fulfillment, ' .
'and more. Visit the Magento Partner Directory to see all of our trusted partners.'
)); ?>
Expand Down Expand Up @@ -61,7 +61,7 @@
)); ?>
</p>
<a class="action-secondary" target="_blank"
href="https://marketplace.magento.com/">
href="https://commercemarketplace.adobe.com/">
<?= $block->escapeHtml(__('Visit Magento Marketplaces')) ?>
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</actionGroup>
<actionGroup ref="StorefrontOpenCartFromMinicartActionGroup" stepKey="openCart"/>
<click selector="{{MultishippingSection.checkoutWithMultipleAddresses}}" stepKey="proceedMultishipping"/>
<waitForElementClickable selector="{{StorefrontCustomerSignInPopupFormSection.createAnAccount}}" stepKey="waitForCreateAccount"/>
<click selector="{{StorefrontCustomerSignInPopupFormSection.createAnAccount}}" stepKey="clickCreateAccount"/>
<seeElement selector="{{CheckoutShippingSection.region}}" stepKey="seeRegionSelector"/>
</test>
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/UrlRewrite/Test/Mftf/Data/UrlRewriteData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</entity>
<entity name="customPermanentUrlRewrite" type="urlRewrite">
<data key="request_path" unique="prefix">wishlist</data>
<data key="target_path">https://marketplace.magento.com/</data>
<data key="target_path">https://commercemarketplace.adobe.com/</data>
<data key="redirect_type">301</data>
<data key="redirect_type_label">Permanent (301)</data>
<data key="store_id">1</data>
Expand All @@ -37,7 +37,7 @@
</entity>
<entity name="customTemporaryUrlRewrite" type="urlRewrite">
<data key="request_path" unique="prefix">wishlist</data>
<data key="target_path">https://marketplace.magento.com/</data>
<data key="target_path">https://commercemarketplace.adobe.com/</data>
<data key="redirect_type">302</data>
<data key="redirect_type_label">Temporary (302)</data>
<data key="store_id">1</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
namespace Magento\Newsletter\Model\Plugin;

use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Mail\Template\TransportBuilderMock;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* phpcs:disable Magento2.Security.Superglobal
* @magentoAppIsolation enabled
*/
class PluginTest extends \PHPUnit\Framework\TestCase
Expand All @@ -24,6 +27,11 @@ class PluginTest extends \PHPUnit\Framework\TestCase
*/
protected $customerRepository;

/**
* @var TransportBuilderMock
*/
protected $transportBuilderMock;

protected function setUp(): void
{
$this->accountManagement = Bootstrap::getObjectManager()->get(
Expand All @@ -32,6 +40,9 @@ protected function setUp(): void
$this->customerRepository = Bootstrap::getObjectManager()->get(
\Magento\Customer\Api\CustomerRepositoryInterface::class
);
$this->transportBuilderMock = Bootstrap::getObjectManager()->get(
TransportBuilderMock::class
);
}

protected function tearDown(): void
Expand Down Expand Up @@ -223,4 +234,67 @@ public function testCustomerWithTwoNewsLetterSubscriptions()
$extensionAttributes = $customer->getExtensionAttributes();
$this->assertTrue($extensionAttributes->getIsSubscribed());
}

/**
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
* @magentoConfigFixture current_store newsletter/general/active 1
* @magentoDataFixture Magento/Customer/_files/customer_welcome_email_template.php
*
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function testCreateAccountWithNewsLetterSubscription(): void
{
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
$customerFactory = $objectManager->get(\Magento\Customer\Api\Data\CustomerInterfaceFactory::class);
$customerDataObject = $customerFactory->create()
->setFirstname('John')
->setLastname('Doe')
->setEmail('customer@example.com');
$extensionAttributes = $customerDataObject->getExtensionAttributes();
$extensionAttributes->setIsSubscribed(true);
$customerDataObject->setExtensionAttributes($extensionAttributes);
$this->accountManagement->createAccount($customerDataObject, '123123qW');
$message = $this->transportBuilderMock->getSentMessage();

$this->assertNotNull($message);
$this->assertEquals('Welcome to Main Website Store', $message->getSubject());
$this->assertStringContainsString(
'John',
$message->getBody()->getParts()[0]->getRawContent()
);
$this->assertStringContainsString(
'customer@example.com',
$message->getBody()->getParts()[0]->getRawContent()
);

/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
$subscriber = $objectManager->create(\Magento\Newsletter\Model\Subscriber::class);
$subscriber->loadByEmail('customer@example.com');
$this->assertTrue($subscriber->isSubscribed());

$this->transportBuilderMock->setTemplateIdentifier(
'newsletter_subscription_confirm_email_template'
)->setTemplateVars([
'subscriber_data' => [
'confirmation_link' => $subscriber->getConfirmationLink(),
],
])->setTemplateOptions([
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
])
->addTo('customer@example.com')
->getTransport();

$message = $this->transportBuilderMock->getSentMessage();

$this->assertNotNull($message);
$this->assertStringContainsString(
$subscriber->getConfirmationLink(),
$message->getBody()->getParts()[0]->getRawContent()
);
$this->assertEquals('Newsletter subscription confirmation', $message->getSubject());
}
}
Loading

0 comments on commit 5b556f6

Please sign in to comment.