DuplicateFieldCollectionTest.php in Field collection 8
File
tests/src/Kernel/DuplicateFieldCollectionTest.php
View source
<?php
namespace Drupal\Tests\field_collection\Kernel;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field_collection\Entity\FieldCollection;
use Drupal\KernelTests\KernelTestBase;
class DuplicateFieldCollectionTest extends KernelTestBase {
public static $modules = [
'field',
'field_collection',
'node',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installConfig([
'field_collection',
]);
}
public function testDuplicateFieldCollection() {
$values = [
'type' => 'field_collection',
'field_name' => 'my_collection',
'label' => 'My Collection',
];
FieldStorageConfig::create($values + [
'entity_type' => 'user',
])
->save();
$field_collection_first = FieldCollection::load('my_collection');
$field_collection_first
->set('label', 'A new label');
$field_collection_first
->save();
FieldStorageConfig::create($values + [
'entity_type' => 'node',
])
->save();
$field_collection_second = FieldCollection::load('my_collection');
$this
->assertSame('A new label', $field_collection_second
->label());
}
}