Skip to content

Commit ac5d0f3

Browse files
committed
Merge branch 'b-7.1.x' into b-8.0.x
2 parents a005b6a + a1e439f commit ac5d0f3

File tree

4 files changed

+95
-60
lines changed

4 files changed

+95
-60
lines changed

source/Application/Controller/Admin/ArticleList.php

+3-21
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@ private function setIsActiveFieldForProductsInList(ListModel $productList): void
301301
$useTimeCheck = Registry::getConfig()->getConfigParam('blUseTimeCheck');
302302
$now = $this->getCurrentTimeAsDatabaseTimestamp();
303303
foreach ($productList as $key => $product) {
304-
$product->showActiveCheckInAdminPanel = $this->isProductAlwaysActive($product);
304+
$product->showActiveCheckInAdminPanel = $product->isProductAlwaysActive();
305305

306306
if ($useTimeCheck) {
307-
$product->hasActiveTimeRange = $this->hasProductActiveTimeRange($product);
308-
$product->isActiveNow = $this->isProductActiveNow($product, $now);
307+
$product->hasActiveTimeRange = $product->hasProductValidTimeRange();
308+
$product->isActiveNow = $product->isProductActive($now);
309309
}
310310
$productList[$key] = $product;
311311
}
@@ -328,22 +328,4 @@ private function convertValueToDatabaseTimestamp(Field $field): void
328328
Registry::getUtilsDate()->convertDBDate($field);
329329
}
330330
}
331-
332-
private function isProductAlwaysActive(Article $product): bool
333-
{
334-
return !empty($product->oxarticles__oxactive->value);
335-
}
336-
337-
private function isProductActiveNow(Article $product, string $now): bool
338-
{
339-
return $this->hasProductActiveTimeRange($product)
340-
&& $product->oxarticles__oxactivefrom->value <= $now
341-
&& $product->oxarticles__oxactiveto->value >= $now;
342-
}
343-
344-
private function hasProductActiveTimeRange(Article $product): bool
345-
{
346-
return !Registry::getUtilsDate()->isEmptyDate($product->oxarticles__oxactivefrom->value)
347-
&& !Registry::getUtilsDate()->isEmptyDate($product->oxarticles__oxactiveto->value);
348-
}
349331
}

source/Application/Model/Article.php

+18
Original file line numberDiff line numberDiff line change
@@ -4031,6 +4031,24 @@ public function getArticleVat()
40314031
return $this->_dArticleVat;
40324032
}
40334033

4034+
public function hasProductValidTimeRange(): bool
4035+
{
4036+
return !Registry::getUtilsDate()->isEmptyDate($this->oxarticles__oxactivefrom->value)
4037+
|| !Registry::getUtilsDate()->isEmptyDate($this->oxarticles__oxactiveto->value);
4038+
}
4039+
4040+
public function isProductAlwaysActive(): bool
4041+
{
4042+
return !empty($this->oxarticles__oxactive->value);
4043+
}
4044+
4045+
public function isProductActive(string $date): bool
4046+
{
4047+
return $this->hasProductValidTimeRange()
4048+
&& $this->oxarticles__oxactivefrom->value <= $date
4049+
&& $this->oxarticles__oxactiveto->value >= $date;
4050+
}
4051+
40344052
/**
40354053
* Applies VAT to article
40364054
*

tests/Codeception/Acceptance/Admin/ProductListStatusTestCest.php

+5-33
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,27 @@
1010
namespace Acceptance\Admin;
1111

1212
use Codeception\Attribute\Group;
13-
use Codeception\Util\Fixtures;
14-
use DateTime;
1513
use OxidEsales\EshopCommunity\Tests\Codeception\Support\AcceptanceTester;
1614

17-
#[Group('admin')]
15+
#[Group('admin', 'product')]
1816
final class ProductListStatusTestCest
1917
{
20-
private string $activeProductID = '1000';
2118
private string $temporaryActiveProductID = '1003';
2219
private string $temporaryInactiveProductID = '1004';
23-
private string $inactiveProductID = '1005';
2420

2521
public function _before(AcceptanceTester $I): void
2622
{
2723
$I->updateConfigInDatabase('blUseTimeCheck', true, 'bool');
2824
}
2925

30-
public function _after(AcceptanceTester $I): void
26+
public function checkProductsStatuses(AcceptanceTester $I): void
3127
{
32-
$I->updateConfigInDatabase('blUseTimeCheck', false, 'bool');
33-
}
28+
$I->wantToTest('Product statuses by time range');
3429

35-
public function checkProductsStatus(AcceptanceTester $I): void
36-
{
3730
$admin = $I->loginAdmin();
3831
$productList = $admin->openProducts();
3932

40-
$I->wantToTest('Product is active in list');
41-
42-
$productList->filterByProductNumber($this->activeProductID);
43-
44-
$I->assertStringContainsString(
45-
'active',
46-
$I->grabAttributeFrom($productList->productStatusClass, 'class')
47-
);
48-
49-
50-
$I->wantToTest('Product not active in the list');
51-
52-
$productList->filterByProductNumber($this->inactiveProductID);
53-
54-
$I->assertStringNotContainsString(
55-
'active',
56-
$I->grabAttributeFrom($productList->productStatusClass, 'class')
57-
);
58-
59-
60-
$I->wantToTest('Product temporary active in the list');
33+
$I->expect('the given product is active in the list');
6134

6235
$productList->filterByProductNumber($this->temporaryActiveProductID);
6336

@@ -66,8 +39,7 @@ public function checkProductsStatus(AcceptanceTester $I): void
6639
$I->grabAttributeFrom($productList->productStatusClass, 'class')
6740
);
6841

69-
70-
$I->wantToTest('Product temporary not active in the list');
42+
$I->expect('the given product is not active in the list');
7143

7244
$productList->filterByProductNumber($this->temporaryInactiveProductID);
7345

tests/Integration/Application/Model/ArticleTest.php

+69-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OxidEsales\Eshop\Core\Field;
1515
use OxidEsales\Eshop\Core\Registry;
1616
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718

1819
final class ArticleTest extends IntegrationTestCase
1920
{
@@ -58,9 +59,7 @@ public function testIsVisibleWithValidTimeRestrictionsAndDisabledConfig(): void
5859
$this->assertFalse($product->isVisible());
5960
}
6061

61-
/**
62-
* @dataProvider validTimeRestrictionsDataProvider
63-
*/
62+
#[DataProvider('validTimeRestrictionsDataProvider')]
6463
public function testIsVisibleWithValidTimeRestrictions(string $activeFrom, string $activeTo): void
6564
{
6665
Registry::getConfig()->setConfigParam('blUseTimeCheck', true);
@@ -86,9 +85,7 @@ public static function validTimeRestrictionsDataProvider(): array
8685
];
8786
}
8887

