14
14
use OxidEsales \Eshop \Core \Field ;
15
15
use OxidEsales \Eshop \Core \Registry ;
16
16
use OxidEsales \EshopCommunity \Tests \Integration \IntegrationTestCase ;
17
+ use PHPUnit \Framework \Attributes \DataProvider ;
17
18
18
19
final class ArticleTest extends IntegrationTestCase
19
20
{
@@ -58,9 +59,7 @@ public function testIsVisibleWithValidTimeRestrictionsAndDisabledConfig(): void
58
59
$ this ->assertFalse ($ product ->isVisible ());
59
60
}
60
61
61
- /**
62
- * @dataProvider validTimeRestrictionsDataProvider
63
- */
62
+ #[DataProvider('validTimeRestrictionsDataProvider ' )]
64
63
public function testIsVisibleWithValidTimeRestrictions (string $ activeFrom , string $ activeTo ): void
65
64
{
66
65
Registry::getConfig ()->setConfigParam ('blUseTimeCheck ' , true );
@@ -86,9 +85,7 @@ public static function validTimeRestrictionsDataProvider(): array
86
85
];
87
86
}
88
87
89
- /**
90
- * @dataProvider invalidTimeRestrictionsDataProvider
91
- */
88
+ #[DataProvider('invalidTimeRestrictionsDataProvider ' )]
92
89
public function testIsVisibleWithInvalidTimeRestrictions (string $ activeFrom , string $ activeTo ): void
93
90
{
94
91
Registry::getConfig ()->setConfigParam ('blUseTimeCheck ' , true );
@@ -113,4 +110,70 @@ public static function invalidTimeRestrictionsDataProvider(): array
113
110
[$ future ->format (self ::$ timeFormat ), $ past ->format (self ::$ timeFormat )]
114
111
];
115
112
}
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
+ }
116
179
}
0 commit comments