-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniil Tkachev
committed
Nov 29, 2024
1 parent
919b39f
commit 7306823
Showing
10 changed files
with
171 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidSolutionCatalysts\Unzer\Tests\Integration\Service; | ||
|
||
use OxidSolutionCatalysts\Unzer\Service\TmpOrderService; | ||
use OxidSolutionCatalysts\Unzer\Model\TmpOrder; | ||
use OxidEsales\Eshop\Application\Model\Order; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TmpOrderServiceTest extends TestCase | ||
{ | ||
private TmpOrderService $tmpOrderService; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->tmpOrderService = new TmpOrderService(); | ||
} | ||
|
||
public function testGetOrderBySessionOrderIdReturnsOrderIfLoaded(): void | ||
{ | ||
$orderMock = $this->createMock(Order::class); | ||
$orderMock->method('load')->with('sessionOrderId')->willReturn(true); | ||
|
||
$tmpOrderMock = $this->createMock(TmpOrder::class); | ||
$tmpOrderMock->expects($this->never())->method('getTmpOrderByOxOrderId'); | ||
|
||
$this->tmpOrderService = $this->getMockBuilder(TmpOrderService::class) | ||
->setMethods(['getTmpOrder']) | ||
->getMock(); | ||
|
||
$this->tmpOrderService | ||
->expects($this->any()) | ||
->method('getTmpOrder') | ||
->willReturn($tmpOrderMock); | ||
|
||
$result = $this->tmpOrderService->getOrderBySessionOrderId('sessionOrderId'); | ||
|
||
$this->assertInstanceOf(Order::class, $result); | ||
} | ||
|
||
public function testGetOrderBySessionOrderIdFallsBackToTmpOrder(): void | ||
{ | ||
$orderMock = $this->createMock(Order::class); | ||
$orderMock->method('load')->with('sessionOrderId')->willReturn(false); | ||
|
||
$tmpOrderMock = $this->createMock(TmpOrder::class); | ||
$tmpOrderMock->expects($this->once())->method('getTmpOrderByOxOrderId')->with('sessionOrderId')->willReturn($orderMock); | ||
|
||
$this->tmpOrderService = $this->getMockBuilder(TmpOrderService::class) | ||
->setMethods(['getTmpOrder']) | ||
->getMock(); | ||
|
||
$this->tmpOrderService | ||
->expects($this->any()) | ||
->method('getTmpOrder') | ||
->willReturn($tmpOrderMock); | ||
|
||
$result = $this->tmpOrderService->getOrderBySessionOrderId('sessionOrderId'); | ||
|
||
$this->assertInstanceOf(Order::class, $result); | ||
} | ||
|
||
public function testGetPaymentTypeReturnsOrderPaymentType(): void | ||
{ | ||
$orderMock = $this->createMock(Order::class); | ||
$orderMock->method('getFieldData')->with('oxpaymenttype')->willReturn('PAYMENT_TYPE'); | ||
|
||
$result = $this->tmpOrderService->getPaymentType('sessionOrderId', $orderMock); | ||
|
||
$this->assertSame('PAYMENT_TYPE', $result); | ||
} | ||
|
||
public function testGetPaymentTypeFallsBackToTmpOrder(): void | ||
{ | ||
$orderMock = $this->createMock(Order::class); | ||
$orderMock->method('getFieldData')->with('oxpaymenttype')->willReturn(''); | ||
|
||
$tmpOrderMock = $this->createMock(TmpOrder::class); | ||
$tmpOrderMock->expects($this->once())->method('getTmpOrderByOxOrderId')->with('sessionOrderId')->willReturn($orderMock); | ||
|
||
$this->tmpOrderService = $this->getMockBuilder(TmpOrderService::class) | ||
->setMethods(['getTmpOrder']) | ||
->getMock(); | ||
|
||
$this->tmpOrderService | ||
->expects($this->any()) | ||
->method('getTmpOrder') | ||
->willReturn($tmpOrderMock); | ||
|
||
$result = $this->tmpOrderService->getPaymentType('sessionOrderId', $orderMock); | ||
|
||
$this->assertSame('', $result); | ||
} | ||
|
||
public function testGetOrderCurrencyReturnsOrderCurrency(): void | ||
{ | ||
$orderMock = $this->createMock(Order::class); | ||
$orderMock->method('getFieldData')->with('oxcurrency')->willReturn('EUR'); | ||
|
||
$result = $this->tmpOrderService->getOrderCurrency('sessionOrderId', $orderMock, 'paymentType'); | ||
|
||
$this->assertSame('EUR', $result); | ||
} | ||
|
||
public function testGetOrderCurrencyFallsBackToTmpOrder(): void | ||
{ | ||
$orderMock = $this->createMock(Order::class); | ||
$orderMock->method('getFieldData')->with('oxcurrency')->willReturn(null); | ||
|
||
$tmpOrderMock = $this->createMock(TmpOrder::class); | ||
$tmpOrderMock->expects($this->once())->method('getTmpOrderByOxOrderId')->with('sessionOrderId')->willReturn($orderMock); | ||
|
||
$this->tmpOrderService = $this->getMockBuilder(TmpOrderService::class) | ||
->setMethods(['getTmpOrder']) | ||
->getMock(); | ||
|
||
$this->tmpOrderService | ||
->expects($this->any()) | ||
->method('getTmpOrder') | ||
->willReturn($tmpOrderMock); | ||
|
||
$result = $this->tmpOrderService->getOrderCurrency('sessionOrderId', $orderMock, 'paymentType'); | ||
|
||
$this->assertNull($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters