Skip to content

Commit

Permalink
Merge pull request #6715 from magento-cia/2.4.3-develop-2.4-develop-s…
Browse files Browse the repository at this point in the history
…ync-032221

Sync of 2.4.3-develop with 2.4-develop
  • Loading branch information
admanesachin authored Mar 25, 2021
2 parents 511f0f1 + f90864a commit c1a5532
Show file tree
Hide file tree
Showing 560 changed files with 98,282 additions and 30,921 deletions.
58 changes: 22 additions & 36 deletions app/code/Magento/Authorization/Model/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@
*/
namespace Magento\Authorization\Model;

use Magento\Authorization\Model\ResourceModel\Role\Collection;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Model\AbstractModel;

/**
* Admin Role Model
*
* @api
* @method int getParentId()
* @method \Magento\Authorization\Model\Role setParentId(int $value)
* @method Role setParentId(int $value)
* @method int getTreeLevel()
* @method \Magento\Authorization\Model\Role setTreeLevel(int $value)
* @method Role setTreeLevel(int $value)
* @method int getSortOrder()
* @method \Magento\Authorization\Model\Role setSortOrder(int $value)
* @method Role setSortOrder(int $value)
* @method string getRoleType()
* @method \Magento\Authorization\Model\Role setRoleType(string $value)
* @method Role setRoleType(string $value)
* @method int getUserId()
* @method \Magento\Authorization\Model\Role setUserId(int $value)
* @method Role setUserId(int $value)
* @method string getUserType()
* @method \Magento\Authorization\Model\Role setUserType(string $value)
* @method Role setUserType(string $value)
* @method string getRoleName()
* @method \Magento\Authorization\Model\Role setRoleName(string $value)
* @method Role setRoleName(string $value)
* @api
* @since 100.0.2
*/
class Role extends \Magento\Framework\Model\AbstractModel
class Role extends AbstractModel
{
/**
* @var string
Expand All @@ -38,23 +42,6 @@ class Role extends \Magento\Framework\Model\AbstractModel
*/
protected $_cacheTag = 'user_assigned_role';

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Authorization\Model\ResourceModel\Role $resource
* @param \Magento\Authorization\Model\ResourceModel\Role\Collection $resourceCollection
* @param array $data
*/
public function __construct( //phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Authorization\Model\ResourceModel\Role $resource,
\Magento\Authorization\Model\ResourceModel\Role\Collection $resourceCollection,
array $data = []
) {
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}

/**
* @inheritDoc
*/
Expand All @@ -70,31 +57,30 @@ public function __sleep()
public function __wakeup()
{
parent::__wakeup();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$this->_resource = $objectManager->get(\Magento\Authorization\Model\ResourceModel\Role::class);
$this->_resourceCollection = $objectManager->get(
\Magento\Authorization\Model\ResourceModel\Role\Collection::class
);
$objectManager = ObjectManager::getInstance();
$this->_resource = $objectManager->get(ResourceModel\Role::class);
$this->_resourceCollection = $objectManager->get(Collection::class);
}

/**
* Class constructor
*
* @return void
* @inheritdoc
*/
protected function _construct()
{
$this->_init(\Magento\Authorization\Model\ResourceModel\Role::class);
$this->_init(ResourceModel\Role::class);
}

/**
* Update object into database
* Obsolete method of update
*
* @return $this
* @deprecated Method was never implemented and used.
*/
public function update()
{
$this->getResource()->update($this);
// phpcs:disable Magento2.Functions.DiscouragedFunction
trigger_error('Method was never implemented and used.', E_USER_DEPRECATED);

return $this;
}

Expand Down
33 changes: 33 additions & 0 deletions app/code/Magento/AwsS3/Test/Mftf/Helper/S3FileAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ public function assertFileExists($filePath, $message = ''): void
$this->assertTrue($this->driver->isExists($filePath), $message);
}

/**
* Asserts that a file with the given glob pattern exists in the given path on the remote storage system
*
* @param string $path
* @param string $pattern
* @param string $message
*
* @throws \Magento\Framework\Exception\FileSystemException
*/
public function assertGlobbedFileExists($path, $pattern, $message = ""): void
{
$files = $this->driver->search($pattern, $path);
$this->assertNotEmpty($files, $message);
}

/**
* Assert a file does not exist on the remote storage system
*
Expand Down Expand Up @@ -206,6 +221,24 @@ public function assertFileContainsString($filePath, $text, $message = ""): void
$this->assertStringContainsString($text, $this->driver->fileGetContents($filePath), $message);
}

/**
* Asserts that a file with the given glob pattern at the given path on the remote storage system contains a given string
*
* @param string $path
* @param string $pattern
* @param string $text
* @param int $fileIndex
* @param string $message
* @return void
*
* @throws \Magento\Framework\Exception\FileSystemException
*/
public function assertGlobbedFileContainsString($path, $pattern, $text, $fileIndex = 0, $message = ""): void
{
$files = $this->driver->search($pattern, $path);
$this->assertStringContainsString($text, $this->driver->fileGetContents($files[$fileIndex] ?? ''), $message);
}

