public function CurrentCurrencyCartTest::testProductAddToCartForm in Commerce Currency Resolver 8
Test adding a product to the cart.
@covers ::checkCurrency @covers ::shouldCurrencyRefresh @covers ::checkOrderOwner @covers \Drupal\commerce_currency_resolver\CurrencyOrderProcessor::process @covers \Drupal\commerce_currency_resolver\Resolver\CommerceCurrencyResolver::resolve
File
- tests/
src/ Functional/ CurrentCurrencyCartTest.php, line 113
Class
- CurrentCurrencyCartTest
- Tests the add to cart form with mixed currencies.
Namespace
Drupal\Tests\commerce_currency_resolver\FunctionalCode
public function testProductAddToCartForm() {
$this
->assertEqual('USD', $this->variation
->getPrice()
->getCurrencyCode());
$this
->assertEqual('999', $this->variation
->getPrice()
->getNumber());
$this
->assertEqual('HRK', $this->currentCurrency
->getCurrency());
// Confirm that the initial add to cart submit works.
$this
->postAddToCart($this->variation
->getProduct());
$this
->assertSession()
->pageTextContains('HRK6,843.15');
$this->cart = Order::load($this->cart
->id());
$this
->drupalGet('cart');
$this
->assertEqual(999 * 6.85, $this->cart
->getTotalPrice()
->getNumber());
$this
->assertEqual('HRK', $this->cart
->getTotalPrice()
->getCurrencyCode());
// Check product display. And check current currency.
$this
->drupalGet('product/1');
$this
->assertSession()
->pageTextContains('HRK6,843.15');
$this
->assertEqual('HRK', $this->currentCurrency
->getCurrency());
// Switch currency back to USD.
$this->store
->setDefaultCurrencyCode('USD');
$this->store
->save();
$this
->reloadEntity($this->store);
$this
->resetCurrencyContainer();
$this
->assertEqual('USD', $this->currentCurrency
->getCurrency());
$this
->postAddToCart($this->variation
->getProduct());
$order = Order::load($this->cart
->id());
$this
->drupalGet('cart');
$this
->assertEqual(2 * 999, $order
->getTotalPrice()
->getNumber());
$this
->assertEqual('USD', $order
->getTotalPrice()
->getCurrencyCode());
}