Skip to content

Instantly share code, notes, and snippets.

@chx
Created October 31, 2020 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chx/66449f2aeb36aa37c7bba05253dab197 to your computer and use it in GitHub Desktop.
Save chx/66449f2aeb36aa37c7bba05253dab197 to your computer and use it in GitHub Desktop.
map item test
<?php
namespace Drupal\Tests\field\Kernel;
use Drupal\entity_test\Entity\EntityTestMapField;
class MapItemTest extends FieldKernelTestBase {
protected function setUp(): void {
parent::setUp();
$this->installEntitySchema('entity_test_map_field');
}
public function testMapItem() {
$name = $this->randomString();
$data = [];
for ($i = 0; $i <= 4; $i++) {
$data[$this->randomMachineName()] = $this->randomString();
}
$entity = EntityTestMapField::create([
'name' => $name,
'data' => $data,
]);
$entity = $this->entitySaveReload($entity);
$this->assertSame($name, $entity->label());
foreach ($data as $k => $v) {
$this->assertSame($v, $entity->data->$k);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment