Skip to content

Commit

Permalink
Merge pull request #8299 from magento-l3/PR-L3-2023-05-11
Browse files Browse the repository at this point in the history
PR-L3-2023-05-11
  • Loading branch information
dhorytskyi authored Jul 4, 2023
2 parents 2abc466 + 94133ec commit 09eaf9f
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Backup/Model/ResourceModel/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function rollBackTransaction()
*/
public function runCommand($command)
{
$this->connection->query($command);
$this->connection->multiQuery($command);
return $this;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogSearch/etc/search_request.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<queries>
<query xsi:type="boolQuery" name="advanced_search_container" boost="1">
<queryReference clause="should" ref="sku_query"/>
<queryReference clause="should" ref="price_query"/>
<queryReference clause="must" ref="price_query"/>
<queryReference clause="should" ref="category_query"/>
<queryReference clause="must" ref="visibility_query"/>
</query>
Expand Down
35 changes: 20 additions & 15 deletions app/code/Magento/GoogleAnalytics/Block/Ga.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function getPageName()
* @link https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#set
* @link https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#gaObjectMethods
* @deprecated 100.2.0 please use getPageTrackingData method
* @see getPageTrackingData method
*/
public function getPageTrackingCode($accountId)
{
Expand All @@ -103,6 +104,7 @@ public function getPageTrackingCode($accountId)
*
* @return string|void
* @deprecated 100.2.0 please use getOrdersTrackingData method
* @see getOrdersTrackingData method
*/
public function getOrdersTrackingCode()
{
Expand All @@ -120,33 +122,35 @@ public function getOrdersTrackingCode()
foreach ($collection as $order) {
$result[] = "ga('set', 'currencyCode', '" . $order->getOrderCurrencyCode() . "');";
foreach ($order->getAllVisibleItems() as $item) {
$quantity = $item->getQtyOrdered() * 1;
$format = fmod($quantity, 1) !== 0.00 ? '%.2f' : '%d';
$result[] = sprintf(
"ga('ec:addProduct', {
'id': '%s',
'name': '%s',
'price': '%s',
'quantity': %s
'price': %.2f,
'quantity': $format
});",
$this->escapeJsQuote($item->getSku()),
$this->escapeJsQuote($item->getName()),
$item->getPrice(),
$item->getQtyOrdered()
(float)$item->getPrice(),
$quantity
);
}

$result[] = sprintf(
"ga('ec:setAction', 'purchase', {
'id': '%s',
'affiliation': '%s',
'revenue': '%s',
'tax': '%s',
'shipping': '%s'
'revenue': %.2f,
'tax': %.2f,
'shipping': %.2f
});",
$order->getIncrementId(),
$this->escapeJsQuote($this->_storeManager->getStore()->getFrontendName()),
$order->getGrandTotal(),
$order->getTaxAmount(),
$order->getShippingAmount()
(float)$order->getGrandTotal(),
(float)$order->getTaxAmount(),
(float)$order->getShippingAmount(),
);

$result[] = "ga('send', 'pageview');";
Expand Down Expand Up @@ -232,19 +236,20 @@ public function getOrdersTrackingData()

foreach ($collection as $order) {
foreach ($order->getAllVisibleItems() as $item) {
$quantity = $item->getQtyOrdered() * 1;
$result['products'][] = [
'id' => $this->escapeJsQuote($item->getSku()),
'name' => $this->escapeJsQuote($item->getName()),
'price' => $item->getPrice(),
'quantity' => $item->getQtyOrdered(),
'price' => (float)$item->getPrice(),
'quantity' => $quantity,
];
}
$result['orders'][] = [
'id' => $order->getIncrementId(),
'affiliation' => $this->escapeJsQuote($this->_storeManager->getStore()->getFrontendName()),
'revenue' => $order->getGrandTotal(),
'tax' => $order->getTaxAmount(),
'shipping' => $order->getShippingAmount(),
'revenue' => (float)$order->getGrandTotal(),
'tax' => (float)$order->getTaxAmount(),
'shipping' => (float)$order->getShippingAmount(),
];
$result['currency'] = $order->getOrderCurrencyCode();
}
Expand Down
40 changes: 26 additions & 14 deletions app/code/Magento/GoogleAnalytics/Test/Unit/Block/GaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,21 @@ public function testOrderTrackingCode()
ga('ec:addProduct', {
'id': 'sku0',
'name': 'testName0',
'price': '0.00',
'price': 0.00,
'quantity': 1
});
ga('ec:addProduct', {
'id': 'sku1',
'name': 'testName1',
'price': 1.00,
'quantity': 1.11
});
ga('ec:setAction', 'purchase', {
'id': '100',
'affiliation': 'test',
'revenue': '10',
'tax': '2',
'shipping': '1'
'revenue': 10.00,
'tax': 2.00,
'shipping': 2.00
});
ga('send', 'pageview');";

