PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | tests/Module/Options/OptionsProviderTest.php +0 -211 2.3.22.0.9 View file →
@@ -3,17 +3,12 @@
3 3 declare( strict_types=1 );
4 4
5 5 namespace Tests\Module\Options;
6 6
7 -use Packetery\Core\Entity\PacketStatus;
8 -use Packetery\Module\Framework\WpAdapter;
9 -use Packetery\Module\Options\OptionNames;
10 7 use Packetery\Module\Options\OptionsProvider;
11 8 use PHPUnit\Framework\TestCase;
12 9
13 10 class OptionsProviderTest extends TestCase {
14 - private const DUMMY_NONSENSE_VALUE = 'nonsense';
15 -
16 11 public static function dimensionsUnitProvider(): array {
17 12 return [
18 13 [
19 14 'unit' => 'cm',
@@ -38,9 +33,8 @@
38 33 * @dataProvider dimensionsUnitProvider
39 34 */
40 35 public function testGetDimensionsNumberOfDecimals( string $unit, int $expectedDecimals ): void {
41 36 $provider = $this->getMockBuilder( OptionsProvider::class )
42 - ->disableOriginalConstructor()
43 37 ->onlyMethods( [ 'getDimensionsUnit' ] )
44 38 ->getMock();
45 39
46 40 $provider->method( 'getDimensionsUnit' )
@@ -100,9 +94,8 @@
100 94 int $numberOfDecimals,
101 95 string $unit
102 96 ): void {
103 97 $provider = $this->getMockBuilder( OptionsProvider::class )
104 - ->disableOriginalConstructor()
105 98 ->onlyMethods( [ 'getDimensionsNumberOfDecimals', 'getDimensionsUnit' ] )
106 99 ->getMock();
107 100
108 101 $provider->method( 'getDimensionsNumberOfDecimals' )
@@ -112,210 +105,6 @@
112 105 ->willReturn( $unit );
113 106
114 107 $result = $provider->getSanitizedDimensionValueInMm( $dimensionValue );
115 108 $this->assertEquals( $expectedValue, $result );
116 - }
117 -
118 - public function testStatusSyncingPacketStatuses(): void {
119 - $wpAdapterMock = $this->createMock( WpAdapter::class );
120 - $wpAdapterMock
121 - ->method( 'getOption' )
122 - ->willReturnCallback(
123 - static function ( string $key ): array {
124 - if ( $key === OptionNames::PACKETERY_SYNC ) {
125 - return [ 'status_syncing_packet_statuses' => [ PacketStatus::DEPARTED, PacketStatus::UNKNOWN ] ];
126 - }
127 -
128 - return [];
129 - }
130 - );
131 -
132 - $provider = new OptionsProvider(
133 - $wpAdapterMock
134 - );
135 -
136 - $result = $provider->getStatusSyncingPacketStatuses(
137 - [
138 - new PacketStatus( PacketStatus::DEPARTED, PacketStatus::DEPARTED, true ),
139 - new PacketStatus( PacketStatus::ARRIVED, PacketStatus::ARRIVED, true ),
140 - ]
141 - );
142 - $this->assertSame( [ PacketStatus::DEPARTED ], $result );
143 - }
144 -
145 - public static function wcCarrierConfigEnabledNullableProvider(): array {
146 - return [
147 - [
148 - 'inputValue' => true,
149 - 'expectedValue' => true,
150 - ],
151 - [
152 - 'inputValue' => false,
153 - 'expectedValue' => false,
154 - ],
155 - [
156 - 'inputValue' => null,
157 - 'expectedValue' => null,
158 - ],
159 - [
160 - 'inputValue' => 1,
161 - 'expectedValue' => true,
162 - ],
163 - [
164 - 'inputValue' => 0,
165 - 'expectedValue' => false,
166 - ],
167 - [
168 - 'inputValue' => '1',
169 - 'expectedValue' => true,
170 - ],
171 - [
172 - 'inputValue' => '0',
173 - 'expectedValue' => false,
174 - ],
175 - [
176 - 'inputValue' => '',
177 - 'expectedValue' => false,
178 - ],
179 - [
180 - 'inputValue' => self::DUMMY_NONSENSE_VALUE,
181 - 'expectedValue' => true,
182 - ],
183 - ];
184 - }
185 -
186 - /**
187 - * @dataProvider wcCarrierConfigEnabledNullableProvider
188 - */
189 - public function testIsWcCarrierConfigEnabledNullable( mixed $inputValue, ?bool $expectedValue ): void {
190 - $wpAdapterMock = $this->createMock( WpAdapter::class );
191 - $wpAdapterMock->method( 'getOption' )
192 - ->willReturn( [ 'new_carrier_settings_enabled' => $inputValue ] );
193 -
194 - $provider = new OptionsProvider( $wpAdapterMock );
195 -
196 - $this->assertSame( $expectedValue, $provider->isWcCarrierConfigEnabledNullable() );
197 - }
198 -
199 - public static function autoEmailInfoInsertionEnabledProvider(): array {
200 - return [
201 - [
202 - 'inputValue' => true,
203 - 'expectedValue' => true,
204 - ],
205 - [
206 - 'inputValue' => false,
207 - 'expectedValue' => false,
208 - ],
209 - [
210 - 'inputValue' => null,
211 - 'expectedValue' => true,
212 - ],
213 - [
214 - 'inputValue' => 1,
215 - 'expectedValue' => true,
216 - ],
217 - [
218 - 'inputValue' => 0,
219 - 'expectedValue' => false,
220 - ],
221 - [
222 - 'inputValue' => '1',
223 - 'expectedValue' => true,
224 - ],
225 - [
226 - 'inputValue' => '0',
227 - 'expectedValue' => false,
228 - ],
229 - [
230 - 'inputValue' => '',
231 - 'expectedValue' => false,
232 - ],
233 - [
234 - 'inputValue' => self::DUMMY_NONSENSE_VALUE,
235 - 'expectedValue' => true,
236 - ],
237 - ];
238 - }
239 -
240 - /**
241 - * @dataProvider autoEmailInfoInsertionEnabledProvider
242 - */
243 - public function testIsAutoEmailInfoInsertionEnabled( mixed $inputValue, bool $expectedValue ): void {
244 - $wpAdapterMock = $this->createMock( WpAdapter::class );
245 - $wpAdapterMock->method( 'getOption' )
246 - ->willReturn( [ 'auto_email_info_insertion' => $inputValue ] );
247 -
248 - $provider = new OptionsProvider( $wpAdapterMock );
249 -
250 - $this->assertSame( $expectedValue, $provider->isAutoEmailInfoInsertionEnabled() );
251 - }
252 -
253 - public function testIsAutoEmailInfoInsertionEnabledReturnsDefaultWhenOptionNotSet(): void {
254 - $wpAdapterMock = $this->createMock( WpAdapter::class );
255 - $wpAdapterMock->method( 'getOption' )
256 - ->willReturn( [] );
257 -
258 - $provider = new OptionsProvider( $wpAdapterMock );
259 -
260 - $this->assertSame( true, $provider->isAutoEmailInfoInsertionEnabled() );
261 - }
262 -
263 - public function testGetPacketAutoSubmissionMappedUniqueEvents(): void {
264 - $wpAdapterMock = $this->createMock( WpAdapter::class );
265 - $wpAdapterMock
266 - ->method( 'getOption' )
267 - ->willReturnCallback(
268 - static function ( string $key ): array {
269 - if ( $key === OptionNames::PACKETERY_AUTO_SUBMISSION ) {
270 - return [
271 - 'payment_method_events' => [
272 - [
273 - 'event' => 'order_paid',
274 - ],
275 - [
276 - 'event' => 'order_shipped',
277 - ],
278 - [
279 - 'event' => null,
280 - ],
281 - ],
282 - ];
283 - }
284 -
285 - return [];
286 - }
287 - );
288 -
289 - $provider = new OptionsProvider( $wpAdapterMock );
290 -
291 - $result = $provider->getPacketAutoSubmissionMappedUniqueEvents();
292 - $this->assertSame( [ 'order_paid', 'order_shipped' ], array_values( $result ) );
293 - }
294 -
295 - public function testShowConsignPasswordForZBoxDefaultsToDisabled(): void {
296 - $wpAdapterMock = $this->createMock( WpAdapter::class );
297 - $wpAdapterMock->method( 'getOption' )->willReturn( [] );
298 -
299 - $provider = new OptionsProvider( $wpAdapterMock );
300 -
301 - $this->assertFalse( $provider->isShowConsignPasswordForZBoxEnabled() );
302 - }
303 -
304 - public function testShowConsignPasswordForZBoxReadsStoredValue(): void {
305 - $wpAdapterMock = $this->createMock( WpAdapter::class );
306 - $wpAdapterMock->method( 'getOption' )
307 - ->willReturnCallback(
308 - static function ( string $key ) {
309 - if ( $key === OptionNames::PACKETERY ) {
310 - return [ 'show_consign_password_for_z_box' => true ];
311 - }
312 -
313 - return [];
314 - }
315 - );
316 -
317 - $provider = new OptionsProvider( $wpAdapterMock );
318 -
319 - $this->assertTrue( $provider->isShowConsignPasswordForZBoxEnabled() );
320 109 }
321 110 }