You are here

public function AssetCRUDTest::testCreateAsset in farmOS 2.x

Create asset entity.

File

modules/core/asset/tests/src/Functional/AssetCRUDTest.php, line 35

Class

AssetCRUDTest
Tests the asset CRUD.

Namespace

Drupal\Tests\asset\Functional

Code

public function testCreateAsset() {
  $assert_session = $this
    ->assertSession();
  $name = $this
    ->randomMachineName();
  $edit = [
    'name[0][value]' => $name,
  ];
  $this
    ->drupalPostForm('asset/add/default', $edit, $this
    ->t('Save'));
  $result = \Drupal::entityTypeManager()
    ->getStorage('asset')
    ->getQuery()
    ->accessCheck(TRUE)
    ->range(0, 1)
    ->execute();
  $asset_id = reset($result);
  $asset = Asset::load($asset_id);
  $this
    ->assertEquals($asset
    ->get('name')->value, $name, 'asset has been saved.');
  $assert_session
    ->pageTextContains("Saved asset: {$name}");
  $assert_session
    ->pageTextContains($name);
}