ExchangerProviderPluginTest.php in Commerce Exchanger 8
File
tests/src/Kernel/ExchangerProviderPluginTest.php
View source
<?php
namespace Drupal\Tests\commerce_exchanger\Kernel;
use Drupal\commerce_exchanger\Entity\ExchangeRates;
use Drupal\Tests\commerce\Kernel\CommerceKernelTestBase;
class ExchangerProviderPluginTest extends CommerceKernelTestBase {
protected $test;
protected $enterprise;
public static $modules = [
'commerce_exchanger',
'commerce_exchanger_test',
];
protected function setUp() {
parent::setUp();
$this
->installConfig([
'commerce_exchanger',
]);
$currency_importer = $this->container
->get('commerce_price.currency_importer');
$currency_importer
->import('HRK');
$currency_importer
->import('EUR');
$hnb_entity = ExchangeRates::create([
'id' => 'test',
'label' => 'Test',
'plugin' => 'test',
]);
$hnb_entity
->save();
$this->test = $hnb_entity
->getPlugin();
$fixer_entity = ExchangeRates::create([
'id' => 'enterprise',
'label' => 'Enterprise',
'plugin' => 'enterprise',
'configuration' => [
'enterprise' => TRUE,
],
]);
$fixer_entity
->save();
$this->enterprise = $fixer_entity
->getPlugin();
}
public function testPluginSettings() {
$this
->assertTrue($this->test
->useCrossSync());
$this
->assertFalse($this->test
->isEnterprise());
$this
->assertEqual('HRK', $this->test
->getBaseCurrency());
$this
->assertFalse($this->enterprise
->useCrossSync());
$this
->assertTrue($this->enterprise
->isEnterprise());
$this
->assertEmpty($this->enterprise
->getBaseCurrency());
}
public function testImportCrossSync() {
$this->test
->import();
$rates = $this->container
->get('commerce_exchanger.calculate')
->getExchangeRates();
$this
->assertEqual(round(1 / 0.13, 6), $rates['HRK']['EUR']['value']);
$this
->assertEqual(round(1 / 0.16, 6), $rates['HRK']['USD']['value']);
$this
->assertEqual(0.13, $rates['EUR']['HRK']['value']);
$this
->assertEqual(0.16, $rates['USD']['HRK']['value']);
}
public function testImportEnterprise() {
$test = ExchangeRates::load('test');
$test
->set('status', 0)
->save();
$this->enterprise
->import();
$rates = $this->container
->get('commerce_exchanger.calculate')
->getExchangeRates();
$this
->assertEqual(0.13, $rates['HRK']['EUR']['value']);
$this
->assertEqual(7.58, $rates['EUR']['HRK']['value']);
}
}