You are here

public function CropCRUDTest::testCropTypeSave in Crop API 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/CropCRUDTest.php \Drupal\Tests\crop\Kernel\CropCRUDTest::testCropTypeSave()

Tests crop type save.

File

tests/src/Kernel/CropCRUDTest.php, line 25

Class

CropCRUDTest
Tests the crop entity CRUD operations.

Namespace

Drupal\Tests\crop\Kernel

Code

public function testCropTypeSave() {
  $values = [
    'id' => $this
      ->randomMachineName(),
    'label' => $this
      ->randomString(),
    'description' => $this->randomGenerator
      ->sentences(8),
  ];
  $crop_type = $this->cropTypeStorage
    ->create($values);
  try {
    $crop_type
      ->save();
    $this
      ->assertTrue(TRUE, 'Crop type saved correctly.');
  } catch (\Exception $exception) {
    $this
      ->assertTrue(FALSE, 'Crop type not saved correctly.');
  }
  $loaded = $this->container
    ->get('config.factory')
    ->get('crop.type.' . $values['id'])
    ->get();
  foreach ($values as $key => $value) {
    $this
      ->assertEquals($loaded[$key], $value, new FormattableMarkup('Correct value for @field found.', [
      '@field' => $key,
    ]));
  }
}