View source
<?php
namespace Drupal\Tests\commerce\Functional;
use Drupal\commerce_store\Entity\StoreType;
class EntityTraitTest extends CommerceBrowserTestBase {
public static $modules = [
'field_ui',
'telephone',
'commerce_test',
];
protected function getAdministratorPermissions() {
return array_merge([
'administer commerce_store_type',
'administer commerce_store fields',
], parent::getAdministratorPermissions());
}
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]');
$store_type = StoreType::load('online');
$this
->assertEquals([
'first',
], $store_type
->getTraits());
$this
->submitForm($edit, t('Save'));
$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]');
$store_type = StoreType::load('online');
$this
->assertEquals([], $store_type
->getTraits());
$this
->submitForm($edit, t('Save'));
$this
->drupalGet('admin/commerce/config/store-types/online/edit/fields');
$this
->assertSession()
->pageTextNotContains('phone');
}
public function testDuplicateTraits() {
$this
->drupalGet('admin/commerce/config/store-types/online/edit');
$edit = [
'traits[first]' => 'first',
'traits[second]' => FALSE,
];
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/commerce/config/store-types/online/duplicate');
$this
->assertSession()
->checkboxChecked('traits[first]');
$this
->assertSession()
->checkboxNotChecked('traits[second]');
$edit = [
'label' => 'Online2',
'id' => 'online2',
'traits[first]' => FALSE,
'traits[second]' => FALSE,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Saved the Online2 store type.');
$store_type = StoreType::load('online2');
$this
->assertEquals([], $store_type
->getTraits());
$this
->drupalGet('admin/commerce/config/store-types/online2/edit/fields');
$this
->assertSession()
->pageTextNotContains('phone');
}
}