Expand Down Expand Up @@ -163,9 +169,9 @@ public function testOrderTrackingData()
[
'id' => 100,
'affiliation' => 'test',
'revenue' => 10,
'tax' => 2,
'shipping' => 1
'revenue' => 10.00,
'tax' => 2.00,
'shipping' => 2.0
]
],
'products' => [
Expand All @@ -174,6 +180,12 @@ public function testOrderTrackingData()
'name' => 'testName0',
'price' => 0.00,
'quantity' => 1
],
[
'id' => 'sku1',
'name' => 'testName1',
'price' => 1.00,
'quantity' => 1.11
]
],
'currency' => 'USD'
Expand Down Expand Up @@ -204,7 +216,7 @@ public function testGetPageTrackingData()
* @param int $orderItemCount
* @return Order|MockObject
*/
protected function createOrderMock($orderItemCount = 1)
protected function createOrderMock($orderItemCount = 2)
{
$orderItems = [];
for ($i = 0; $i < $orderItemCount; $i++) {
Expand All @@ -213,8 +225,8 @@ protected function createOrderMock($orderItemCount = 1)
->getMockForAbstractClass();
$orderItemMock->expects($this->once())->method('getSku')->willReturn('sku' . $i);
$orderItemMock->expects($this->once())->method('getName')->willReturn('testName' . $i);
$orderItemMock->expects($this->once())->method('getPrice')->willReturn($i . '.00');
$orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn($i + 1);
$orderItemMock->expects($this->once())->method('getPrice')->willReturn((float)($i . '.0000'));
$orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn($i == 1 ? 1.11 : $i + 1);
$orderItems[] = $orderItemMock;
}

Expand All @@ -223,9 +235,9 @@ protected function createOrderMock($orderItemCount = 1)
->getMock();
$orderMock->expects($this->once())->method('getIncrementId')->willReturn(100);
$orderMock->expects($this->once())->method('getAllVisibleItems')->willReturn($orderItems);
$orderMock->expects($this->once())->method('getGrandTotal')->willReturn(10);
$orderMock->expects($this->once())->method('getTaxAmount')->willReturn(2);
$orderMock->expects($this->once())->method('getShippingAmount')->willReturn($orderItemCount);
$orderMock->expects($this->once())->method('getGrandTotal')->willReturn(10.00);
$orderMock->expects($this->once())->method('getTaxAmount')->willReturn(2.00);
$orderMock->expects($this->once())->method('getShippingAmount')->willReturn(round((float)$orderItemCount, 2));
$orderMock->expects($this->once())->method('getOrderCurrencyCode')->willReturn('USD');
return $orderMock;
}
Expand All @@ -241,7 +253,7 @@ protected function createCollectionMock()

$collectionMock->expects($this->any())
->method('getIterator')
->willReturn(new \ArrayIterator([$this->createOrderMock(1)]));
->willReturn(new \ArrayIterator([$this->createOrderMock(2)]));
return $collectionMock;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<search>
<patterns>
<pattern name="media_gallery_renditions">/{{media url=(?:"|&amp;quot;)(?:.renditions)?(.*?)(?:"|&amp;quot;)}}/</pattern>
<pattern name="media_gallery">/{{media url="?(?:.*?\.renditions\/)(.*?)"?}}/</pattern>
<pattern name="media_gallery">/{{media url="?(?:.*?\.renditions\/)?(.*?)"?}}/</pattern>
<pattern name="wysiwyg">/src=".*\/media\/(?:.renditions\/)*(.*?)"/</pattern>
<pattern name="catalog_image">/^\/?media\/(?:.renditions\/)?(.*)/</pattern>
<pattern name="catalog_image_with_pub">/^\/pub\/?media\/(?:.renditions\/)?(.*)/</pattern>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,42 @@ public function testExecuteWithArrayInParam(array $searchParams): void
);
}