/**
* Assert a file on the remote storage system does not contain a given string
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminAwsS3ExportTaxRatesTest" extends="AdminExportTaxRatesTest">
<annotations>
<features value="AwsS3"/>
<stories value="Export Tax"/>
<title value="S3 - Export Tax Rates"/>
<description value="Exports tax rates from the System > Data Transfer > Import/Export Tax Rates page, from
the Tax Rule page, from the Tax Rates grid page as a .csv, and from the Tax Rates grid page as an .xml.
Validates contents in downloaded file for each export area. Note that MFTF cannot simply click export and
have access to the file that is downloaded in the browser due to the test not having access to the server
that is running the test browser. Therefore, this test verifies that the Export button can be successfully
clicked, grabs the request URL from the Export button's form, executes the request on the magento machine
via a curl request, and verifies the contents of the exported file. Uses S3 for the file system."/>
<severity value="MAJOR"/>
<testCaseId value="MC-38621"/>
<group value="importExport"/>
<group value="tax"/>
</annotations>

<before>
<!-- Enable AWS S3 Remote Storage -->
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.enable_options}}" stepKey="enableRemoteStorage" before="revertInitialTaxRateCA"/>
</before>

<after>
<!-- Disable AWS S3 Remote Storage -->
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage" after="logoutFromAdmin"/>
</after>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminAwsS3ImportTaxRatesTest" extends="AdminImportTaxRatesTest">
<annotations>
<features value="AwsS3"/>
<stories value="Import Tax"/>
<title value="S3 - Import and Update Tax Rates"/>
<description value="Imports tax rates from the System > Data Transfer > Import/Export Tax Rates page and
from the Tax Rule page, to create new tax rates and update existing tax rates. Verifies results on the Tax
Rates grid page. Uses S3 for the file system."/>
<severity value="MAJOR"/>
<testCaseId value="MC-38621"/>
<group value="importExport"/>
<group value="tax"/>
</annotations>

<before>
<!-- Enable AWS S3 Remote Storage -->
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.enable_options}}" stepKey="enableRemoteStorage" before="revertInitialTaxRateCA"/>
</before>

<after>
<!-- Disable AWS S3 Remote Storage -->
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage" after="logoutFromAdmin"/>
</after>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AssertAdminDashboardDisplayedWithNoErrorsActionGroup">
<annotations>
<description>Checks if Dashboard is displayed properly</description>
</annotations>

<seeElement selector="{{AdminDashboardSection.dashboardDiagramOrderContentTab}}" stepKey="seeOrderContentTab"/>
<seeElement selector="{{AdminDashboardSection.dashboardDiagramContent}}" stepKey="seeDiagramContent"/>
<click selector="{{AdminDashboardSection.dashboardDiagramAmounts}}" stepKey="clickDashboardAmount"/>
<waitForLoadingMaskToDisappear stepKey="waitForDashboardAmountLoading"/>
<seeElement selector="{{AdminDashboardSection.dashboardDiagramAmountsContentTab}}" stepKey="seeDiagramAmountContent"/>
<seeElement selector="{{AdminDashboardSection.dashboardDiagramTotals}}" stepKey="seeAmountTotals"/>
<dontSeeJsError stepKey="dontSeeJsError"/>
</actionGroup>
</actionGroups>
83 changes: 83 additions & 0 deletions app/code/Magento/Backend/Test/Mftf/Helper/CurlHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backend\Test\Mftf\Helper;

use Magento\FunctionalTestingFramework\Helper\Helper;

/**
* Class for MFTF helpers for curl requests.
*/
class CurlHelpers extends Helper
{
/**
* Assert a that a curl request's response contains an expected string
*
* @param string $url
* @param string $expectedString
* @param string $postBody
* @param string $cookieName
* @return void
*
*/
public function assertCurlResponseContainsString($url, $expectedString, $postBody = null, $cookieName = 'admin'): void
{
$cookie = $this->getCookie($cookieName);
$curlResponse = $this->getCurlResponse($url, $cookie, $postBody);
$this->assertStringContainsString($expectedString, $curlResponse);
}

/**
* Sends a curl request with the provided URL & cookie. Returns the response
*
* @param string $url
* @param string $cookie
* @param string $postBody
* @return string
*
*/
private function getCurlResponse($url, $cookie = null, $postBody = null): string
{
// Start Session
$session = curl_init($url);

// Set Options
if ($postBody) {
$data = json_decode($postBody, true);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($session, CURLOPT_COOKIE, $cookie);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Execute
$response = curl_exec($session);
curl_close($session);

return $response;
}

/**
* Gets the value of the specified cookie and returns the key value pair of the cookie
*
* @param string $cookieName
* @return string
*
*/
private function getCookie($cookieName = 'admin'): string
{
try {
$webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
$cookieValue = $webDriver->grabCookie($cookieName);

return $cookieName . '=' . $cookieValue;
} catch (\Exception $exception) {
$this->fail($exception->getMessage());
return '';
}
}
}
Loading

0 comments on commit c1a5532

Please sign in to comment.