You are here

public function StoreTest::testStore in Commerce Core 8.2

@covers ::getName @covers ::setName @covers ::getEmail @covers ::setEmail @covers ::getDefaultCurrency @covers ::setDefaultCurrency @covers ::getDefaultCurrencyCode @covers ::setDefaultCurrencyCode @covers ::getTimezone @covers ::setTimezone @covers ::getBillingCountries @covers ::setBillingCountries @covers ::isDefault @covers ::setDefault @covers ::getOwner @covers ::setOwner @covers ::getOwnerId @covers ::setOwnerId

File

modules/store/tests/src/Kernel/Entity/StoreTest.php, line 56

Class

StoreTest
Tests the Store entity.

Namespace

Drupal\Tests\commerce_store\Kernel\Entity

Code

public function testStore() {
  $store = Store::create([
    'type' => 'online',
  ]);
  $store
    ->setName('French store');
  $this
    ->assertEquals('French store', $store
    ->getName());
  $store
    ->setEmail('owner@example.com');
  $this
    ->assertEquals('owner@example.com', $store
    ->getEmail());
  $store
    ->setDefaultCurrencyCode('USD');
  $this
    ->assertEquals('USD', $store
    ->getDefaultCurrencyCode());
  $currency = Currency::load('USD');
  $store
    ->setDefaultCurrency($currency);

  /** @var \Drupal\commerce_price\Entity\CurrencyInterface $default_currency */
  $default_currency = $store
    ->getDefaultCurrency();
  $this
    ->assertNotEmpty($default_currency);
  $this
    ->assertEquals($currency
    ->id(), $default_currency
    ->id());
  $this
    ->assertEquals($currency
    ->id(), $store
    ->getDefaultCurrencyCode());
  $store
    ->setDefaultCurrencyCode('INVALID');
  $this
    ->assertEquals(NULL, $store
    ->getDefaultCurrency());
  $store
    ->setDefaultCurrencyCode('USD');

  /** @var \Drupal\commerce_price\Entity\CurrencyInterface $default_currency */
  $default_currency = $store
    ->getDefaultCurrency();
  $this
    ->assertNotEmpty($default_currency);
  $this
    ->assertEquals('USD', $default_currency
    ->id());
  $this
    ->assertEquals('USD', $store
    ->getDefaultCurrencyCode());
  $store
    ->setTimezone('Europe/Paris');
  $this
    ->assertEquals('Europe/Paris', $store
    ->getTimezone());
  $store
    ->setBillingCountries([
    'FR',
    'DE',
  ]);
  $this
    ->assertEquals([
    'FR',
    'DE',
  ], $store
    ->getBillingCountries());
  $store
    ->setDefault(TRUE);
  $this
    ->assertTrue($store
    ->isDefault());
  $store
    ->setOwner($this->user);
  $this
    ->assertEquals($this->user, $store
    ->getOwner());
  $this
    ->assertEquals($this->user
    ->id(), $store
    ->getOwnerId());
  $store
    ->setOwnerId(0);
  $this
    ->assertInstanceOf(UserInterface::class, $store
    ->getOwner());
  $this
    ->assertTrue($store
    ->getOwner()
    ->isAnonymous());
  $store
    ->setOwnerId($this->user
    ->id());
  $this
    ->assertEquals($this->user, $store
    ->getOwner());
  $this
    ->assertEquals($this->user
    ->id(), $store
    ->getOwnerId());

  // Ensure that we don't store a broken reference to the store owner.
  $store
    ->setOwnerId(900);
  $this
    ->assertTrue($store
    ->getOwner()
    ->isAnonymous());
  $this
    ->assertEquals(900, $store
    ->getOwnerId());
  $store
    ->save();
  $this
    ->assertEquals(0, $store
    ->getOwnerId());
}