| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types=1 ); |
| 4 |
|
| 5 |
namespace Tests\Module\Checkout; |
| 6 |
|
| 7 |
use Packetery\Module\Checkout\CurrencySwitcherService; |
| 8 |
use Packetery\Module\Framework\WpAdapter; |
| 9 |
use Packetery\Module\ModuleHelper; |
| 10 |
use PHPUnit\Framework\MockObject\MockObject; |
| 11 |
use PHPUnit\Framework\TestCase; |
| 12 |
|
| 13 |
class CurrencySwitcherServiceTest extends TestCase { |
| 14 |
private WpAdapter|MockObject $wpAdapter; |
| 15 |
private ModuleHelper|MockObject $moduleHelper; |
| 16 |
private CurrencySwitcherService $currencySwitcherService; |
| 17 |
|
| 18 |
private function createCurrencySwitcherServiceMock(): void { |
| 19 |
$this->wpAdapter = $this->createMock( WpAdapter::class ); |
| 20 |
$this->moduleHelper = $this->createMock( ModuleHelper::class ); |
| 21 |
$this->currencySwitcherService = new CurrencySwitcherService( $this->wpAdapter, $this->moduleHelper ); |
| 22 |
} |
| 23 |
|
| 24 |
public function testGetConvertedPricePluginActive(): void { |
| 25 |
$this->createCurrencySwitcherServiceMock(); |
| 26 |
|
| 27 |
$inputPrice = 123.0; |
| 28 |
$outputPrice = 321.0; |
| 29 |
|
| 30 |
$this->moduleHelper->expects( $this->once() ) |
| 31 |
->method( 'isPluginActive' ) |
| 32 |
->with( 'woocommerce-currency-switcher/index.php' ) |
| 33 |
->willReturn( true ); |
| 34 |
|
| 35 |
$this->wpAdapter->expects( $this->once() ) |
| 36 |
->method( 'applyFilters' ) |
| 37 |
->with( 'woocs_exchange_value', $inputPrice ) |
| 38 |
->willReturn( $outputPrice ); |
| 39 |
|
| 40 |
$this->assertSame( $outputPrice, $this->currencySwitcherService->getConvertedPrice( $inputPrice ) ); |
| 41 |
} |
| 42 |
|
| 43 |
public function testGetConvertedPricePluginNotActive(): void { |
| 44 |
$this->createCurrencySwitcherServiceMock(); |
| 45 |
|
| 46 |
$inputPrice = 123.0; |
| 47 |
$outputPrice = 321.0; |
| 48 |
|
| 49 |
$this->moduleHelper->expects( $this->once() ) |
| 50 |
->method( 'isPluginActive' ) |
| 51 |
->with( 'woocommerce-currency-switcher/index.php' ) |
| 52 |
->willReturn( false ); |
| 53 |
|
| 54 |
$this->wpAdapter->expects( $this->once() ) |
| 55 |
->method( 'applyFilters' ) |
| 56 |
->with( 'packetery_price', $inputPrice ) |
| 57 |
->willReturn( $outputPrice ); |
| 58 |
|
| 59 |
$this->assertSame( $outputPrice, $this->currencySwitcherService->getConvertedPrice( $inputPrice ) ); |
| 60 |
} |
| 61 |
} |
| 62 |
|