You are here

public function EntityTraitTest::testTraits in Commerce Core 8.2

Tests the trait functionality.

File

tests/src/Functional/EntityTraitTest.php, line 36

Class

EntityTraitTest
Tests the entity trait functionality.

Namespace

Drupal\Tests\commerce\Functional

Code

public function testTraits() {
  $this
    ->drupalGet('admin/commerce/config/store-types/online/edit');
  $this
    ->assertSession()
    ->fieldExists('traits[first]');
  $this
    ->assertSession()
    ->fieldExists('traits[second]');
  $this
    ->assertSession()
    ->checkboxNotChecked('traits[first]');
  $this
    ->assertSession()
    ->checkboxNotChecked('traits[second]');
  $edit = [
    'traits[first]' => 'first',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->drupalGet('admin/commerce/config/store-types/online/edit');
  $this
    ->assertSession()
    ->checkboxChecked('traits[first]');
  $this
    ->assertSession()
    ->checkboxNotChecked('traits[second]');

  // The store type entity shows the correct traits.
  $store_type = StoreType::load('online');
  $this
    ->assertEquals([
    'first',
  ], $store_type
    ->getTraits());
  $this
    ->submitForm($edit, t('Save'));

  // The field was created.
  $this
    ->drupalGet('admin/commerce/config/store-types/online/edit/fields');
  $this
    ->assertSession()
    ->pageTextContains('phone');
  $this
    ->drupalGet('admin/commerce/config/store-types/online/edit');
  $edit = [
    'traits[first]' => 'first',
    'traits[second]' => 'second',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('The Second trait is in conflict with the following traits: First.');
  $edit = [
    'traits[first]' => FALSE,
    'traits[second]' => FALSE,
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->drupalGet('admin/commerce/config/store-types/online/edit');
  $this
    ->assertSession()
    ->checkboxNotChecked('traits[first]');
  $this
    ->assertSession()
    ->checkboxNotChecked('traits[second]');

  // The store type entity shows the correct traits.
  $store_type = StoreType::load('online');
  $this
    ->assertEquals([], $store_type
    ->getTraits());
  $this
    ->submitForm($edit, t('Save'));

  // The field was removed.
  $this
    ->drupalGet('admin/commerce/config/store-types/online/edit/fields');
  $this
    ->assertSession()
    ->pageTextNotContains('phone');
}