89-
/**
90-
* @dataProvider invalidTimeRestrictionsDataProvider
91-
*/
88+
#[DataProvider('invalidTimeRestrictionsDataProvider')]
9289
public function testIsVisibleWithInvalidTimeRestrictions(string $activeFrom, string $activeTo): void
9390
{
9491
Registry::getConfig()->setConfigParam('blUseTimeCheck', true);
@@ -113,4 +110,70 @@ public static function invalidTimeRestrictionsDataProvider(): array
113110
[$future->format(self::$timeFormat), $past->format(self::$timeFormat)]
114111
];
115112
}
113+
114+
#[DataProvider('ProductActiveFieldStatesDataProvider')]
115+
public function testIsProductAlwaysActive(?bool $active, bool $result): void
116+
{
117+
$product = oxNew(Article::class);
118+
$product->oxarticles__oxactive = new Field($active);
119+
120+
$this->assertEquals($result, $product->isProductAlwaysActive());
121+
}
122+
123+
public static function ProductActiveFieldStatesDataProvider(): array
124+
{
125+
return [
126+
'NULL value' => [null, false],
127+
'false value' => [false, false],
128+
'true value' => [true, true],
129+
];
130+
}
131+
132+
#[DataProvider('validityTimeRangesDataProvider')]
133+
public function testHasProductValidTimeRange(string $activeFrom, string $activeTo, bool $result): void
134+
{
135+
$product = oxNew(Article::class);
136+
$product->oxarticles__oxactivefrom = new Field($activeFrom);
137+
$product->oxarticles__oxactiveto = new Field($activeTo);
138+
139+
$this->assertEquals($result, $product->hasProductValidTimeRange());
140+
}
141+
142+
public static function validityTimeRangesDataProvider(): array
143+
{
144+
$now = new DateTimeImmutable();
145+
return [
146+
'Empty active From/To' => [self::$defaultTimestamp, self::$defaultTimestamp, false],
147+
'Empty active From' => [self::$defaultTimestamp, $now->format(self::$timeFormat), true],
148+
'Empty active To' => [$now->format(self::$timeFormat), self::$defaultTimestamp, true],
149+
'With active From/to' => [$now->format(self::$timeFormat), $now->format(self::$timeFormat), true],
150+
];
151+
}
152+
153+
#[DataProvider('visibilityTimeRangesDataProvider')]
154+
public function testIsProductActiveNow(string $activeFrom, string $activeTo, bool $result): void
155+
{
156+
$now = new DateTimeImmutable();
157+
$product = oxNew(Article::class);
158+
$product->oxarticles__oxactivefrom = new Field($activeFrom);
159+
$product->oxarticles__oxactiveto = new Field($activeTo);
160+
161+
$this->assertEquals($result, $product->isProductActive($now->format(self::$timeFormat)));
162+
}
163+
164+
public static function visibilityTimeRangesDataProvider(): array
165+
{
166+
$now = new DateTimeImmutable();
167+
$past = $now->modify('-1 day')->format(self::$timeFormat);
168+
$future = $now->modify('+1 day')->format(self::$timeFormat);
169+
return [
170+
'Empty active From/To' => [self::$defaultTimestamp, self::$defaultTimestamp, false],
171+
'Empty activeFrom valid activeTo' => [self::$defaultTimestamp, $future, true],
172+
'Empty activeFrom invalid activeTo' => [self::$defaultTimestamp, $past, false],
173+
'Empty activeTo valid activeFrom' => [$past, self::$defaultTimestamp, false],
174+
'Empty activeTo invalid activeFrom' => [$future, self::$defaultTimestamp, false],
175+
'With valid From/to' => [$past, $future, true],
176+
'With invalid From/to' => [$future, $past, false],
177+
];
178+
}
116179
}

0 commit comments

Comments
 (0)