/**
* Advanced search test by difference product attributes.
*
* @magentoAppArea frontend
* @magentoDataFixture Magento/CatalogSearch/_files/product_for_search.php
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
* @dataProvider testDataForAttributesCombination
*
* @param array $searchParams
* @param bool $isProductShown
* @return void
*/
public function testExecuteForAttributesCombination(array $searchParams, bool $isProductShown): void
{
$this->getRequest()->setQuery(
$this->_objectManager->create(
Parameters::class,
[
'values' => $searchParams
]
)
);
$this->dispatch('catalogsearch/advanced/result');
$responseBody = $this->getResponse()->getBody();

if ($isProductShown) {
$this->assertStringContainsString('Simple product name', $responseBody);
} else {
$this->assertStringContainsString(
'We can&#039;t find any items matching these search criteria.',
$responseBody
);
}
$this->assertStringNotContainsString('Not visible simple product', $responseBody);
}

/**
* Data provider with array in params values
*
Expand Down Expand Up @@ -339,4 +375,71 @@ private function getAttributeOptionValueByOptionLabel(string $attributeCode, str

return $attribute->getSource()->getOptionId($optionLabel);
}

/**
* Data provider with strings for quick search.
*
* @return array
*/
public function testDataForAttributesCombination(): array
{
return [
'search_product_by_name_and_price' => [
[
'name' => 'Simple product name',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => 99,
'to' => 101,
],
'test_searchable_attribute' => '',
],
true
],
'search_product_by_name_and_price_not_shown' => [
[
'name' => 'Simple product name',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => 101,
'to' => 102,
],
'test_searchable_attribute' => '',
],
false
],
'search_product_by_sku' => [
[
'name' => '',
'sku' => 'simple_for_search',
'description' => '',
'short_description' => '',
'price' => [
'from' => 99,
'to' => 101,
],
'test_searchable_attribute' => '',
],
true
],
'search_product_by_sku_not_shown' => [
[
'name' => '',
'sku' => 'simple_for_search',
'description' => '',
'short_description' => '',
'price' => [
'from' => 990,
'to' => 1010,
],
'test_searchable_attribute' => '',
],
false
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
namespace Magento\Framework\Backup;

use Magento\Backup\Helper\Data;
use Magento\Backup\Model\ResourceModel\Db;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Module\Setup;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
use Magento\Framework\Backup\BackupInterface;

/**
* Provide tests for \Magento\Framework\Backup\Db.
Expand All @@ -32,16 +33,17 @@ public static function setUpBeforeClass(): void
}

/**
* Test db backup includes triggers.
* Test db backup and rollback including triggers.
*
* @magentoConfigFixture default/system/backup/functionality_enabled 1
* @magentoDataFixture Magento/Framework/Backup/_files/trigger.php
* @magentoDbIsolation disabled
*/
public function testBackupIncludesCustomTriggers()
public function testBackupAndRollbackIncludesCustomTriggers()
{
$helper = Bootstrap::getObjectManager()->get(Data::class);
$time = time();
/** BackupInterface $backupManager */
$backupManager = Bootstrap::getObjectManager()->get(Factory::class)->create(
Factory::TYPE_DB
)->setBackupExtension(
Expand All @@ -60,6 +62,12 @@ public function testBackupIncludesCustomTriggers()
'/CREATE TRIGGER `?test_custom_trigger`? AFTER INSERT ON `?'. $tableName . '`? FOR EACH ROW/',
$content
);

// Test rollback
$backupResourceModel = Bootstrap::getObjectManager()->get(Db::class);
$backupManager->setResourceModel($backupResourceModel);
$backupManager->rollback();

//Clean up.
$write->delete('/backups/' . $time . '_db_testbackup.sql');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ public function contentProvider()
2020
]
],
'Relevant paths in content without quotes' => [
'content {{media url=testDirectory/path.jpg}} content',
[
2020
]
],
'Relevant wysiwyg paths in content' => [
'content <img src="https://domain.com/media/testDirectory/path.jpg"}} content',
[
Expand Down
Loading

0 comments on commit 09eaf9f

Please sign in to comment.