You are here

public function EntityCRUDTest::newEntitiesCanBeCreated in Entity Construction Kit (ECK) 8

@test

File

tests/src/Functional/EntityCRUDTest.php, line 17

Class

EntityCRUDTest
Tests if eck entities are correctly created and updated.

Namespace

Drupal\Tests\eck\Functional

Code

public function newEntitiesCanBeCreated() {
  $entityTypeInfo = $this
    ->createEntityType([
    'title',
  ], 'TestType');
  $bundleInfo = $this
    ->createEntityBundle($entityTypeInfo['id'], 'TestBundle');
  $params = [
    'eck_entity_type' => $entityTypeInfo['id'],
    'eck_entity_bundle' => $bundleInfo['type'],
  ];
  $url = Url::fromRoute('eck.entity.add', $params);
  $values = [
    'title[0][value]' => 'testEntity',
  ];
  $this
    ->drupalGet($url);
  $this
    ->submitForm($values, 'Save');
  $currentUrl = $this
    ->getSession()
    ->getCurrentUrl();
  $entity = \Drupal::entityTypeManager()
    ->getStorage($entityTypeInfo['id'])
    ->load(1);
  $entityUrl = $entity
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();
  $this
    ->assertSame($entityUrl, $currentUrl);
}