MultivalueTest.php in Chosen 3.0.x
File
tests/src/Functional/MultivalueTest.php
View source
<?php
namespace Drupal\Tests\chosen\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
class MultivalueTest extends BrowserTestBase {
use ContentTypeCreationTrait;
use UserCreationTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'chosen',
'options',
'node',
];
public function setUp() {
parent::setUp();
$this->container
->get('config.factory')
->getEditable('chosen.settings')
->set('minimum_multiple', 0)
->save();
$this
->createContentType([
'type' => 'article',
]);
$user = $this
->drupalCreateUser([
'access content',
'bypass node access',
]);
$this
->drupalLogin($user);
$storage = FieldStorageConfig::create([
'type' => 'list_string',
'entity_type' => 'node',
'field_name' => 'test_multiselect',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
]);
$storage
->setSetting('allowed_values', [
'one' => 'One',
'two' => 'Two',
]);
$storage
->save();
$field = FieldConfig::create([
'field_name' => 'test_multiselect',
'bundle' => 'article',
'entity_type' => 'node',
]);
$field
->save();
$entity_form_display = EntityFormDisplay::load('node' . '.' . 'article' . '.' . 'default');
if (!$entity_form_display) {
$entity_form_display = EntityFormDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'article',
'mode' => 'default',
'status' => TRUE,
]);
}
$entity_form_display
->setComponent('test_multiselect', [
'type' => 'options_select',
])
->save();
}
public function testNoneOption() {
$this
->drupalGet('node/add/article');
$this
->assertSession()
->responseNotContains('_none');
}
}