Skip to content

Commit 70848ea

Browse files
committed
ACP2E-215: [Magento Cloud] Branch Merge Failure
1 parent bab395a commit 70848ea

File tree

2 files changed

+111
-4
lines changed
  • app/code/Magento/Cron/Model/Config/Backend/Product
  • dev/tests/integration/testsuite/Magento/Cron/Model/Config/Backend/Product

2 files changed

+111
-4
lines changed

app/code/Magento/Cron/Model/Config/Backend/Product/Alert.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
class Alert extends \Magento\Framework\App\Config\Value
1818
{
1919
/**
20-
* Cron string path
20+
* Cron expression config path
2121
*/
2222
const CRON_STRING_PATH = 'crontab/default/jobs/catalog_product_alert/schedule/cron_expr';
2323

2424
/**
25-
* Cron model path
25+
* Cron model config path
2626
*/
2727
const CRON_MODEL_PATH = 'crontab/default/jobs/catalog_product_alert/run/model';
2828

@@ -71,8 +71,16 @@ public function __construct(
7171
*/
7272
public function afterSave()
7373
{
74-
$time = $this->getData('groups/productalert_cron/fields/time/value');
75-
$frequency = $this->getData('groups/productalert_cron/fields/frequency/value');
74+
$time = $this->getData('groups/productalert_cron/fields/time/value') ?:
75+
explode(
76+
',',
77+
$this->_config->getValue(
78+
'catalog/productalert_cron/time',
79+
$this->getScope(),
80+
$this->getScopeId()
81+
) ?: '0,0,0'
82+
);
83+
$frequency = $this->getValue();
7684

7785
$cronExprArray = [
7886
(int)$time[1], //Minute
@@ -102,6 +110,7 @@ public function afterSave()
102110
self::CRON_MODEL_PATH
103111
)->save();
104112
} catch (\Exception $e) {
113+
// phpcs:ignore Magento2.Exceptions.DirectThrow
105114
throw new \Exception(__('We can\'t save the cron expression.'));
106115
}
107116

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Cron\Model\Config\Backend\Product;
9+
10+
use Magento\Config\Model\Config as ConfigModel;
11+
use Magento\Config\Model\PreparedValueFactory;
12+
use Magento\Cron\Model\Config\Source\Frequency;
13+
use Magento\Framework\App\Config\ValueFactory;
14+
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* @magentoAppArea adminhtml
20+
*/
21+
class AlertTest extends TestCase
22+
{
23+
/**
24+
* @var ObjectManagerInterface
25+
*/
26+
private $objectManager;
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
protected function setUp(): void
32+
{
33+
$this->objectManager = Bootstrap::getObjectManager();
34+
}
35+
36+
/**
37+
* @dataProvider frequencyDataProvider
38+
* @param string $frequency
39+
* @param string $expectedCronExpr
40+
*/
41+
public function testDirectSave(string $frequency, string $expectedCronExpr): void
42+
{
43+
$preparedValueFactory = $this->objectManager->get(PreparedValueFactory::class);
44+
/** @var Alert $sitemapValue */
45+
$alertValue = $preparedValueFactory->create('catalog/productalert_cron/frequency', $frequency, 'default', 0);
46+
$alertValue->save();
47+
48+
self::assertEquals($expectedCronExpr, $this->getCronExpression());
49+
}
50+
51+
/**
52+
* @dataProvider frequencyDataProvider
53+
* @param string $frequency
54+
* @param string $expectedCronExpr
55+
*/
56+
public function testSaveFromAdmin(string $frequency, string $expectedCronExpr): void
57+
{
58+
$config = $this->objectManager->create(ConfigModel::class);
59+
$config->setSection('catalog');
60+
$config->setGroups(
61+
[
62+
'productalert_cron' => [
63+
'fields' => [
64+
'time' => ['value' => ['00', '00', '00']],
65+
'frequency' => ['value' => $frequency],
66+
],
67+
],
68+
]
69+
);
70+
$config->save();
71+
72+
self::assertEquals($expectedCronExpr, $this->getCronExpression());
73+
}
74+
75+
/**
76+
* @return array
77+
*/
78+
public function frequencyDataProvider(): array
79+
{
80+
return [
81+
'daily' => [Frequency::CRON_DAILY, '0 0 * * *'],
82+
'weekly' => [Frequency::CRON_WEEKLY, '0 0 * * 1'],
83+
'monthly' => [Frequency::CRON_MONTHLY, '0 0 1 * *'],
84+
];
85+
}
86+
87+
/**
88+
* @return string
89+
*/
90+
private function getCronExpression(): string
91+
{
92+
$valueFactory = $this->objectManager->get(ValueFactory::class);
93+
$cronExprValue = $valueFactory->create()
94+
->load(Alert::CRON_STRING_PATH, 'path');
95+
96+
return $cronExprValue->getValue();
97+
}
98+
}

0 commit comments

Comments
 (0)