You are here

public function PriceItemGeneratedSampleValueTest::testGeneratedSampleValue in Commerce Core 8.2

Tests the generated sample value.

@dataProvider dataForGeneratedSamples

Parameters

array $available_currencies: The available currencies.

File

modules/price/tests/src/Kernel/PriceItemGeneratedSampleValueTest.php, line 25

Class

PriceItemGeneratedSampleValueTest
Tests generating sample values for price fields.

Namespace

Drupal\Tests\commerce_price\Kernel

Code

public function testGeneratedSampleValue(array $available_currencies) {

  /** @var \Drupal\commerce_price\CurrencyImporterInterface $currency_importer */
  $currency_importer = $this->container
    ->get('commerce_price.currency_importer');
  foreach ($available_currencies as $available_currency) {
    $currency_importer
      ->import($available_currency);
  }
  $definition = BaseFieldDefinition::create('commerce_price')
    ->setSetting('available_currencies', $available_currencies);
  $sample = PriceItem::generateSampleValue($definition);
  $this
    ->assertIsArray($sample);
  $price = Price::fromArray($sample);
  $currency_code = reset($available_currencies);
  $this
    ->assertEquals($currency_code, $price
    ->getCurrencyCode());
}