|
39 | 39 | */
|
40 | 40 | class CreateTest extends TestCase
|
41 | 41 | {
|
42 |
| - const CUSTOMER_ID = 1; |
| 42 | + public const CUSTOMER_ID = 1; |
43 | 43 |
|
44 | 44 | /**
|
45 | 45 | * @var Create
|
@@ -461,4 +461,126 @@ public function testInitFromOrder()
|
461 | 461 |
|
462 | 462 | $this->adminOrderCreate->initFromOrder($this->orderMock);
|
463 | 463 | }
|
| 464 | + |
| 465 | + /** |
| 466 | + * Test case for setShippingAsBilling |
| 467 | + * |
| 468 | + * @dataProvider setShippingAsBillingDataProvider |
| 469 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 470 | + */ |
| 471 | + public function testSetShippingAsBilling(bool $flag, array $billingData, array $shippingData): void |
| 472 | + { |
| 473 | + $billingAddress = $this->createPartialMock(Address::class, ['getData']); |
| 474 | + $shippingAddress = $this->createPartialMock( |
| 475 | + Address::class, |
| 476 | + [ |
| 477 | + 'addData', |
| 478 | + 'setSameAsBilling', |
| 479 | + 'getData', |
| 480 | + ] |
| 481 | + ); |
| 482 | + $billingAddress->expects($this->any()) |
| 483 | + ->method('getData') |
| 484 | + ->willReturn($billingData); |
| 485 | + $shippingAddress->expects($this->any()) |
| 486 | + ->method('getData') |
| 487 | + ->willReturn($shippingData); |
| 488 | + $shippingAddress->expects($this->any()) |
| 489 | + ->method('addData') |
| 490 | + ->willReturnSelf(); |
| 491 | + $shippingAddress->expects($this->any()) |
| 492 | + ->method('setSameAsBilling') |
| 493 | + ->with($flag) |
| 494 | + ->willReturnSelf(); |
| 495 | + $quote = $this->getMockBuilder(Quote::class) |
| 496 | + ->disableOriginalConstructor() |
| 497 | + ->setMethods( |
| 498 | + [ |
| 499 | + 'getBillingAddress', |
| 500 | + 'getShippingAddress', |
| 501 | + 'setRecollect' |
| 502 | + ] |
| 503 | + ) |
| 504 | + ->getMock(); |
| 505 | + |
| 506 | + $quote->expects($this->any()) |
| 507 | + ->method('getBillingAddress') |
| 508 | + ->willReturn($billingAddress); |
| 509 | + $quote->expects($this->any()) |
| 510 | + ->method('getShippingAddress') |
| 511 | + ->willReturn($shippingAddress); |
| 512 | + $quote->expects($this->any()) |
| 513 | + ->method('setRecollect') |
| 514 | + ->willReturn(true); |
| 515 | + $this->sessionQuote |
| 516 | + ->method('getQuote') |
| 517 | + ->willReturn($quote); |
| 518 | + $this->adminOrderCreate->setShippingAsBilling($flag); |
| 519 | + } |
| 520 | + |
| 521 | + /** |
| 522 | + * Data provider for setShippingAsBilling function |
| 523 | + * |
| 524 | + * @return array |
| 525 | + */ |
| 526 | + public function setShippingAsBillingDataProvider(): array |
| 527 | + { |
| 528 | + return [ |
| 529 | + 'testcase when sameAsBillingFlag is false' => [ |
| 530 | + false, |
| 531 | + [ |
| 532 | + 'quote_id' => 1, |
| 533 | + 'entity_id' => 1, |
| 534 | + 'same_as_billing' => 1, |
| 535 | + 'customer_address_id' => null, |
| 536 | + 'weight' => '0.0000', |
| 537 | + 'free_shipping' => '0' |
| 538 | + ], |
| 539 | + [ |
| 540 | + 'quote_id' => 1, |
| 541 | + 'entity_id' => 1, |
| 542 | + 'same_as_billing' => 1, |
| 543 | + 'customer_address_id' => null, |
| 544 | + 'weight' => '0.0000', |
| 545 | + 'free_shipping' => '0' |
| 546 | + ] |
| 547 | + ], |
| 548 | + 'testcase when sameAsBillingFlag is true and there is no `weight` property' => [ |
| 549 | + true, |
| 550 | + [ |
| 551 | + 'quote_id' => 1, |
| 552 | + 'entity_id' => 1, |
| 553 | + 'same_as_billing' => 1, |
| 554 | + 'customer_address_id' => null, |
| 555 | + 'free_shipping' => '0' |
| 556 | + ], |
| 557 | + [ |
| 558 | + 'quote_id' => 1, |
| 559 | + 'entity_id' => 1, |
| 560 | + 'same_as_billing' => 1, |
| 561 | + 'customer_address_id' => null, |
| 562 | + 'free_shipping' => '0' |
| 563 | + ] |
| 564 | + ], |
| 565 | + 'testcase when sameAsBillingFlag is true and there is `weight` property' => [ |
| 566 | + false, |
| 567 | + [ |
| 568 | + 'quote_id' => 1, |
| 569 | + 'entity_id' => 1, |
| 570 | + 'same_as_billing' => 1, |
| 571 | + 'customer_address_id' => null, |
| 572 | + 'weight' => '0.0000', |
| 573 | + 'free_shipping' => '1' |
| 574 | + ], |
| 575 | + [ |
| 576 | + 'quote_id' => 1, |
| 577 | + 'entity_id' => 1, |
| 578 | + 'same_as_billing' => 1, |
| 579 | + 'customer_address_id' => null, |
| 580 | + 'weight' => '8.0000', |
| 581 | + 'free_shipping' => '1' |
| 582 | + ] |
| 583 | + ] |
| 584 | + ]; |
| 585 | + } |
464 | 586 | }
|
0 commit comments