function OptionsAllowedValuesTest::testSubmitFieldStorageUpdate

Same name and namespace in other branches
  1. 11.x core/modules/options/tests/src/Kernel/OptionsAllowedValuesTest.php \Drupal\Tests\options\Kernel\OptionsAllowedValuesTest::testSubmitFieldStorageUpdate()

Tests that the field storage form submit resets the cached values.

File

core/modules/options/tests/src/Kernel/OptionsAllowedValuesTest.php, line 65

Class

OptionsAllowedValuesTest
Tests the caching of options allowed values.

Namespace

Drupal\Tests\options\Kernel

Code

public function testSubmitFieldStorageUpdate() : void {
  $service = $this->container
    ->get(OptionsAllowedValuesInterface::class);
  $this->assertSame([
    1 => 'One',
    2 => 'Two',
    3 => 'Three',
  ], $service->getAllowedValues($this->fieldStorage));
  // Change the setting without saving: the cached values are still returned.
  $this->fieldStorage
    ->setSetting('allowed_values', [
    1 => 'First',
  ]);
  $this->assertSame([
    1 => 'One',
    2 => 'Two',
    3 => 'Three',
  ], $service->getAllowedValues($this->fieldStorage));
  // The field storage form submit handler resets all cached allowed values.
  ListItemBase::submitFieldStorageUpdate();
  $this->assertSame([
    1 => 'First',
  ], $service->getAllowedValues($this->fieldStorage));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.