public function CommerceExchangerCalculatorTest::testPriceConversion in Commerce Exchanger 8
@covers ::priceConversion
File
- tests/
src/ Kernel/ CommerceExchangerCalculatorTest.php, line 141
Class
- CommerceExchangerCalculatorTest
- Tests the exchanger calculator.
Namespace
Drupal\Tests\commerce_exchanger\KernelCode
public function testPriceConversion() {
$priceHrk = $this->container
->get('commerce_exchanger.calculate')
->priceConversion($this->priceHrk, 'USD');
$this
->assertEqual(100 * 0.15, $priceHrk
->getNumber());
$priceUsd = $this->container
->get('commerce_exchanger.calculate')
->priceConversion($this->priceUsd, 'HRK');
$this
->assertEqual(100 * 6.85, $priceUsd
->getNumber());
$price_equal = $this->container
->get('commerce_exchanger.calculate')
->priceConversion($this->priceUsd, 'USD');
$this
->assertEqual(100.0, $price_equal
->getNumber());
$this
->config($this->exchangerId)
->setData([
'rates' => [
'HRK' => [
'USD' => [
'value' => 0,
'sync' => 0,
],
],
'USD' => [
'HRK' => [
'value' => '0',
'sync' => 0,
],
],
],
])
->save();
$this
->expectException(ExchangeRatesDataMismatchException::class);
$this->container
->get('commerce_exchanger.calculate')
->priceConversion($this->priceUsd, 'HRK');
$this
->expectException(ExchangeRatesDataMismatchException::class);
$this->container
->get('commerce_exchanger.calculate')
->priceConversion($this->priceHrk, 'USD');
}