View source
<?php
namespace Drupal\Tests\commerce_exchanger\Kernel;
use Drupal\commerce_exchanger\ExchangerProviderRates;
use Drupal\Tests\commerce\Kernel\CommerceKernelTestBase;
class ExchangerRemoteProviderTest extends CommerceKernelTestBase {
public function testImport() {
$this
->expectException(\InvalidArgumentException::class);
$definition = [
'base' => 'HRK',
'rates' => [
'EUR' => 'abs',
],
'transform' => FALSE,
];
new ExchangerProviderRates($definition);
}
public function testValid() {
$definition = [
'base' => 'HRK',
'rates' => [
'EUR' => '7.55',
'USD' => '6.45',
],
];
$rates = new ExchangerProviderRates($definition);
$this
->assertEquals($definition['base'], $rates
->getBaseCurrency());
$this
->assertEquals($definition['rates'], $rates
->getRates());
$this
->assertFalse($rates
->isTransform());
$this
->assertCount(2, $rates
->getRates());
$this
->assertEmpty($rates
->getCurrencies());
}
public function testValidFiltered() {
$definition = [
'base' => 'HRK',
'rates' => [
'EUR' => '7.55',
'USD' => '6.45',
'UAH' => '5.40',
],
'currencies' => [
'EUR' => 'Euro',
'USD' => 'Dolar',
'HRK' => 'Croatian Kuna',
],
'transform' => TRUE,
];
$rates = new ExchangerProviderRates($definition);
$this
->assertEquals($definition['base'], $rates
->getBaseCurrency());
$this
->assertNotEqual($definition['rates'], $rates
->getRates());
$this
->assertTrue($rates
->isTransform());
$this
->assertCount(3, $rates
->getCurrencies());
$this
->assertNotEqual($definition['rates']['EUR'], $rates
->getRates()['EUR']);
$this
->assertEqual(round(1 / 7.55, 6), $rates
->getRates()['EUR']);
$this
->assertEqual(2, count($rates
->getRates()));
}
}