Skip to content

Commit

Permalink
Merge pull request #8255 from magento-gl/mainline-integration-tests
Browse files Browse the repository at this point in the history
Mainline integration tests
  • Loading branch information
2 parents adc4105 + c065e16 commit b0c72f3
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 6 deletions.
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());
}
}
150 changes: 150 additions & 0 deletions dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Store\Model;

use Magento\Customer\Test\Fixture\Customer;
use Magento\Framework\App\Area;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\ObjectManagerInterface;
use Magento\Newsletter\Model\Subscriber;
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
use Magento\Store\Test\Fixture\Store as StoreFixture;
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
use Magento\TestFramework\Fixture\Config as ConfigFixture;
use Magento\TestFramework\Fixture\DataFixture;
use Magento\TestFramework\Fixture\DataFixtureStorage;
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
use Magento\TestFramework\Fixture\DbIsolation;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Mail\Template\TransportBuilderMock;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* phpcs:disable Magento2.Security.Superglobal
*/
class MultiStoreTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @var DataFixtureStorage
*/
private $fixtures;

/**
* @inheridoc
* @throws LocalizedException
*/
protected function setUp(): void
{
parent::setUp();

$this->objectManager = Bootstrap::getObjectManager();
$this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
}

/**
* @return void
* @throws LocalizedException
* @throws \Magento\Framework\Exception\MailException
*/
#[
DbIsolation(false),
ConfigFixture('system/smtp/transport', 'smtp', 'store'),
DataFixture(WebsiteFixture::class, as: 'website2'),
DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'store_group2'),
DataFixture(StoreFixture::class, ['store_group_id' => '$store_group2.id$'], 'store2'),
DataFixture(
Customer::class,
[
'store_id' => '$store2.id$',
'website_id' => '$website2.id$',
'addresses' => [[]]
],
as: 'customer1'
),
DataFixture(WebsiteFixture::class, as: 'website3'),
DataFixture(StoreGroupFixture::class, ['website_id' => '$website3.id$'], 'store_group3'),
DataFixture(StoreFixture::class, ['store_group_id' => '$store_group3.id$'], 'store3'),
DataFixture(
Customer::class,
[
'store_id' => '$store3.id$',
'website_id' => '$website3.id$',
'addresses' => [[]]
],
as: 'customer2'
),
]
public function testStoreSpecificEmailInFromHeader() :void
{
$customerOne = $this->fixtures->get('customer1');
$storeOne = $this->fixtures->get('store2');
$customerOneData = [
'email' => $customerOne->getDataByKey('email'),
'storeId' => $storeOne->getData('store_id'),
'storeEmail' => 'store_one@example.com'
];

$this->subscribeNewsLetterAndAssertFromHeader($customerOneData);

$customerTwo = $this->fixtures->get('customer2');
$storeTwo = $this->fixtures->get('store3');
$customerTwoData = [
'email' => $customerTwo->getDataByKey('email'),
'storeId' => $storeTwo->getData('store_id'),
'storeEmail' => 'store_two@example.com'
];

$this->subscribeNewsLetterAndAssertFromHeader($customerTwoData);
}

/**
* @param $customerData
* @return void
* @throws LocalizedException
* @throws \Magento\Framework\Exception\MailException
*/
private function subscribeNewsLetterAndAssertFromHeader(
$customerData
) :void {
/** @var Subscriber $subscriber */
$subscriber = $this->objectManager->create(Subscriber::class);
$subscriber->subscribe($customerData['email']);

/** @var TransportBuilderMock $transportBuilderMock */
$transportBuilderMock = $this->objectManager->get(TransportBuilderMock::class);
$transportBuilderMock->setTemplateIdentifier(
'customer_password_reset_password_template'
)->setTemplateVars([
'subscriber_data' => [
'confirmation_link' => $subscriber->getConfirmationLink(),
],
])->setTemplateOptions([
'area' => Area::AREA_FRONTEND,
'store' => (int) $customerData['storeId']
])
->setFromByScope(
[
'email' => $customerData['storeEmail'],
'name' => 'Store Email Name'
],
(int) $customerData['storeId']
)
->addTo($customerData['email'])
->getTransport();

$headers = $transportBuilderMock->getSentMessage()->getHeaders();

$this->assertNotNull($transportBuilderMock->getSentMessage());
$this->assertStringContainsString($customerData['storeEmail'], $headers['From']);
}
}
Loading

0 comments on commit b0c72f3

Please sign in to comment.